I have one question about C2DM, I registered yesterday and I got email that my mail and app are approved. From app I get registration_id, I have broadcast_receiver like
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
android.util.Log.d("REG_1","onReceive");
if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
final String registrationId = intent
.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
android.util.Log.d("REG_1",registrationId);
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
String token = prefs.getString("token", null);
String userId;
try {
userId = RestClient.getUserIdByToken(token).getString(
"user_id");
Intent i = new Intent(context, RegService.class);
i.putExtra("c2dm_registration_id",registrationId);
i.putExtra("token", token);
i.putExtra("user_id", userId);
i.putExtra("device_id", "bla");
i.setAction(android.content.Intent.ACTION_VIEW);
context.startService(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
saveRegistrationId(context, registrationId);
}
and I enter in this function during registration and I send messages from command line like
curl https://www.google.com/accounts/ClientLogin -d [email protected] -d "Passwd=MY_PASSWORD" -d accountType=GOOGLE -d source=Google-cURL-Example -d service=ac2dm
and
curl --header "Authorization: GoogleLogin auth=DQAAAMMAAAC58D4X-5zjQFdYuGz7D9DhnuN4OUiz_gCtOJRSNwNLN0-wxveAEVL985hNKJXyQ_7U4sTfsUGh_3OXMLKpB5PNN1eaI4AfT19LaJ1vGJCZ_sSE0NDqGsC0mZVdMsYbE2Sz1r1WE_p5WNokfGMRdmxIHl0QCWb43lTD3iCvr51ujmnHnvpn2mDLWr6j9DtyDxADRw1to2iGgpJNelXmIA8tOzjyqF3szN-N2IYnihJ8H2t3G5wotOWy1EahB43Lv2NPdlV-A4yVSbdsYGM_AVdd" "https://android.apis.google.com/c2dm/send" -d registration_id=APA91bHhbsPedDVnYCaSJQMhWjfjK3W9jOaMgVITUHqw97w4fF_8fermSG22CzFvpPuTyRKnJFyJ_iwfgJEJ4uidURxuHZCCBuPtGAsv6NeVipmOd53Fkru_A3NW3cpIMo9gvuVxIB0QqxOvl1SmVfqRzD4qQfSNaw -d "data.test_result=This data will be send to your application as payload" -d collapse_key=2
id=0:1322216144957968%b3c4048a00000032
but it never enter in onHandle function of broadcatreceiver.
<receiver
android:name="com.surveyce.android.c2dm.C2DMRegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter >
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.surveyce.android" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter >
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.surveyce.android" />
</intent-filter>
</receiver>
...
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--<uses-permission android:name="android.permission.WAKE_LOCK" />-->
<uses-permission android:name="com.surveyce.android.permission.C2D_MESSAGE" />
<permission
android:name="com.surveyce.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Did anybody have similar strange problems that get registrationId and send messages but do not receive message on phone ? What can be problem, maybe because I registered yesterday ( but how than I get rigistrationId and auth for that account) ? Package names and gmail are account are 100% ok.
Add a service tag [write your receiver name in below service tag which is sub class of C2DMBaseReceiver]
<service android:name=".C2DMReceiver" />
Use C2DMBroadcastReceiver Instead of C2DMRegistrationReceiver
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">