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.

2
  • I've edited the question (thanks) Commented Sep 15, 2015 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. Commented Sep 15, 2015 at 17:24

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

none work. I know this because I have place a log in the onReceive method and it doesn't show.
@JY2k Two more check. 1. Check your android:name=".CustomParseGCMReceiver" is correct point to CustomParseGCMReceiver class. 2. Test it on other device or emulator.
1. don;t understand what you mean? 2. I've tested on multiple devices.
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".

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.