0

私はNotificationManager正常に作成するを持っていますNotification

 private void showNotification() {
    Notification notification = new Notification(R.drawable.snog_icon, getString(R.string.sn_g_entering_beacon_mode_),
            System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this notification
    Intent i = new Intent(this, SnogActivity.class);
    i.putExtra("fromNotification", "yes");

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    notification.setLatestEventInfo(this, getString(R.string.sn_g_avalanche_buddy),
                   getString(R.string.beacon_mode_activated_), contentIntent);
    notification.flags |= Notification.FLAG_ONGOING_EVENT; // Notification.DEFAULT_ALL 

    // Send the notification.
    // We use a string id because it is a unique number.  We use it later to cancel.
    mNM.notify(R.string.service_started, notification);
}

その部分は正常に機能し、通知が表示され、通知をタップすると正しいアクティビティが開始されます。アプリの後半で、簡単な通知を通知しようとします。

Notification not = new Notification(R.drawable.snog_icon, "checker", System.currentTimeMillis());
not.flags |= Notification.DEFAULT_ALL;

mNM.notify(R.string.checker, not);

そして、それはnotify()呼び出しでアプリをクラッシュさせIllegalArgumentExceptionます。私はNotificationCompat.Builderかなりのインターネットの結果に従って使用することになっていますが、それも利用できません。

4

1 に答える 1

0

この例外を修正することもできますが、NotifcationCompatを使用して、最初から修正したいと思います。互換性パッケージで利用可能です。Eclipseプロジェクトを右クリックして追加する必要があります>Androidツール>サポートライブラリの追加

この後、プロジェクトでNotificationCompatを使用できるようになります...次に、次のサイトにアクセスします:http: //developer.android.com/guide/topics/ui/notifiers/notifications.html

そこにはいくつかの素晴らしくて単純な例があります。

幸運を!

于 2012-11-22T20:50:33.053 に答える