mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-01-14 08:57:53 -05:00
Several things here: - Add support for the W3C notifications spec, and rewrite the old API to call the new W3C one behind the scenes. - Notifications are now automatically cleared when the user clicks. - Clicking the notification brings the user to the same instance of the app as was already running (and not a new copy as by default in Android notifications). - Support for multiple notifications from one app using tags, as specified in the W3C spec and supported by Android. - Support for canceling a single notification by tag, as per W3C spec. Callbacks to Javascript when the user clicks are specified but not yet supported; I will add that assuming I can get Android to call some code in the plugin when the notification is clicked.
28 lines
1.1 KiB
Java
28 lines
1.1 KiB
Java
// This class is used on all Androids below Honeycomb
|
|
package com.phonegap.plugins.statusBarNotification;
|
|
|
|
|
|
import com.google.cordova.statusbarnotificationtest.R;
|
|
import android.app.Notification;
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageManager;
|
|
|
|
public class StatusNotificationIntent {
|
|
public static Notification buildNotification( Context context, CharSequence contentTitle, CharSequence contentText ) {
|
|
int icon = R.drawable.notification;
|
|
long when = System.currentTimeMillis();
|
|
Notification noti = new Notification(icon, contentTitle, when);
|
|
noti.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
|
PackageManager pm = context.getPackageManager();
|
|
Intent notificationIntent = pm.getLaunchIntentForPackage(context.getPackageName());
|
|
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
|
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
|
|
noti.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
|
|
return noti;
|
|
}
|
|
}
|