简体   繁体   中英

com.google.android.c2dm.permission.SEND permission not granted

I've added com.google.android.c2dm.permission.SEND in the manifest as shown below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lewwe.broadcastsender">
    <uses-permission android:name="com.google.android.c2dm.permission.SEND" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

However, when I use the following code to check if the permission is granted, it returns a result that is not granted

    int res = getApplicationContext().checkCallingOrSelfPermission("com.google.android.c2dm.permission.SEND");
    if (res == PackageManager.PERMISSION_GRANTED)
        System.out.println("GRANTED");
    else
        System.out.println("NOT GRANTED");

I got the following error log when I try to interact with another broadcast receiver from another app that requires the com.google.android.c2dm.permission.SEND permission:

03-31 07:44:21.648 675-691/? W/BroadcastQueue: Permission Denial: broadcasting Intent { flg=0x10 cmp=cn.wps.moffice_eng/cn.wps.moffice.main.gcm.GcmReceiver (has extras) } from com.example.lewwe.broadcastsender (pid=2680, uid=10077) requires com.google.android.c2dm.permission.SEND due to receiver cn.wps.moffice_eng/cn.wps.moffice.main.gcm.GcmReceiver

I am thinking that I have to request for this permission during runtime. If that is true, how do I do that?

The com.google.android.c2dm.permission.SEND permission is held by Google Play services. This prevents other apps from invoking the broadcast receiver.

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdReceiver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM