I tried to update from the gcm.jar to get the GCM from the google-play-services.jar.
I'm using the same code as shown here.
I'm using the same server (node-gcm) as before the change of the client implementation.
I get the registrationId but when I tried to send a notification, GcmBroadcastReceiver.onReceive wasn't called. (I have it on the manifest file)
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
/**
* Created with IntelliJ IDEA.
* User: Eran
* Date: 11/11/13
* Time: 00:43
* To change this template use File | Settings | File Templates.
*/
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("GcmBroadcastReceiver", intent.getDataString());
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gamerlabs.high5poker"
android:versionCode="3"
android:versionName="3.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
>
</supports-screens>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.android.vending.BILLING" />
<permission android:name="com.gameralabs.high5poker.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.gameralabs.high5poker.permission.C2D_MESSAGE" />
<application
android:name="com.gameralabs.classes.HFApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:debuggable="true"
>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity android:name="com.facebook.LoginActivity"/>
<activity
android:name="com.gameralabs.high5poker.HFSplashActivity"
android:screenOrientation="landscape"
android:noHistory="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.gameralabs.high5poker.HFLoginActivity"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
<activity
android:name="com.gameralabs.high5poker.HFLobbyActivity"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
<activity
android:name="com.gameralabs.high5poker.HFGameActivity"
android:noHistory="true"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
<activity android:name="com.gameralabs.high5poker.HFActivity"/>
<receiver
android:name="com.gameralabs.high5poker.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.gameralabs.high5poker" />
</intent-filter>
</receiver>
<service android:name="com.gameralabs.high5poker.GcmIntentService" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
</manifest>
Any help?
You forgot to change the package name in the permissions.
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
Should be
<permission android:name="com.mintmark.TestGcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mintmark.TestGcm.permission.C2D_MESSAGE" />
Just a quick note that the new GCM implementation has been updated to state that we should remove the WakefulBroadcastReceiver from our code.
Per the new sample:
In the app manifest, replace your GcmBroadcastReceiver with
"com.google.android.gms.gcm.GcmReceiver", and replace the current
service declaration that extends IntentService to the new
GcmListenerService
Remove the BroadcastReceiver implementation from your client code
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences
.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
mInformationTextView.setText(getString(R.string.gcm_send_message));
} else {
mInformationTextView.setText(getString(R.string.token_error_message));
}
}
};
#Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE));
}
#Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
super.onPause();
}
Related
This is my service:
public class KeepAliveService extends Service {
Alarm alarm = new Alarm();
public void onCreate()
{
Log.i("","KEEPALIVE onCreate");
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onCreate start command");
return START_STICKY;
}
#Override
public void onStart(Intent intent, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onStart");
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
}
I have it declared like this in my manifest, after my :
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:icon="#drawable/ic_launcher"
android:name="com.vidyo.vidyomod.VidyoModApplication"
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:allowBackup="true"
android:supportsRtl="true"
tools:replace="android:icon">
<activity
android:name="com.vidyo.vidyomod.activities.BaseActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vidyocore" />
</intent-filter>
</activity>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:process=":remote" android:name="com.vidyo.vidyomod.utils.Alarm"></receiver>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
And on my onCreate of my BaseActivity, I do this:
Intent i= new Intent(BaseActivity.this, KeepAliveService.class);
startService(i);
I debugged, my breakpoint at startService does stop, but OnCreate is not called. why?
You have to put your Service and your BroadcastReceiver inside your application tag:
<application>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
Also, you are starting service in a different process.
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
The debugger is attached to your main process. When the new one starts, it has no debugger attached, so it will ignore your breakpoints.
My onReceive() doesn't get invoked at all even when application receives sms message. It doesn't get invoked when the message arrives. Shouldn't it be working in background and only gets invoked when the SMS arrives?
It works fine on a seperate project but not when I'm integraing to my own app.
My Code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
public class SmsBroadcastReciever extends BroadcastReceiver {
private static final String LOG_TAG = "SMSBroadRec";
public static final String SMS_BUNDLE = "pdus";
String SenderNo = "+92----------";
String SenderNo2 = "+92----------";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(LOG_TAG, "In onReceive()");
Bundle bundle = intent.getExtras();
String smsBody;
String address;
try {
if ( !bundle.isEmpty() ){
Log.d(LOG_TAG, "Sms received");
String verificationCode = null;
Object[] sms = (Object[]) bundle.get(SMS_BUNDLE);
for (Object sm : sms) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sm);
smsBody = smsMessage.getMessageBody();
address = smsMessage.getOriginatingAddress();
Log.d(LOG_TAG, address);
if (SenderNo.equals(address) || SenderNo2.equals(address)) {
verificationCode = getVerificationCode(smsBody);
Log.e(LOG_TAG, "OTP received: " + verificationCode);
break;
} else {
Log.d(LOG_TAG, "wrong sender");
break;
}
}
SharedPreferences prefs = context.getSharedPreferences(AppConfig.APP_SCRATCH, Context.MODE_PRIVATE);
SharedPreferences.Editor ed = prefs.edit();
ed.putString(AppConfig.APP_SCRATCH, verificationCode);
if (ed.commit()) {
Log.d(LOG_TAG, "commit succesful"); //added to the shared preferences
} else {
Log.d(LOG_TAG, "commit unsuccessful");
}
} else {
Log.d(LOG_TAG, "Intent must be empty!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
private String getVerificationCode(String message) {
String code = null;
int index = message.indexOf(AppConfig.OTP_DELIMITER);
if (index != -1) {
int start = index + 2;
int length = 8;
code = message.substring(start, start + length);
return code;
}
return code;
}
}
This is the part of the manifest file and i have added permissions too which are READ_SMS, RECEIVE_SMS, WRITE_SMS.
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ubroadkast.nayatel"
android:versionCode="4"
android:versionName="1.3">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="true" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission
android:name="android.permission.RECORD_AUDIO"
android:required="true" />
<uses-permission
android:name="android.permission.CAMERA"
android:required="true" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.SEND_SMS"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.CHANGE_WIFI_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.READ_CONTACTS"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_CONTACTS"
android:required="true" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission android:name="android.permission.WRITE_SMS"
android:required="true"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"
android:required="true"/>
<uses-permission android:name="android.permission.READ_SMS"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Ubroadkast">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider912845522101212"
android:exported="true" />
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:screenOrientation="landscape" />
<activity
android:name=".Home"
android:label="#string/app_name"
android:screenOrientation="portrait" />
<activity
android:name=".Settings"
android:label="Settings"
android:screenOrientation="portrait" />
<activity
android:name=".UserStatus"
android:label="#string/title_activity_user_status" />
<activity
android:name=".login"
android:label="#string/app_name"
android:screenOrientation="portrait" />
<activity
android:name=".SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".facebook"
android:label="UBroadkast Facebook Sign In"
android:screenOrientation="portrait" />
<activity
android:name=".Terms"
android:label="Terms And Conditions"
android:screenOrientation="portrait" />
<activity
android:name=".Signup"
android:label="Sign Up"
android:screenOrientation="portrait" />
<activity
android:name=".rating"
android:label="Ubroadkast Feedback"
android:screenOrientation="portrait" />
<activity
android:name=".change_password"
android:label="Reset Password" />
<activity android:name=".HomeScreen" />
<activity android:name=".Videoview" />
<activity android:name=".URLExtractor" />
<receiver android:name=".SmsBroadcastReciever" android:enabled="true" android:exported="false">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECIEVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
change following line in manifest from
<action android:name="android.provider.Telephony.SMS_RECIEVED"/>
to
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
There's a spelling mistake of word "received".
Actually my application works fine and able to receive GCM push notifications but there are some of devices which are not receiving GCM notification in GCMIntentService only when my app is in background. devices are huwai honor,xiaomi's some models. So bellow is my code, Let me know if anybody gone through this problem earlier. Can anyone please help me on this?
Android manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.testapp"
android:installLocation="preferExternal"
android:versionCode="41"
android:versionName="4.1.7" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<permission
android:name="com.app.testapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.app.testapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_LOGS" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:name="com.app.testapp.MyApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/SampleTheme">
<activity
android:name="com.app.testapp.activity.SplashActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/ActivityTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- GCM -->
<receiver
android:name="com.app.testapp.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.app.testapp" />
</intent-filter>
</receiver>
<!-- Services -->
<service android:name="com.app.testapp.GCMIntentService" />
receiver:
public class GCMBroadcastReceiver extends
com.google.android.gcm.GCMBroadcastReceiver {
#Override
protected String getGCMIntentServiceClassName(Context context) {
return "com.app.testapp.GCMIntentService";
}
}
Service:
package com.app.testapp;
import android.content.Context;
import android.content.Intent;
import com.app.testapp.util.Constants;
import com.app.testapp.util.Logger;
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
private static String TAG = "GCM";
public MyGCMIntentService() {
super(Constants.SENDER_ID);
}
#Override
protected void onError(Context arg0, String arg1) {
Logger.logger(TAG, "onError");
}
String message = null;
#Override
protected void onMessage(Context context, Intent intent) {
message = intent.getExtras().getString("message");
Logger.logger(TAG, "onMessage message=" + message);
}
#Override
protected void onRegistered(Context arg0, String arg1) {
Logger.logger(TAG, "onRegistered");
}
#Override
protected void onUnregistered(Context arg0, String arg1) {
Logger.logger(TAG, "onUnregistered");
}
}
I was updating my app to new GCM 7.5 while I noticed thatgoogle changed lot of things.
take a look at my code
public class GcmIntentService extends GcmListenerService {
public static final int NOTIFICATION_ID = 1;
private static final String TAG = "MyGcmListenerService";
public GcmIntentService() {
super();
}
#Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from);
String message2 = data.getString("payload");
String title = data.getString("title");
String type = data.getString("push_type");
Log.i(TAG, "Message: " + message2 + " PushType:" + type + "title" + title);
for (String key : data.keySet())
{
Log.d("Bundle Debug", key + " = \"" + data.get(key) + "\"");
}
// parseMessage(data);
// sendNotification(message);
}
#Override
public void onDeletedMessages() {
// sendNotification("Deleted messages on server");
}
#Override
public void onMessageSent(String msgId) {
// sendNotification("Upstream message sent. Id=" + msgId);
}
#Override
public void onSendError(String msgId, String error) {
// sendNotification("Upstream message send error. Id=" + msgId + ", error" + error);
}
Now into my problem: The data recieved is null except I logged the bundle there was a collapsekey too.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.was.abcd"
android:versionCode="404080000"
android:versionName="4.8.0" >
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false"
android:xlargeScreens="true" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<!-- * Google Cloud Messaging -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.was.abcd.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.was.abcd.permission.C2D_MESSAGE" />
<!-- Google Cloud Messaging * -->
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:largeHeap="#bool/largeheap"
android:theme="#style/Theme.FullScreen" >
<!-- * Google Cloud Messaging -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- Google Cloud Messaging * -->
<activity
android:name="com.magazine.screens.ShelfActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.magazine.screens.SplashActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.magazine.screens.ReaderActivity"
android:configChanges="keyboardHidden|screenSize"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name="com.magazine.screens.PurchaseActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.magazine.screens.FacebookActivity"
android:configChanges="orientation"
android:hardwareAccelerated="true"
android:icon="#drawable/fb_logo"
android:screenOrientation="portrait" >
</activity>
<!-- * Google Cloud Messaging -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.was.abcd" />
</intent-filter>
</receiver>
<activity
android:name="com.magazine.messaging.NotificationDialogActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
<service
android:name="com.magazine.messaging.GcmIntentService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity
android:name="com.facebook.LoginActivity"
android:label="#string/app_name" >
</activity>
</application>
Please take a look at these points:
As per Google Documentation make use of GCMReceiver instead of WakefulBroadcastReceiver.
Also if you are using gcm.register() please make us of InstanceId as the former has been deprecated.
Hope that helps!!
this is the result in node-gcm server
**
{ multicast_id: 5309930915296650000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1410197314824005%31e4cc17f9fd7ecd' } ] }
**
and my server code in which i retrieve reg_ids from my mongoDb and store them in a string array and pass it to the send method
exports.create = function ( req, res ){
new Comment({
// username : req.body.username,
content : req.body.comment,
created : Date.now()
}).save( function( err, comment, count ){
res.redirect( '/' );
});
reg_ids=[];
User.find({},'gcm_id',function(err,res)
{
for(i=0;i<res.length;i++)
{
reg_ids.push(res[i].gcm_id);
console.log(i+'th entry is '+res[i].gcm_id+'\n');
}
// reg_ids=res.toArray();
var message = new gcm.Message();
message.delay_while_idle = 1;
message.addDataWithKeyValue('message',req.body.comment);
sender.send(message, reg_ids, 4, function (err, result) {
console.log(result);
});
});
};
everything in the server seems fine
and my receiver
here i placed a Log.D to check if receiver is triggered
but it was not
package com.javapapers.android;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("receiver", "received");
ComponentName comp = new ComponentName(context.getPackageName(),
GCMNotificationIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
and finally my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.javapapers.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.javapapers.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.javapapers.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".RegisterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.javapapers.android.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
</activity>
<receiver
android:name=".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" />
<action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION"/>
<category android:name="com.javapapers.android" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
</application>
</manifest>
i've been struck with this from a long time
I would be thankful if someone could help
You have to add the message key and value in order for the message to send.
Like so:
message.addData('message', 'push notification worked');