Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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 adb命令_Android_Google Cloud Messaging_Android Shell - Fatal编程技术网

用于触发自定义接收器的Android adb命令

用于触发自定义接收器的Android adb命令,android,google-cloud-messaging,android-shell,Android,Google Cloud Messaging,Android Shell,我有下面的接收器,当服务器启动推送通知时,它工作得非常好。我希望能够使用ADB在本地进行测试。 这是我正在使用的命令: adb shell am broadcast -a com.parse.push.intent.RECEIVE --es com.parse.Data "Ipsum Lorem" -n com.jon.ticktock/.CustomParseGCMReceiver 这就是在清单中定义接收者的方式: <receiver android:name=".CustomPars

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

adb shell am broadcast -a com.parse.push.intent.RECEIVE --es com.parse.Data "Ipsum Lorem" -n com.jon.ticktock/.CustomParseGCMReceiver
这就是在清单中定义接收者的方式:

<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>


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

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

  • 原始广播
  • adb shell am广播-com.parse.push.intent.RECEIVE

  • 额外的
  • adb shell am广播-a com.parse.push.intent.RECEIVE--es com.parse.Data“Ipsum Lorem”

  • 具有给定组件
  • adb shell am广播-a com.parse.push.intent.RECEIVE--es com.parse.Data“Ipsum Lorem”-n com.jon.ticktock/.CustomParseGCMReceiver


    检查哪个部分出错。

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

    android:exported=“false”

    但是,当“true”时,我将在Parse SDK“SecurityException”的初始化中崩溃

    Parse.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");
        }
        ...
    }
    
    AllParsePushIntententreCeVersionInternal

    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;
    }
    

    您可以在清单中调用“onReceive”。

    delete
    android:exported=“false”

    因为未报告的组件不能通过shell访问,除非它是根shell。

    我已经编辑了问题(谢谢),您可以尝试以下操作:
    adb shell am broadcast-a com.whereismywifeserver.intent.TEST--es sms_body“TEST from adb”
    ,可能无需指定接收器。无工作。我知道这一点,因为我在onReceive方法中放置了一个日志,但它没有显示。@JY2k再检查两次。1.检查您的
    android:name=“.CustomParseGCMReceiver”
    是否正确指向
    CustomParseGCMReceiver
    类。2.在其他设备或模拟器上测试它。1。大学教师;我不明白你的意思?2.我在多台设备上进行了测试。
    //Parse.initialize(this, "PARSE APPLICATION ID", "PARSE API KEY");