2

我有以下接收器,当服务器启动推送通知时它工作得很好。我希望能够使用 ADB 在本地对其进行测试。这是我正在使用的命令:

adb shell am broadcast -a com.parse.push.intent.RECEIVE --es com.parse.Data "Ipsum Lorem" -n com.jon.ticktock/.CustomParseGCMReceiver

这就是在 Manifest 中定义接收者的方式:

<receiver android:name=".CustomParseGCMReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="com.parse.push.intent.RECEIVE" />
        <action android:name="com.parse.push.intent.DELETE" />
        <action android:name="com.parse.push.intent.OPEN" />
    </intent-filter>
</receiver>

但是,该命令似乎不会触发此接收器。

4

3 回答 3

1

当为“exported”“false”的Receiver属性时,不能直接调用。

安卓:导出=“假”

但是,当“真”时,我会在 Parse SDK 的初始化中崩溃“SecurityException”。

解析.java

public static void initialize(Context context, String applicationId, String clientKey) {
    ...
    if (!allParsePushIntentReceiversInternal()) {
    throw new SecurityException("To prevent external tampering to your app's notifications, " +
          "all receivers registered to handle the following actions must have " +
          "their exported attributes set to false: com.parse.push.intent.RECEIVE, "+
          "com.parse.push.intent.OPEN, com.parse.push.intent.DELETE");
    }
    ...
}

allParsePushIntentReceiversInternal

private static boolean allParsePushIntentReceiversInternal() {
    List<ResolveInfo> intentReceivers = ManifestInfo.getIntentReceivers(
        ParsePushBroadcastReceiver.ACTION_PUSH_RECEIVE,
        ParsePushBroadcastReceiver.ACTION_PUSH_DELETE,
        ParsePushBroadcastReceiver.ACTION_PUSH_OPEN);

    for (ResolveInfo resolveInfo : intentReceivers) {
        if (resolveInfo.activityInfo.exported) {
            return false;
        }
    }
    return true;
}

如果要真正发送,则需要在不执行 Parse SDK 初始化的情况下进行构建。您可以在 ADB 中发送广播。

//Parse.initialize(this, "PARSE APPLICATION ID", "PARSE API KEY");

您可以调用“onReceive”。

于 2015-10-23T13:18:31.410 回答
1

您可以逐步测试是否可以接收广播。

  1. 原始广播

adb shell am broadcast -a com.parse.push.intent.RECEIVE

  1. 有额外的

adb shell am broadcast -a com.parse.push.intent.RECEIVE --es com.parse.Data "Ipsum Lorem"

  1. 具有给定的组件

adb shell am broadcast -a com.parse.push.intent.RECEIVE --es com.parse.Data "Ipsum Lorem" -n com.jon.ticktock/.CustomParseGCMReceiver

检查哪个部分是错误的。

于 2015-09-15T14:45:48.847 回答
0

android:exported="false"在 Manifest 中删除。

因为无法通过 shell 访问未导出的组件,除非它是根 shell。 http://developer.android.com/guide/topics/manifest/receiver-element.html#exported

于 2015-12-04T01:15:36.760 回答