Android ANAZON SNS (GCM) issue

I have an issue with Amazon SNS service in Android app. I am using Amazon SNS push service. See this link http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html for more details on Amazon SNS service.

I implemented it like in the Amazon samples http://docs.aws.amazon.com/sns/latest/dg/mobile-push-gcm.html and it worked great for me for a while.

But lately, some users using Android 4.0.3 or 4.0.4 reported me a report with an incorrect working push service. I started researching this problem and found strange behavior of this: sometimes my push receiver clicks on a message - "unregistered = my.package.name" instead of the real message I clicked on.

Here is my AndroidManifest.xml code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.package"
    android:versionCode="14"
    android:versionName="1.49" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="com.google.android.c2dm.permission.REGISTER" />

    <permission android:name="my.package.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="my.package.permission.C2D_MESSAGE" />

    <application
        android:name="com.test.package.AppClass"
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <receiver
            android:name="com.test.package.ExternalReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.REGISTER" />

                <category android:name="com.test.package" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

      

Here is my ExternalReceiver:

    public class ExternalReceiver extends BroadcastReceiver {
    private static final String ACTION_REGISTRATION =  "com.google.android.c2dm.intent.REGISTRATION";
    private static final String ACTION_RECEIVE = "com.google.android.c2dm.intent.RECEIVE";
    private static final String UNREGISTERED = "unregistered";

    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            Bundle extras = intent.getExtras();

            String message = "";
            String action = intent.getAction();

            if (extras != null) {
                for (String key : extras.keySet()) {
                    message += key + "=" + extras.getString(key) + "\n";
                }
            }

            if (action.equalsIgnoreCase(ACTION_REGISTRATION)) {
                Log.i(TAG, message);
            } else if (action.equalsIgnoreCase(ACTION_RECEIVE)) {
                String pushText = intent.getStringExtra("default");
                processPush(pushText, context);
            }
        }
    }
}

      

And these are the LogCat messages I have when I clicked on an already registered device some message:

12-20 13:32:33.683: I/Test ExtrernalReceiver(5353): registration_id=APA91bFQymRS8NOPgHDlFicpQIXDwvgWQR6_CVYC1Le-Cmhl8uTzPDPVbe1yjjKdQjMsilo4XGImAiX8ORnkZiySjbwgTmzC7lC8T3Plch1m0faKiiqc6hl75msTBmMIBhtLtKdtz_R6CY1yjygvyWplTh_yq04tCaOKCfcDcsYwYbQdmscyfUA
12-20 13:32:49.693: I/Test ExtrernalReceiver(5353): registration_id=APA91bFQymRS8NOPgHDlFicpQIXDwvgWQR6_CVYC1Le-Cmhl8uTzPDPVbe1yjjKdQjMsilo4XGImAiX8ORnkZiySjbwgTmzC7lC8T3Plch1m0faKiiqc6hl75msTBmMIBhtLtKdtz_R6CY1yjygvyWplTh_yq04tCaOKCfcDcsYwYbQdmscyfUA
12-20 13:33:19.763: I/Test ExtrernalReceiver(5353): unregistered=my.package

      

+3


source to share


1 answer


Your recipient record, if you are a manifest, has run out a bit. The intent filter category tag must match your application (see 2nd line package="my.package"

). One of these package names is incorrect.

    <receiver
        android:name="com.test.package.ExternalReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.REGISTER" />
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="my.package" />
        </intent-filter>
    </receiver>

      

if the actual package is "com.test.package" change both links

<category android:name="com.test.package" />

      

and



<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.test.package"

      

I would advise here to use the updated Google Play Services example in the support library (it uses the WakefulBroadcastReceiver support library and no longer needs to configure the broadcast receiver for the following:

            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.REGISTER" />

      

... since you can register your application with GCM:

                GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
                String regId = gcm.register(senderId);

      

+1


source







All Articles