Я использую GCM для уведомления.android GCM push, без вибрации, без звука, без головы
Я прошу сервер приложений отправить push-уведомление пользователю, и сервер делает это.
При получении push-уведомления сообщение хорошо отображается на экране. , но он не производит никакого звука или вибрации, конечно, нет головы.
так, вот мой код конечно, я уже добавил два используют-разрешения (WAKE_LOCK, вибрирует)
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
private static final String TAG = "FirebaseMsgService";
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// sendPushNotification(remoteMessage.getData().get("message"));
if(remoteMessage.getData().size() > 0){
sendPushNotification(remoteMessage.getNotification().getBody());
}
}
private void sendPushNotification(String message) {
System.out.println("received message : " + message);
Intent intent = new Intent(this, Activity_Login_Main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 //Request code
, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.backicon).setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setContentTitle("Push Title ")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wakelock.acquire(5000);
notificationManager.notify(0 // ID of notification
, notificationBuilder.build());
}
}
я проверил с бревенчатыми, если работает два метода (onMessageReceived, sendPushNotification). и я нашел, что это хорошо работает ... –
Хорошо, это работает, если приложение находится в фоновом режиме. –