我有一个任务,在该任务中,我必须使用BroadcastReceiver
以及SMS上的地址和内容来显示Notification
中的传入消息。现在我必须点击才能在数据库中插入sms值。当任务完成后,我希望它从活动中清除。是否有可能在活动内部为传入的短信创建通知?如何在android中的活动内部创建通知?
-3
A
回答
0
您可以试试这不会生成您自己的通知。
@SuppressWarnings("deprecation")
private static void generateNotification(Context context) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "New Contact Added",
when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);
PendingIntent intent = PendingIntent.getActivity(context, iUniqueId,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, "New", intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(2, notification);
}
+0
这是'BroadcastReceiver'里面的工作吗? –
+0
是的当你将消息接收器消息,里面,它会工作 –
相关问题
- 1. 在BroadcastReceiver内部创建通知:Android
- 2. 仅当尚未创建活动时,如何从活动通知创建活动?
- 3. 在android通知中创建一个地图活动
- 4. 在Android中点击通知时避免重新创建活动
- 5. 如何创建Android通知?
- 6. 如何在摆动中创建通知
- 7. Android自动创建通知
- 8. 从非活动类创建通知
- 9. 如何通知不活动的活动?
- 10. 返回创建通知活动的主要活动
- 11. 通知不在android中开始活动
- 12. Android - 创建通知
- 13. Android的通知 - 如何把活动前没有召回活动
- 14. Android:如何通知其他活动完成的活动()
- 15. Android如何创建动态活动
- 16. 拖动活动,如通知android
- 17. Android推送通知无法重新创建活动
- 18. 在android中动态创建活动
- 19. Android通知 - 非活动类
- 20. Android通知恢复活动
- 21. Android通知刷新活动
- 22. Android:活动间通知
- 23. 按下通知时重新创建活动 - 如何?
- 24. 如何从Phonegap创建Android通知?
- 25. 如何在通知管理器(Android)上创建动态ID?
- 26. 如何在Android中通知开始当前活动时收到通知
- 27. 活动内部的通知栏(或类似内容)
- 28. 在通知中使用TaskStackBuilder重新创建活动
- 29. 通话的Android活动从通知
- 30. 在android中创建自定义通知
是的,这是可能的。现在的问题是什么? –
必须在活动内部显示传入消息的通知。 –
您正在询问密码。关于如何生成通知有一千个答案,您只需要了解方式。 Btw答案是由某人发布。 –