firebase cloud messaging not received notification in some device


firebase cloud messaging not received notification in some device



I used FCM to push notification, its work successfully in background and foreground mode, in the device that I used to debug while another device does not work in background mode.
here is my code I wish ur help to know what the issue .is it from phone so how to fix it ? or from google services.
here MyFirebaseInstanceIDService


public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

SharedPrefManager sharedPrefManager;
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.

String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.wtf("myfirebase", "Refreshed token: " + refreshedToken);

sendRegistrationToServer(refreshedToken);

}

public void sendRegistrationToServer(String refreshedToken )
{
sharedPrefManager=new SharedPrefManager(getApplicationContext());

ApiInterface apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<Result> call = apiInterface.insert_token(sharedPrefManager.getPrefVal("id_shared"),refreshedToken);
call.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {

}

@Override
public void onFailure(Call<Result> call, Throwable t) {
//Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_LONG).show();

}
}
);

}

}



here MyFirebaseMessagingService


public class MyFirebaseMessagingService extends FirebaseMessagingService {

String TAG ="fbmessage";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...

createNotification("Hello",remoteMessage.getData().get("body"));

}

public void createNotification(String title, String sub) {
// Prepare intent which is triggered if the
// notification is selected
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

// PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0 /* request code */, intent,PendingIntent.FLAG_UPDATE_CURRENT);

// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(sub).setSmallIcon(R.drawable.biglogored)
.setContentIntent(pendingIntent)
.build();
long vibrate = { 0, 100, 200, 300 };
noti.vibrate = vibrate;
NotificationManager notificationManager = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);

}

}



here the services which i set it in mainfist


<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>



here the PHP code.


$fields = array('to'=>$token,
'data'=>array('title'=>$title,'body'=> $Message));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_IPRESOLVE,CURL_IPRESOLV_V4);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);





Please, post your code as text and not as images.
– Ondrej K.
Jun 29 at 21:41





ok I edited to text, thanx
– Alaa Al-Rayes
Jun 30 at 3:35









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV