i've got a problem showing notification on my android device, i utilize parse.com website, is there a better way to send notification? and how can i solve this?
This is my Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bpartyorg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<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.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.androidhive.pushnotifications.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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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.example.bpartyorg.ShowPopUp"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.example.bpartyorg.MyCustomReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.example.bpartyorg.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
This i my MyReceiver
package com.example.bpartyorg;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.DialogFragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null)
{
Log.d(TAG, "Receiver intent null");
}
else
{
String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals("com.example.bpartyorg.UPDATE_STATUS"))
{
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.equals("customdata"))
{
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.getApplicationContext().startActivity(pupInt);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
i use PARSE.COM in "pushes sent" i have "1", so it sends push notification, but my android device doesn't show it how can i solve this problem?
Related
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".
I have not received push on my device Xiaomi redmi 2. In other device receiving the push function normally even with the app closed.
I tested on a Samsung device and it worked perfectly, I could not understand why no notification arrives on my device
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter" >
<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.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
<application
android:name=".StarterApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.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.parse.starter" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<meta-data android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher"/>
</application>
</manifest>
java:
import android.app.Application;
import android.util.Log;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.ParseUser;
import com.parse.SaveCallback;
public class StarterApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
ParseUser.enableAutomaticUser();
// Add your initialization code here
Parse.initialize(this, "us5HP0AWX4sdyHA1zjJEW6HdF9akjURdOIr1cAVF", "XunSChL6PglIFwfhP7AYyZ1UkHMpJ2Q98vZjjdqp");
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", ParseUser.getCurrentUser());
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
}
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');
I can get bts info in one activity , but when use that code in OnRecive of this code it is not work , Why this code can not get bts tower?
package com.example.testneighbore;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import java.util.List;
public class SMS extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Toast.makeText(context, " START ", Toast.LENGTH_LONG).show();
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
List<NeighboringCellInfo> NeighboringList = telephonyManager.getNeighboringCellInfo();
String retStr="";
for (int i = 0; i < NeighboringList.size(); i++) {
int cid = NeighboringList.get(i).getCid();
int lac = NeighboringList.get(i).getLac();
retStr += "&" + cid + "," + lac + ",";
}
Toast.makeText(context,"Print: "+ retStr, Toast.LENGTH_LONG).show();
Toast.makeText(context, " END ", Toast.LENGTH_LONG).show();
}
}
}
My AndroidManifest.xml is :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testneighbore"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testneighbore.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SMS">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES"/>
</manifest>
I think my main problem is with Context, but I'm not sure.
your problem is related to context, because the context is involved with receiving sms. To solve this problem, you have to make thread and get bts info in it. it is better that your thread to be call within ~20 seconds delay . you can use omething like this in OnRecieve()
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// get info
}
}, 20000);
I don't know where is the problem with my manifest, the problem is only with android 2.3.6. In my tablet with android 4.1.2 it's receiving the messages. I have received the registration ID with 2.3.6 but the messages are never received. Please,someone could help me?:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ciqtech.quicky.mobile.passenger"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission
android:name="com.ciqtech.quicky.mobile.passenger.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.MAPS_RECEIVE" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
GCM CONFIGURATION
-->
<permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="..." />
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity android:name="com.facebook.LoginActivity" >
</activity>
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.PassengerActivity"
android:label="#string/title_activity_passenger" >
</activity>
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.LoginActivity"
android:label="#string/title_activity_login" >
</activity>
<!-- GCM
RECEIVER
-->
<receiver
android:name="com.ciqtech.quicky.mobile.passenger.broadcast_receivers.QuickyGCMBroadcastReceiver"
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.ciqtech.quicky.mobile.passenger" />
</intent-filter>
</receiver>
<service android:name=".services.GCMIntentService" android:enabled="true" />
</application>
</manifest>
UPDATE
QuickyGCMBroadcastReceiver
package com.ciqtech.quicky.mobile.passenger.broadcast_receivers;
import com.ciqtech.quicky.mobile.passenger.services.GCMIntentService;
import com.google.android.gcm.GCMBroadcastReceiver;
import android.content.Context;
import android.util.Log;
public class QuickyGCMBroadcastReceiver extends GCMBroadcastReceiver {
final String TAG = "QuickyGCMBroadcastReceiver";
#Override
protected String getGCMIntentServiceClassName(Context context) {
Log.d(TAG, "GET GCM INTENT SERVICE CLASS NAME");
return GCMIntentService.class.getName();
}
}
GCMIntentService. The device register correctly in android 2.3.x but it doesn't receive the messages, my message log on onMessage isn't never called, while in android 4.1.x it works perfectly. Thanks for your help.
package com.ciqtech.quicky.mobile.passenger.services;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.ciqtech.quicky.mobile.passenger.R;
import com.ciqtech.quicky.mobile.passenger.activities.LoginActivity;
import com.ciqtech.quicky.mobile.passenger.activities.PassengerActivity;
import com.ciqtech.quicky.mobile.passenger.broadcast_receivers.Device;
import com.ciqtech.quicky.mobile.passenger.configs.GCMSettings;
import com.ciqtech.quicky.mobile.passenger.dto.NotificationDTO;
import com.ciqtech.quicky.mobile.passenger.utils.SessionManager;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gms.gcm.GoogleCloudMessaging;
public class GCMIntentService extends GCMBaseIntentService {
Context ctx;
SharedPreferences prefs;
final String TAG = "GCMIntentService";
NotificationCompat.Builder builder;
public GCMIntentService() {
super(GCMSettings.GCM_SENDER);
}
#Override
public void onError(Context context, String errorId) {
Log.d(TAG + " - onError", "Messaging registration error: " + errorId);
}
#Override
protected boolean onRecoverableError(Context context, String errorId) {
Log.d(TAG + "- onRecoverableError", "Received recoverable error: " + errorId);
return super.onRecoverableError(context, errorId);
}
#Override
protected void onMessage(Context context, Intent intent) {
String msg = intent.getExtras().getString( "msg" );
Log.d(TAG, " - onMessage: " + msg);
// [more code]
}
// Put the GCM message into a notification and post it.
private void sendNotification(String msg) {
}
#Override
public void onRegistered(Context context, String registrationId) {
Log.d(TAG + " - onRegistered", "onRegistered()");
prefs = context.getSharedPreferences("Quickytaxi-Notifications",0);
String deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
SessionManager session = new SessionManager(context);
String uid = session.getUserDetails().get("id");
Log.d(TAG, deviceID + " " + registrationId + " " + uid);
Device.register(deviceID, registrationId, uid);
}
#Override
protected void onUnregistered(Context context, String s) {
Log.d(TAG + "- onUnregistered", "onUnregistered()");
String deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
Device.unregister(deviceID);
}
public void notify(NotificationDTO notificationDTO, Intent intent){
}
}
Try following workaround not using (so far as I know) any deprecated classes. Add the action "com.google.android.c2dm.intent.REGISTRATION" to the GCMBroadcastReceiver in your manifest. This will enable to receive the registration_id at your GCMBroadcastReceiver.
<receiver
android:name="YOUR_PACKAGE_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" />
<category android:name="YOUR_PACKAGE_NAME" />
</intent-filter>
</receiver>
After that your GCMBroadcastReceiver is able to receive the registration_id:
public void onReceive(Context context, Intent intent)
{
String regId = intent.getExtras().getString("registration_id");
if(regId != null && !regId.equals(""))
{
/* Do what ever you want with the regId eg. send it to your server */
}
}
Although I still get a SERVICE_NOT_AVAILABLE error, I can handle the registration_id in my GCMBroadcastReceiver and I am able to send messages to my smartphone. Quite weird, but it works for me.
I was facing same problem from last one week but simple solutions is Android.Manifest File Changes.You have added only two permissions for C2D_MESSAGE but it required three.
<permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.C2D_MESSAGE" />
It will work for all android versions.
Ensure that your package name specified in the manifest matches the category name specified in the GCM receiver configuration. According to the manifest provided Your package name should look as below :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ciqtech.quicky.mobile.passenger"
android:versionCode="1"
android:versionName="1.0" >
Similar question can be found here GCM Push RECEIVE category Name on Android OS < 4.1. Hope that helps.