我不知道这里有正确的用语,但是当通知发布时,通知抽屉" (您从屏幕顶部拉出并查看所有应用的大量通知列表的内容),有应用程序的通知。
我希望在点击此通知后恢复我的应用。但是,我没有在通知构建器中看到任何相关方法。这还有可能吗?
我的代码:
private void launchNotification(Context context) {
String notificationText = "Click to resume app!";
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.notification_small_icon);
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
notificationBuilder.setContentText(notificationText);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());
}
答案 0 :(得分:0)
试试这个
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b = new NotificationCompat.Builder(getApplicationContext());
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("Ticker")
.setContentTitle("title")
.setContentText("message")
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
.setContentIntent(contentIntent)
.setContentInfo("Info");
Random r = new Random();
int randomNo = r.nextInt(100000000 + 1);
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(randomNo, b.build());
答案 1 :(得分:0)
尝试此操作...通知意图您可以将应用程序打开到定向活动。
hyphens: manual