我面臨着一些問題,需要你們的幫助,我有我的應用程序在前臺,當我從服務器發送的通知,然後通知來與通知圖標。如何在我的應用程序處於前景時關閉通知圖標?
但我需要什麼,當我的應用程序是在前臺用戶正在觀看的通知,然後通知圖標不應該被顯示給用戶。
當我的應用程序在後臺/或應用程序時,未啓動然後通知圖標通知要來,並且用戶按壓的通知圖標,然後通知圖標被擱置了該工作得很好。
我曾試圖:
if(getIntent()!=null){
Log.e("getIntent","getIntent");
broadcastReciver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(NOTIFY_ACTIVITY_ACTION))
{
if(intent.getExtras().getBoolean("reload")){
int notificationId = intent.getIntExtra("notificationId", 0);
Log.e("notificationId","notificationId---"+notificationId);
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(notificationId);
setFragmentView(0);
//finish();
}
}
}
};
}
在onMessageReceived:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("notificationId",NOTIFICATION_ID);
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.splash_logo)
.setContentTitle("Logizo")
.setContentText("New Order Arrived")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_ID/* ID of notification */, notificationBuilder.build());
你究竟想做什麼?你不想讓你的應用程序在前臺顯示通知? – Prashant
@Prashant是現在解決了。 –