我试图在我的 android 应用程序中显示一个小通知,但我看不到任何东西。MainActivity
类有一个static field
命名activity
,它等于this
。message.data
只是从一个物体上拉出来的。这就是我所说的:
sendNotification(MainActivity.activity.getApplicationContext(),
null,
message.data,
message.data,
1, true, true, true, 0);
这是肉:
public static void sendNotification(Context caller, Class<?> activityToLaunch, String title, String msg, int numberOfEvents,boolean sound, boolean flashLed, boolean vibrate,int iconID) {
NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.ic_launcher,"Notification",System.currentTimeMillis());
notify.icon = iconID;
notify.tickerText = title;
notify.when = System.currentTimeMillis();
notify.number = numberOfEvents;
notify.flags |= Notification.FLAG_AUTO_CANCEL;
if (sound) notify.defaults |= Notification.DEFAULT_SOUND;
if (vibrate) notify.vibrate = new long[] {100, 200, 300};
if (flashLed) {
notify.flags |= Notification.FLAG_SHOW_LIGHTS;
notify.ledARGB = Color.CYAN;
notify.ledOnMS = 500;
notify.ledOffMS = 500;
}
int NOTIFICATION_ID = 1232;
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(caller, 0, notificationIntent, 0);
notify.setLatestEventInfo(caller, title, msg, contentIntent);
notifier.notify(NOTIFICATION_ID, notify);
}
我可以记录消息,所以我知道它正在被调用等等——但是,我是 android 开发的初学者,可能缺少一个关键部分。我在模拟器 android 2.2 上运行。这一切都在我链接到在后台运行的cordova的插件对象中,如果这很重要的话。