簡體   English   中英

待定意圖未啟動

[英]Pending Intent not launching

我有一個創建通知的活動。 當我使用和AVD模擬器(針對Android 2.1更新1)時,通知將啟動PendingIntent,但在實際設備(運行Android 2.2.1)上根本不啟動。 我缺少哪些基本的東西?

你還沒有發布任何代碼。 所以我分享了對我有用的代碼:

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);

}

這是custom_notification_layout.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>

注意:請勿忘記在適當時清除應用程序圖標如果您設置了上面的標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM