Android 未决意图不启动
我有一个创建通知的活动。当我使用和AVD模拟器(针对Android 2.1 update 1)时,通知会启动PendingEvent,但在实际设备上根本不会启动(运行Android 2.2.1)。有什么基本的东西我遗漏了吗?您没有发布任何代码。因此,我正在分享我的代码,这些代码对我很有用:Android 未决意图不启动,android,android-pendingintent,Android,Android Pendingintent,我有一个创建通知的活动。当我使用和AVD模拟器(针对Android 2.1 update 1)时,通知会启动PendingEvent,但在实际设备上根本不会启动(运行Android 2.2.1)。有什么基本的东西我遗漏了吗?您没有发布任何代码。因此,我正在分享我的代码,这些代码对我很有用: public static void notifyIcon(Context context){ NotificationManager notifier = (NotificationManager) co
public static void notifyIcon(Context context){
NotificationManager notifier = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.your_app_notification, "", System.currentTimeMillis());
/**
*Setting these flags will stop clearing your icon
*from the status bar if the user does clear all
*notifications.
*/
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
notification.contentView = contentView;
//If you want to open any activity on the click of the icon.
Intent notificationIntent = new Intent(context, YourActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.setLatestEventInfo(context, "title", null, contentIntent);
notifier.notify(1, notification);
//To cancel the icon ...
notifier.cancel(1);
}
下面是自定义通知布局.xml
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp" >
</LinearLayout>
注意:如果您设置了上述标志,请不要忘记在适当的时候清除应用程序图标。如果您在代码中保留
通知程序.cancel()
,通知是否会显示?我的代码几乎相同,只是我的PendingEvent设置了标志\u UPDATE\u CURRENT
和我的通知设置了标志\u AUTO\u CANCEL
。我不会取消我的通知管理员通知。取消(1);用于删除通知,如果不想删除,请将其保留。。。