Why is GCM permission not granted on Android 6?

Background

I'm trying to figure out which application in the office I need to change about my permissions in order to support Android 6 well.

Problem

I found which permission needs confirmation, and which is not, except for one:

<uses-permission android:name=".permission.C2D_MESSAGE"/> 

This permission does not seem to be mentioned anywhere that I am looking for, as one that is not automatically granted, and yet I cannot find where the user can include it as confirmation.

What i tried

To determine which permissions are granted by default and which are not, I simply called this code:

 private void checkPermissionsOfApp(String packageName) { PackageManager pm = getPackageManager(); try { final ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); Log.d("AppLog", "Listing all permissions of app with PackageName: " + applicationInfo.packageName); PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS); //Get Permissions String[] requestedPermissions = packageInfo.requestedPermissions; if (requestedPermissions != null) { for (String permission : requestedPermissions) { boolean permissionGranted = pm.checkPermission(permission, packageName) == PackageManager.PERMISSION_GRANTED; Log.d("AppLog", "permission:" + permission + " permissionGranted:" + permissionGranted); } } } catch (NameNotFoundException e) { e.printStackTrace(); } } 

And the call:

 checkPermissionsOfApp(getPackageName()); 

Using the code above, it is reset for problem resolution, but when using ContextCompat.checkSelfPermission, it says that it is not provided.

Question

How could this be? How can I give the application this permission? Is he mentioned somewhere?

+5
source share
2 answers

The documentation, which was updated in October 2015, still indicates that you need signature permission.

See also Do not receive push notifications from GCM (Android)

As @CommonsWare mentioned, this does not seem to be part of the new run-time permissions check, or at least not considered a “dangerous” permission, and therefore should be automatically provided.

+1
source

ok, I'm not sure why this is so, but permission is only allowed if:

  • Application package name - its prefix
  • you also declare permission as such:

     <permission android:name="com.example.user.androidmtest.permission.C2D_MESSAGE" android:protectionLevel="signature"/> 

The strange thing is that although the code said that permission was not granted when the package name was not added, it worked on the application.

+1
source

Source: https://habr.com/ru/post/1234954/


All Articles