i want to implement google cloud messaging service CCM. but i am getting forced closed error. i am debugging the code on real device.
My Main.java code is as below:
package com.imran.fgcm;
import com.google.android.gcm.GCMRegistrar;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "123450000");
Toast.makeText(this, regId , Toast.LENGTH_LONG).show();
} else {
// Log.v(TAG, "Already registered");
Toast.makeText(this, "Already registered" , Toast.LENGTH_LONG).show();
}
and my android manifest file is code is as below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.imran.fgcm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<permission android:name="com.imran.fgcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.imran.fgcm.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 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" />
<category android:name="com.imran.fgcm" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
now it had stopped giving forced closed error after i added the GCMIntetservice.java class. but it is still not genrerating the device id. My logcat output is
01-03 11:34:01.023: V/GCMRegistrar(6469): Registering receiver
01-03 11:34:01.023: D/GCMRegistrar(6469): resetting backoff for com.imran.fgcm
01-03 11:34:01.058: V/GCMRegistrar(6469): Registering app com.imran.fgcm of senders 732773857047
01-03 11:34:01.288: D/TextLayoutCache(6469): Using debug level: 0 - Debug Enabled: 0
01-03 11:34:01.843: D/CLIPBOARD(6469): Hide Clipboard dialog at Starting input: finished by someone else... !
01-03 11:34:03.138: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-03 11:34:03.138: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:03.138: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:03.143: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-1
01-03 11:34:03.148: D/GCMBaseIntentService(6469): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-03 11:34:03.148: D/GCMBaseIntentService(6469): Registration error: SERVICE_NOT_AVAILABLE
01-03 11:34:03.148: D/GCMBaseIntentService(6469): Scheduling registration retry, backoff = 4143 (3000)
01-03 11:34:03.213: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:07.318: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.gcm.intent.RETRY
01-03 11:34:07.318: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:07.318: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:07.353: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-2
01-03 11:34:07.368: V/GCMRegistrar(6469): Registering app com.imran.fgcm of senders 732773857047
01-03 11:34:07.398: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:07.443: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-03 11:34:07.443: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:07.443: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:07.453: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-3
01-03 11:34:07.458: D/GCMBaseIntentService(6469): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-03 11:34:07.458: D/GCMBaseIntentService(6469): Registration error: SERVICE_NOT_AVAILABLE
01-03 11:34:07.458: D/GCMBaseIntentService(6469): Scheduling registration retry, backoff = 7873 (6000)
01-03 11:34:07.503: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:07.508: D/dalvikvm(6469): GC_CONCURRENT freed 213K, 4% free 12852K/13319K, paused 3ms+3ms
01-03 11:34:15.343: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.gcm.intent.RETRY
01-03 11:34:15.343: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:15.343: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:15.378: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-4
01-03 11:34:15.393: V/GCMRegistrar(6469): Registering app com.imran.fgcm of senders 732773857047
01-03 11:34:15.428: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:15.498: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-03 11:34:15.498: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:15.498: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:15.503: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-5
01-03 11:34:15.508: D/GCMBaseIntentService(6469): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-03 11:34:15.508: D/GCMBaseIntentService(6469): Registration error: SERVICE_NOT_AVAILABLE
01-03 11:34:15.508: D/GCMBaseIntentService(6469): Scheduling registration retry, backoff = 7347 (12000)
01-03 11:34:15.538: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:22.863: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.gcm.intent.RETRY
01-03 11:34:22.863: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:22.863: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:22.908: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-6
01-03 11:34:22.923: V/GCMRegistrar(6469): Registering app com.imran.fgcm of senders 732773857047
01-03 11:34:22.958: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:22.968: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-03 11:34:22.968: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:22.968: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:22.978: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-7
01-03 11:34:22.978: D/GCMBaseIntentService(6469): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-03 11:34:22.983: D/GCMBaseIntentService(6469): Registration error: SERVICE_NOT_AVAILABLE
01-03 11:34:22.983: D/GCMBaseIntentService(6469): Scheduling registration retry, backoff = 35123 (24000)
01-03 11:34:23.013: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:58.113: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.gcm.intent.RETRY
01-03 11:34:58.118: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:58.118: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:58.153: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-8
01-03 11:34:58.168: V/GCMRegistrar(6469): Registering app com.imran.fgcm of senders 732773857047
01-03 11:34:58.203: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:34:58.228: V/GCMBroadcastReceiver(6469): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-03 11:34:58.228: V/GCMBroadcastReceiver(6469): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:34:58.228: V/GCMBaseIntentService(6469): Acquiring wakelock
01-03 11:34:58.233: V/GCMBaseIntentService(6469): Intent service name: GCMIntentService-732773857047-9
01-03 11:34:58.238: D/GCMBaseIntentService(6469): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-03 11:34:58.238: D/GCMBaseIntentService(6469): Registration error: SERVICE_NOT_AVAILABLE
01-03 11:34:58.238: D/GCMBaseIntentService(6469): Scheduling registration retry, backoff = 67761 (48000)
01-03 11:34:58.268: V/GCMBaseIntentService(6469): Releasing wakelock
01-03 11:35:50.863: D/CLIPBOARD(6469): Hide Clipboard dialog at Starting input: finished by someone else... !
01-03 11:35:52.688: E/ActivityThread(6469): Activity com.imran.fgcm.Main has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@41903ec8 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-03 11:35:52.688: E/ActivityThread(6469): android.app.IntentReceiverLeaked: Activity com.imran.fgcm.Main has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@41903ec8 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1118)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1105)
01-03 11:35:52.688: E/ActivityThread(6469): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:355)
01-03 11:35:52.688: E/ActivityThread(6469): at com.google.android.gcm.GCMRegistrar.setRetryBroadcastReceiver(GCMRegistrar.java:293)
01-03 11:35:52.688: E/ActivityThread(6469): at com.google.android.gcm.GCMRegistrar.register(GCMRegistrar.java:215)
01-03 11:35:52.688: E/ActivityThread(6469): at com.imran.fgcm.Main.onCreate(Main.java:19)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.Activity.performCreate(Activity.java:4470)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-03 11:35:52.688: E/ActivityThread(6469): at android.os.Handler.dispatchMessage(Handler.java:99)
01-03 11:35:52.688: E/ActivityThread(6469): at android.os.Looper.loop(Looper.java:137)
01-03 11:35:52.688: E/ActivityThread(6469): at android.app.ActivityThread.main(ActivityThread.java:4511)
01-03 11:35:52.688: E/ActivityThread(6469): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 11:35:52.688: E/ActivityThread(6469): at java.lang.reflect.Method.invoke(Method.java:511)
01-03 11:35:52.688: E/ActivityThread(6469): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-03 11:35:52.688: E/ActivityThread(6469): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-03 11:35:52.688: E/ActivityThread(6469): at dalvik.system.NativeStart.main(Native Method)
01-03 11:36:06.028: V/GCMRegistrar(6860): Registering receiver
01-03 11:36:06.033: D/GCMRegistrar(6860): resetting backoff for com.imran.fgcm
01-03 11:36:06.053: V/GCMRegistrar(6860): Registering app com.imran.fgcm of senders 732773857047
01-03 11:36:06.093: D/TextLayoutCache(6860): Using debug level: 0 - Debug Enabled: 0
01-03 11:36:06.178: D/CLIPBOARD(6860): Hide Clipboard dialog at Starting input: finished by someone else... !
01-03 11:36:06.203: V/GCMBroadcastReceiver(6860): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-03 11:36:06.203: V/GCMBroadcastReceiver(6860): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:36:06.203: V/GCMBaseIntentService(6860): Acquiring wakelock
01-03 11:36:06.218: V/GCMBaseIntentService(6860): Intent service name: GCMIntentService-732773857047-1
01-03 11:36:06.238: D/GCMBaseIntentService(6860): handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null
01-03 11:36:06.238: D/GCMBaseIntentService(6860): Registration error: SERVICE_NOT_AVAILABLE
01-03 11:36:06.238: D/GCMBaseIntentService(6860): Scheduling registration retry, backoff = 2363 (3000)
01-03 11:36:06.263: V/GCMBaseIntentService(6860): Releasing wakelock
01-03 11:36:08.618: V/GCMBroadcastReceiver(6860): onReceive: com.google.android.gcm.intent.RETRY
01-03 11:36:08.618: V/GCMBroadcastReceiver(6860): GCM IntentService class: com.imran.fgcm.GCMIntentService
01-03 11:36:08.618: V/GCMBaseIntentService(6860): Acquiring wakelock
01-03 11:36:08.653: V/GCMBaseIntentService(6860): Intent service name: GCMIntentService-732773857047-2
01-03 11:36:08.668: E/GCMBaseIntentService(6860): Received invalid token: 1111101101100100100110110001110011001001010011110110001010010110
01-03 11:36:08.668: V/GCMBaseIntentService(6860): Releasing wakelock
TO receive the Notification you need to override the onMessage method from GCMIntentService class as follows
here “mymsg” should me match with your php message attribute. Please Note that both name should be same in php and in android otherwise you will not receive the notification.