我已经创建了一个运行连接到HC-06模块的应用程序。还有brodcastlistener可以监听特定的短信并从我的应用程序生成通知。当我点击通知然后它应该加载应用程序活动。但我的应用程序始终连接到蓝牙时运行。但是当点击通知时我想在同一个应用程序中启动一个活动。我可以这样做吗?
答案 0 :(得分:0)
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
Intent notificationIntent = new Intent(context, HomeActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);