You can retrieve the Android ID via:
var androidId = NativeEssentials.Instance.AndroidId;
You can use NativeBuddy to register with Google Cloud MEssaging (GCM) by passing your application's sender Id in with the following command:
NativeEssentials.Instance.RegisterWithGcm("<APP_SENDER_ID>");
This will attempt registration with GCM and result in the callback (see section below) getting called.
You can retrieve your GCM Registration ID in two ways.
Regsiter a callback prior to calling the NativeEssentials.Instance.RegisterWithGcm
documented above
NativeEssentials.OnRegisteredWithGcm += (registrationId) =>
{
Debug.Log("[GCM] Registered with GCM with ID: " + registrationId);
};
Once registration has been completed, you can also retrieve the GCM Registration ID with
var myGcmRegId = NativeEssentials.Instance.GcmRegistrationId;
Note: In order to register with GCM and retrieve the token, you will need to ensure that the standard GCM native libraries have been included in your project.
If you are using runtime permissions for Android 6+, you should add a handler for this as early as possible in your application lifecycle. The Awake()
method is typically a good place for this
void Awake ()
{
NativeEssentials.Instance.OnAndroidPermissionCallback += (requestResult) =>
{
StringBuilder sb = new StringBuilder();
sb.Append("Results for premission request:");
bool gotoAppSettings = false;
foreach(var p in requestResult)
{
sb.Append("\nPermission: " + p.Permission);
sb.Append(string.Format(", Result: {0} ({1})", p.Status.ToString(), p.RawStatus));
sb.Append(", CanNotAskAgain: " + p.NeverAskAgain);
/* p.Status will be either:
- PermissionsHelper.NativeAndroidPermissionStatus.PERMISSION_GRANTED
- PermissionsHelper.NativeAndroidPermissionStatus.PERMISSION_DENIED */
// NeverAskAgain will be true if the user selected the checkbox to disable request for said permission. In this case, granting the permission can only be done from the app settings page
};
}
You can retrieve the status of a permission, and this is recommended in case the user previously declined the permission - it give you the opportunity to explain why the permission us required.
PermissionsHelper.StatusResponse sr = NativeEssentials.Instance.GetAndroidPermissionStatus(PermissionsHelper.Permissions.GET_ACCOUNTS);
Above call's result will be one of the following values:
PermissionsHelper.StatusResponse.PLATFORM_NOT_SUPPORTED
PermissionsHelper.StatusResponse.PERMISSION_RESPONSE_GRANTED
PermissionsHelper.StatusResponse.PERMISSION_RESPONSE_PROVIDE_RATIONALE
PermissionsHelper.StatusResponse.PERMISSION_RESPONSE_CAN_REQUEST
Simply call:
AndroidBuddy.Instance.RequestAndroidPermissions(new string[] {
AndroidBuddyPermissions.Permissions.READ_EXTERNAL_STORAGE
});
Or for multiple permissions at once:
NativeEssentials.Instance.RequestAndroidPermissions(new string[] {
PermissionsHelper.Permissions.GET_ACCOUNTS,
PermissionsHelper.Permissions.READ_EXTERNAL_STORAGE
});
This will present the native permission dialogs, and result in the NativeEssentials.Instance.OnAndroidPermissionCallback
(outlined above) being fired.
Use NativeEssentials' Manifest Editor to create your AndroidManifest or edit required permissions. The editor can be invoked by the Window
→ NativeEssentials
→ Configure AndroidManifest
menu command