Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 检查广播接收器权限程序_Android_Android Intent_Broadcastreceiver_Android Permissions - Fatal编程技术网

Android 检查广播接收器权限程序

Android 检查广播接收器权限程序,android,android-intent,broadcastreceiver,android-permissions,Android,Android Intent,Broadcastreceiver,Android Permissions,我有一个广播接收器用于我的C2DM(旧)消息,如 <receiver android:name=".C2DMRegistrationReceiver"> <!-- Receive the actual message --> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"

我有一个广播接收器用于我的C2DM(旧)消息,如

    <receiver android:name=".C2DMRegistrationReceiver">
           <!-- Receive the actual message -->
          <intent-filter>
              <action android:name="com.google.android.c2dm.intent.RECEIVE" />
              <category android:name="com.test" />
          </intent-filter>
          <!-- Receive the registration id -->
          <intent-filter>
              <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
              <category android:name="com.test" />
          </intent-filter>
         <intent-filter>
              <action android:name="REGISTRY_RETRY" />
              <category android:name="com.test" />
          </intent-filter>
    </receiver>

我还测试了
context.checkCallingPermission(permission)
its-1以了解C2DM寄存器的意图。Enforce给了我一个SecurityException。

我知道这个问题很老,但我遇到了同样的问题,这是在谷歌搜索中出现的,所以我们开始吧

简单的回答是你不能

所提到的是在执行IPC时使用的,例如使用AIDL

广播接收器未执行IPC,因此无法从广播接收器获取发件人权限

要强制执行该权限,必须在清单中声明广播接收器的权限。这是因为Android在将其交付给接收者之前强制执行了所需的权限


这些权限对于接收方中的所有操作都是通用的。要处理这个问题,您可以按照@commonware的建议将广播接收器分成不同的类。

为什么不简单地将您用于
注册表的逻辑\u RETRY
移动到一个单独的
广播接收器
?如果你想在这个和C2DM之间有共同的代码,可以使用继承或组合。是的,这肯定是最简单的解决方案。我只是好奇,对那个问题有点固执。
<receiver android:name=".C2DMRegistrationReceiver" permission="com.google.android.c2dm.permission.SEND">
  private boolean checkC2DMPermission(Context context) {
    String permission = "com.google.android.c2dm.permission.SEND";
    context.enforceCallingPermission(permission, "Keine C2DM Permission");
    return true;
  }