开发者

c2dm why is the wrong c2dm app on my phone getting the message

开发者 https://www.devze.com 2023-03-19 05:27 出处:网络
[UPDATE] (when you read my question this is good to know) I had a small programing bug and now its kind of working. However both apps on the phone arereceiving the same message so there is something i

[UPDATE]

(when you read my question this is good to know)

I had a small programing bug and now its kind of working. However both apps on the phone are receiving the same message so there is something i forgot to do

[END UPDATE]

I have a c2dm app and server set up for month and everything works grate. I have 14 users/friends registered and all pushes works find

I run in to some trouble when I created a sandbox on another computer running the next version of the app and server.

On the sandbox i have changed the package name on the app.

On my phone i have both versions installed fine and dandy.

Only difference is the sandbox version app is communicating with sandbox server (of course).

why is the wrong c2dm app on my phone getting the message?

Now, Why is messages from sandbox app being received by the non-sandbox app?

For a amateur programmer like me the documentation for c2dm is sometimes hard to understand.

Im confused about the:

public static final String EXTRA_APPLICATION_PENDING_INTENT = "app";

Should I write the package name here? Something has to uniquely identify the two apps right?

Another thing i cannot find an answer/documentation for is the registration_id.

I imagine that a phone only have one registration_id but can have multiple c2dm apps?

This was my assumption, gladly correct me if im wrong.

im confused if the problem is in the the way i handle registration_id or the way i send push messages. dont know where to begin here?

[UPDATE]...

    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
        <!-- Receive the actual message -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.bent.blaster" />
        </intent-filter>
        <intent-filter>
        <!-- Receive the registration id -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.bent.blaster" />
        </intent-filter>
</receiver>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.bent.blaster" 
          android:versionCode="1" 
          android:versionName="0.52" 
          android:installLocation="preferExternal">
    <permission android:name="com.bent.blaster.permission.C2D_MESSAGE" android:protectionLevel="signature" />      
    <uses-permission android:name="com.bent.blaster.permission.C2D_MESSAGE" /&g开发者_开发问答t;
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />      
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-sdk android:minSdkVersion="8" />


What i'm writing here i originally got from many pages but the best one that did it for me is http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html#example_server at start i watched the Google I/O 2010 c2dm intro and then i watched this nice lecture http://marakana.com/forums/android/general/272.html but at last that link up there had all i need to make my application work.

The answer: in the manifest where you specified your receiver like this (this is an element inside the application tag):

    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <!-- Receive the actual message -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="de.vogella.android.c2dm" />
        </intent-filter>
        <!-- Receive the registration id -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="de.vogella.android.c2dm" />
        </intent-filter>
    </receiver>

Notice the category tag, I think you didn't assign a category with your Package name either that or one of this permission is missing from (this is an element inside the manifest root tag):

<permission android:name="de.vogella.android.c2dm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

as you already guessed the category specifies that only an apllication with that package or sub packages can read the c2dm messages while the android:protectionLevel="signature" specifies that your c2dm messages are protected by a signature (which is the package).

Have a nice day i hope i helped


When both my apps where receiving the same push i did not
understand that every app had it's own registration_id.

I think they for a short moment had the same registration_id until i uninstalled/reinstalled on of them.


I think the problem i had was because for a short time both apps had the same reg_id. That changed when i 24 hour later uninstalled/reinstalled one of them. Bit confusing at first but after talking to Google Team it's clear now and everything is working. Thanks for your time

0

精彩评论

暂无评论...
验证码 换一张
取 消