GcmListenerService.onMessageReceived() never called - android

I've been looking on the internet for quite a while now, but have not found the answer.
I have followed the examples and tutorials:
https://developers.google.com/cloud-messaging/android/client
I see there are several who have problems with this when they try to send "notification" payload, but for my app, it's only "data" payload.
gcmListner:
public class GCMPushReceiver extends GcmListenerService {
#Override
public void onMessageReceived(String from, Bundle data) {
Log.d("gcmReceiver", "something received");
String message = data.getString("message");
sendNotificasjon(message);
}
}
Manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<permission android:name="com.example.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.NoActionBar" >
<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.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.premission.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.example.myapp"/>
</intent-filter>
</receiver>
<service android:name=".GCMPushResiver" android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<service android:name=".GCMregistrationIntentService" android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
</application>
postman sendt:
{
"to":"SOME_TOLKEN_XXX",
"data": {
"message": "melding"
}
}
postman received:
{
"multicast_id": 73503399375464XXXX,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1471781513806225%030a2fe3f9fdXXX"
}
]
}

Related

How to update firebasemessagingservice to latest version?

I get an error says "error: class, interface, or enum expected" and I found out its from the firebasemessagingservice needs to be updated and I don't know how to do it. Please help.
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
}
}
you put an extra " } " in your code. remove it and recompile
Correct code:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
}
}
And here is the androidManifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=""
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!-- Disable opening of launcher Activity -->
<meta-data
android:name="com.onesignal.NotificationOpened.DEFAULT"
android:value="DISABLE" />
<activity
android:name=""
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=""
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=""
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name="com.tools.vactivities.ActivityRecipesDetail"
android:configChanges="orientation|keyboardHidden|screenSize" />
<!--admob-->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!--fcm-->
<service android:name="com.tools.notification.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".MyFirebaseMessagingService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.tools.notification.NotificationExtenderExample"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
</application>

Firebase notification is not working when the activity is on the foreground

I don't have problem with the notification when my app is in the background. Can someone tell me why?
This is my manifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".CrowdWeather"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".FirebaseNotification">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
This is the FirebaseNotification.java:
public class FirebaseNotification extends FirebaseMessagingService {
public static final String TAG= "Firebase rocks";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d("getFrom",remoteMessage.getFrom()+" ");
Log.d("messageData",remoteMessage.getMessageType()+" ");
Log.d("notificationBody",remoteMessage.getNotification().getBody() +" ");
Log.d("total",remoteMessage.getTtl()+" ");
}
}

Parse Push Notification for android not working

I have looked into many questions but i didn't get any push notifications.
I have added all the permissions and have simple receiver. When i debug it shows the device token to be null. In parse the device is detected and the notification is marked to be sent but not received in my device.
I am sharing the code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Parse.initialize(this, "", "");
}
catch (Exception e){
e.printStackTrace();
}
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Log.e("Tag 1", e == null ? "Succeed to register the app" : "Failed to register the app", e);
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Log.d("Tag 2", "Device token: " + deviceToken);
}
});
Manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arpan.push_notifivations">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:protectionLevel="signature"
android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.example.arpan.push_notifivations.MainActivity">
<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.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>
<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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.example.arpan.push_notifivations" />
</intent-filter>
</receiver>
</application>
</manifest>
The dependencies i added are
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

Android - Pushes not received after the app is closed in parse

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);
}
}
});
}
}

Android: Why I am not receiving the BOOT_COMPLETED intent?

I am testing on an physical device (SAMSUNG ACE GT S5830i)
But I am not receiving the BOOT_COMPLETED intent therefore the service is not Receiver is not starting
This is the code I am using.
public class BootCompleteReceiver extends BroadcastReceiver {
static final String TAG = "InfoService.BroadcastReceiver";
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.e(TAG, "System boot notification received.");
Intent service = new Intent(context, InfoService.class);
context.startService(service);
} else {
Log.e(TAG, "Intent received: " + intent);
}
}
}
This is the Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appengine.paranoid_android.lost"
android:versionCode="2"
android:versionName="1.1">
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity android:name=".InfoSetup"
android:label="#string/activity_name"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LockScreen"
android:label="#string/activity_name"
android:launchMode="singleInstance"
android:clearTaskOnLaunch="true"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<service android:name=".InfoService"
android:label="#string/service_name"/>
<receiver android:name=".BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<!-- <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> -->
Try to add the full path with the package for <receiver android:name=".BootCompleteReceiver">
<receiver android:name="com.appengine.paranoid_android.lost.BootCompleteReceiver">

Categories

Resources