我已经创建了一个应用服务器,使用该服务器我向我的app发送通知。app收到通知,但是问题是该应用收到的通知来自我在服务器端编写的脚本。 MyFirebaseMessagingService上编写的代码扩展了FirebaseMessagingService,但未执行。
public class MyFirebaseMessagingService extends
FirebaseMessagingService {
public MyFirebaseMessagingService() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//super.onMessageReceived(remoteMessage);
Log.i("Remote Message", remoteMessage.getNotification().getBody().toString());
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String remoteMessage) {
Log.i("AAAAAAAAAAAA","AAAAAAAAAAA");
Intent i = new Intent(this, Tips_Notification.class);
//i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent
itself)
stackBuilder.addParentStack(Tips_Notification.class);
// Adds the Intent that starts the Activity to the top of the
stack
stackBuilder.addNextIntent(i);
PendingIntent pi = stackBuilder.getPendingIntent( 0,
PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new
NotificationCompat.Builder(this);
//notificationBuilder.setSmallIcon(R.drawable.ic_stat_name);
notificationBuilder.setContentTitle("Abhishek ghatge");
notificationBuilder.setContentText("Alert Trade School
notification");notificationBuilder.setAutoCancel(false);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setContentIntent(pi);
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND|Notification.
DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE);
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
}
}
<?php
include '../config/connection.php';
include '../push_notification/push.php';
include '../push_notification/firebase.php';
echo $string = $_POST['message'];
/*
$firebase = new Firebase();
$push = new Push();
$push->setTitle("Trade School");
$push->setMessage($string);
//$push->setPayload($payload);
$json = $push->getPush();
*/
该通知来自上述代码。 我从MyFirebaseMessagingService中删除NotificationCompat代码 上课,但该应用仍会收到通知。
I want a pop-up notification like Whatsapp shows.