C2AP inapp registration: Intent service failed to start

Well, I really don't know what I'm missing here. I am trying to get C2DM to work for our application, and especially the translation processing makes me fight.

We have the BroadcastReceiver app:

public final class AppBroadcastReceiver extends BroadcastReceiver {

    //get an instance if not already present
    public static AppBroadcastReceiver getInstance(final IntentFilter filter) {
        if (instance == null) {
            instance = new GlobalBroadcastReceiver();
        }
        if (filter != null) {
            filter.addAction("com.google.android.c2dm.intent.REGISTRATION";
            filter.addAction("com.google.android.c2dm.intent.RECEIVE");
            filter.addCategory("my.package.name");
        }
        return instance;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        final String broadcastAction = intent.getAction();
        Log.d(logTag, String.format("GlobalBroadcastReceiver::onReceive for action = %s", broadcastAction));

        if ("com.google.android.c2dm.intent.REGISTRATION".equals(broadcastAction)) {
            for (final AppBroadcastListener l : listeners) {
                l.c2dmRegistration(intent);
            }
        } else if ("com.google.android.c2dm.intent.RECEIVE".equals(broadcastAction)) {
            for (final ApplBroadcastListener l : listeners) {
                l.c2dmReceive(intent);
            }
        }//else
    }//onReceive
}

AppBroadcastListener is an interface that implements all our actions to ensure that the corresponding method is at least present. In their methods onResume (), onStop (), operations that are registered and unregistered in the receiver, respectively.

For testing purposes, I have a Debug function that proves to me the following two methods:

public void sendC2DM(View v){
    Intent intent= new Intent();
    intent.setAction(com.google.android.c2dm.intent.RECEIVE);
    intent.putExtra("message","Bender: \"kiss my shiny metal ass!\"");
    intent.addCategory(getPackageName() );

    sendBroadcast(intent);
}

public void registerC2DM(View v){
    Intent registrationIntent = new Intent(com.google.android.c2dm.intent.REGISTRATION);
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
    registrationIntent.putExtra("sender", ourSenderIdregistered@googlemail.com);
    startService(registrationIntent);
}

And in the android manifest, I added the following lines to <application>-tag:

    <receiver
        android:name=".AppBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >

        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="my.package.name" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="my.package.name" />
        </intent-filter>
    </receiver>

, , , BroadcastReceiver onResume(), - , BroadcastReceiver . ., .

"C2DM", , . ( Bender Toast), registerC2DM().startService(registrationIntent); :

Intent { act = com.google.android.c2dm.intent.REGISTRATION( )}: not

, . : android.manifest() gmail.
. gmail, ourSenderIdregistered@googlemail.com, . , . ( , ... ehm no?!). , - , : C

+3
1

, :

c2dm,

com.google.android.c2dm.intent.REGISTER

, ,

com.google.android.c2dm.intent.REGISTRATION

? , :

//false
public void registerC2DM(View v){
    Intent registrationIntent = new Intent(com.google.android.c2dm.intent.REGISTRATION);
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
    registrationIntent.putExtra("sender", ourSenderIdregistered@googlemail.com);
    startService(registrationIntent);
}


//true
public void registerC2DM(View v){
    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", ourSenderIdregistered@googlemail.com);
    startService(registrationIntent);
}

3 , ...:)

+3

All Articles