How to access provider's supported types in Android Wear 2.0 - android-wear-2.0

I am starting to work on the new Android Wear 2.0 Api's specifically Complications. I have found out that the Complications will default to the "easiest" supported type that the provider also supports, such as the Android Wear Battery Life will default to TYPE_SHORT_TEXT when the complication supports TYPE_SHORT_TEXT as well as TYPE_RANGED_VALUE. So I am wondering if there is a way to access the types the provider supports (which is added in the manifest for provider as a service) as shown below.
<meta-data android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="RANGED_VALUE,SHORT_TEXT,LONG_TEXT"/>
Is there a way to access the array of supported types of a provider?
EDIT:
I found the way to access the supported types of a provider through reading the manifest's meta data where the supported types for the service is needed to be declared.
ComponentName service = new ComponentName(this, DataProvider.class);
try {
Bundle bundle = getPackageManager().getServiceInfo(service, PackageManager.GET_META_DATA).metaData;
if(bundle != null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d(TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Though I am still wondering about how to access the supported type of Google's system built providers (under AppName: Android Wear) such as Watch battery, World clock, etc.
Any ideas?

Related

RestartApplication is not getting called after Intune enrolment for Xamarin

As per Microsoft Intune Documentation.
When an app receives MAM policies for the first time, it must restart to apply the required hooks. To notify the app that a restart needs to happen, the SDK provides a delegate method in IntuneMAMPolicyDelegate.h. refer here
I have implemented the same in Xamarin.
var authResult = await adalHelper.Authenticate();
if(authResult != null && !string.IsNullOrEmpty(authResult.AccessToken)){
var enrollmentDel = new EnrollmentDelegate(this);
IntuneMAMEnrollmentManager.Instance.Delegate = enrollmentDel;
IntuneMAMPolicyManager.Instance.Delegate = new EnrollmentPolicyDelegate();
IntuneMAMEnrollmentManager.Instance.RegisterAndEnrollAccount(authResult.UserInfo.DisplayableId.ToLower());
}
EnrollmentPolicyDelegate:
public class EnrollmentPolicyDelegate : IntuneMAMPolicyDelegate
{
public override bool RestartApplication
{
get
{
var returnedVal = base.RestartApplication;
return returnedVal;
}
}
}
As per documentation, I am supposed to use this property to know when I need to restart the application
I need your help to figure that out. When and at stage, and where I use this property to decide. For me it never gets called.
If you read the document of restartApplication in IntuneMAMPolicyDelegate.h, it says:
This method is Called by the Intune SDK when the application needs to restart because
policy has been received for the first time, or if we're handling a
mam-ca remediation and are restarting as a part of a SW because we
need to remove an existing user.
In my understanding, the method is managered by Intune SDK and you just need to return ture/false to determine who should handle the restart.(That means you don't have to use this property to decide)
Returns TRUE if the host application will restart on its own.
Returns FALSE if the host application wants the Intune SDK to handle
the restart
And I checked some samples, they return false to let the Intune SDK to handle the restart. You can see the source code in Chatr-Sample-Intune-iOS-App and Wagr-Sample-Intune-iOS-App.

Xamarin.Android Java bindings library runtime failure accessing native library

TL;DR: I am looking for a way to find and extract a native shared library (.so) file from an Android device that is running a vendor-specific custom Android build. I need this file as the missing piece in a Xamarin.Android Java bindings library.
I am attempting to create a Xamarin.Android bindings library for a Java SDK that exposes laser barcode scanning APIs on Famoco's Android devices. These devices run a vendor-specific Android build, which supports some special features, such as centralized device management.
I followed the usual procedures to create the bindings library, without using any custom transforms or additions, and there were no compiler errors.
Here is the factory method, generated within the bindings library, that attempts to create a new BarCodeReader instance:
[Register ("open", "(ILandroid/content/Context;)Lcom/zebra/adc/decoder/BarCodeReader;", "")]
public static unsafe global::Com.Zebra.Adc.Decoder.BarCodeReader Open (int readerId, global::Android.Content.Context context)
{
const string __id = "open.(ILandroid/content/Context;)Lcom/zebra/adc/decoder/BarCodeReader;";
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [2];
__args [0] = new JniArgumentValue (readerId);
__args [1] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
return global::Java.Lang.Object.GetObject<global::Com.Zebra.Adc.Decoder.BarCodeReader> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
} finally {
}
}
The above code fails while executing the following line:
var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
An exception is thrown: No implementation found for void com.zebra.adc.decoder.BarCodeReader.native_setup(java.lang.Object, int, java.lang.Object).
I learned from the troubleshooting guidelines that this type of failure is typically caused by the inability to resolve a required native library.
In an attempt to confirm this as the cause, I used JD-GUI to decompile the Famoco JAR, from which I extracted the following snippets of the implementation code:
// This is the underlying Java implementation of the above bindings library factory method
public static BarCodeReader open(int readerId, Context context)
{
return new BarCodeReader(readerId, context);
}
// This is the BarCodeReader constructor that is called by the factory method
BarCodeReader(int readerId, Context context)
{
this.mEventHandler = null;
this.mAutoFocusCallback = null;
this.mDecodeCallback = null;
this.mErrorCallback = null;
this.mPreviewCallback = null;
this.mSnapshotCallback = null;
this.mVideoCallback = null;
this.mZoomListener = null;
Looper aLooper = Looper.myLooper();
if (null == aLooper) {
aLooper = Looper.getMainLooper();
}
if (aLooper != null) {
this.mEventHandler = new EventHandler(this, aLooper);
}
native_setup(new WeakReference(this), readerId, context);
}
// This method is called by the above constructor, but fails because no implementation exists
private final native void native_setup(Object paramObject, int paramInt);
It seems to me that the above runtime error is occurring because the private method native_setup is not implemented within the Java code, but separately within a native library that is not referenced anywhere within my bindings library project. Does this seem like a reasonable diagnosis?
Unfortunately, I didn't find any .so (native library) files within the SDK kit supplied by Famoco. I have contacted their support team, who stated that it is not necessary to link an .so file when consuming their SDK JAR. Famoco are not keen to support cross-platform apps on their devices, but they did confirm that they have other customers using Xamarin, who appear to have solved this problem. Unfortunately, Famoco support don't seem able to tell me how to achieve this.
Could it be that the required native library already exists on the device (deployed as part of the custom Android build)? To verify this hypothesis, I installed the Famoco sample laser scanning app, which runs correctly, even though there is no sign of a .so file within its project source kit.
If so, is it feasible to find and extract the .so file from the Android environment and how should I do this?
Yes, the libbarcodereader44.so file should be preinstalled on the custom device. It may be either in the /system/lib or in the /vendor/lib directory. You must load this library from your code before calling the open () method. Here you can find more details about the Famoco SDK.

How can I get Android and iPhone IMEI number using Xamarin.forms

I am developing an Xamarin.forms application, I need to catch the imei number of mobile that is using the application. I am aware of how it is done in Android. But how can I do the same in Xamarin.forms. Please educate me.
There is no 'Forms-way' of doing this. If you know how on Android you can make use of the DependencyService. Which means in your shared project create an interface like:
public interface IImeiService
{
string GetImei();
}
Now in your Android project implement this interface, so it would be something like:
public class ImeiService : IImeiService
{
public string GetImei()
{
// ... Implement your Android code here
}
}
Register your Android code with an attribute on the class above the namespace
[assembly: Xamarin.Forms.Dependency (typeof (ImeiService))]
namespace ImeiApp.Droid {
You can now access it, back in your shared code, with:
var imei = DependencyService.Get<IImeiService>().GetImei();
If you would have an iOS implementation you could repeat the same steps, although you can, of course, use the same interface and call in shared code, so you will only need a iOS specific implementation.
However, since iOS 7 Apple disallows access to this kind of information programmatically, so you cannot get the IMEI number. And if you can, you will use code that will not be allowed through the App Store review process.

How can I save some user data locally on my Xamarin Forms app?

I have a simple Xamarin Forms app. I've now got a simple POCO object (eg. User instance or an list of the most recent tweets or orders or whatever).
How can I store this object locally to the device? Lets imagine I serialize it as JSON.
Also, how secure is this data? Is it part of Keychains, etc? Auto backed up?
cheers!
You have a couple options.
SQLite. This option is cross-platform and works well if you have a lot of data. You get the added bonus of transaction support and async support as well. EDIT: In the past I suggested using SQLite.Net-PCL. Due to issues involving Android 7.0 support (and an apparent sunsetting of support) I now recommend making use of the project that was originally forked from: sqlite-net
Local storage. There's a great nuget that supports cross-platform storage. For more information see PCLStorage
There's also Application.Current.Properties implemented in Xamarin.Forms that allow simple Key-Value pairs of data.
I think you'll have to investigate and find out which route serves your needs best.
As far as security, that depends on where you put your data on each device. Android stores app data in a secure app folder by default (not all that secure if you're rooted). iOS has several different folders for data storage based on different needs. Read more here: iOS Data Storage
Another option is the Xamarin Forms settings plugin.
E.g. If you need to store a user instance, just serialize it to json when storing and deserialize it when reading.
Uses the native settings management
Android: SharedPreferences
iOS: NSUserDefaults
Windows Phone: IsolatedStorageSettings
Windows RT / UWP: ApplicationDataContainer
public User CurrentUser
{
get
{
User user = null;
var serializedUser = CrossSettings.Current.GetValueOrDefault<string>(UserKey);
if (serializedUser != null)
{
user = JsonConvert.DeserializeObject<User>(serializedUser);
}
return user;
}
set
{
CrossSettings.Current.AddOrUpdateValue(UserKey, JsonConvert.SerializeObject(value));
}
}
EDIT:
There is a new solution for this. Just use Xamarin.Essentials.
Preferences.Set(UserKey, JsonConvert.SerializeObject(value));
var user= JsonConvert.DeserializeObject<User>(Preferences.Get(UserKey, "default_value");
Please use Xamarin.Essentials
The Preferences class helps to store application preferences in a key/value store.
To save a value:
Preferences.Set("my_key", "my_value");
To get a value:
var myValue = Preferences.Get("my_key", "default_value");
If you want to store a simple value, such as a string, follow this Example code.
setting the value of the "totalSeats.Text" to the "SeatNumbers" key from page1
Application.Current.Properties["SeatNumbers"] = totalSeats.Text;
await Application.Current.SavePropertiesAsync();
then, you can simply get the value from any other page (page2)
var value = Application.Current.Properties["SeatNumbers"].ToString();
Additionally, you can set that value to another Label or Entry etc.
SeatNumbersEntry.Text = value;
If it's Key value(one value) data storage, follow below code
Application.Current.Properties["AppNumber"] = "123"
await Application.Current.SavePropertiesAsync();
Getting the same value
var value = Application.Current.Properties["AppNumber"];

Determine location using Microsoft Location Service API in Windowsphone7

I submit my app on windows-phone7 store, Microsoft need following requirement to certify the app.
The following requirements apply to applications that receive the location of a user's mobile device:
2.7.1 Your application must determine location using Microsoft Location Service API.
2.7.2 The privacy policy of your application must inform users about how location data from the Location Service API is used and disclosed and the controls that users have over the use and sharing
of location data. This can be hosted within or directly linked from the application.
Please help me what i want to mentioned or implement to certify the app.
Here is the code I use to get the location.
private static GeoCoordinateWatcher Watcher;
private void StartGeoWatcher()
{
if (Watcher == null)
{
Watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
Watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(OnPositionChanged);
Watcher.TryStart(false, System.TimeSpan.FromMilliseconds(1000));
}
}
private void OnPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
latitude = e.Position.Location.Latitude;
longitude = e.Position.Location.Longitude;
}

Resources