1

Facebook などのアプリケーションが、コンテンツに応じて通知のタイトルとロゴをどのように変更するかを知りたいです。

たとえば、Facebook では、タグ付けされると、別のタイトルと別のロゴが表示されます。

notify を使用して一意の通知を作成できるはずだと思います。これについて明確な例は見つかりませんが。

私のGenerateNotification:

private static void generateNotification(Context context, String message, String url) {
    int icon = R.drawable.ic_launcher;

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager)
    context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);

    String title = context.getString(R.string.app_name);

    Intent notificationIntent = new Intent(context, ShowChange.class);
    notificationIntent.putExtra ("url",url);
    // set intent so it does not start a new activity
    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;

    // Play default notification sound
    notification.defaults |= Notification.DEFAULT_SOUND;

    //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

    // Vibrate if vibrate is enabled
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);       
}
4

1 に答える 1

0

次のようなものにする必要があります:(これは基本的に、いくつかの変更を加えたコードです)

public static void generateNotification(Context context, String message, String url,int icon_from_drawable) { int icon = icon_from_drawable;

long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);

String title = context.getString(R.string.app_name);

Intent notificationIntent = new Intent(context, ShowChange.class);
notificationIntent.putExtra ("url",url);
// set intent so it does not start a new activity
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;

// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;

//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);      

}

API LEVEL>=11 のアプリを対象とする場合は、Notification.Builder を使用します。ここを参照してください: http://developer.android.com/reference/android/app/Notification.Builder.html 上記のコードが更新を続けるもう 1 つのポイント通知マネージャーの通知メソッドは常に同じ ID、つまり 0 を取得するため、同じ通知オブジェクトが更新されるため、同じ通知オブジェクトが更新されます。

于 2013-05-19T19:10:04.350 に答える