2

I have the following receiver which works perfectly well when the server initiates a push notification. I would like to be able to test it locally using the ADB. This is the command I'm using:

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

And this is how the receiver is defined in the 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>

However the command does not seem to trigger this receiver.

JY2k
  • 2,879
  • 1
  • 31
  • 60
  • I've edited the question (thanks) – JY2k Sep 15 '15 at 14:11
  • You can try this:`adb shell am broadcast -a com.whereismywifeserver.intent.TEST --es sms_body "test from adb"`, might no need to specify receiver. – bjiang Sep 15 '15 at 17:24

3 Answers3

1

You can test if you can receive broadcast step by step.

  1. raw broadcast

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

  1. with extra

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

  1. with given component

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

To check which part is error.

Cao Dongping
  • 969
  • 1
  • 12
  • 29
  • none work. I know this because I have place a log in the onReceive method and it doesn't show. – JY2k Sep 15 '15 at 15:56
  • @JY2k Two more check. 1. Check your `android:name=".CustomParseGCMReceiver"` is correct point to `CustomParseGCMReceiver` class. 2. Test it on other device or emulator. – Cao Dongping Sep 16 '15 at 03:43
  • 1. don;t understand what you mean? 2. I've tested on multiple devices. – JY2k Sep 16 '15 at 12:18
1

When it is Receiver attribute of the "exported" "false", it can not be called directly.

android:exported="false"

However, when the "true", I will crash in the initialization of 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");
    }
    ...
}

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

If you want to really send , you need to build without performing the initialization of Parse SDK. You can send a Broadcast in ADB.

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

You can call the "onReceive".

sakebook
  • 11
  • 1
0

delete android:exported="false" in the Manifest.

Because an unexported component can not be accessed via shell, unless it's a root shell. http://developer.android.com/guide/topics/manifest/receiver-element.html#exported

Swing
  • 858
  • 1
  • 8
  • 21