|
package com.cloud.test;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
public class NotificationActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(android.R.drawable.stat_notify_chat,null,System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_SOUND;
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent openIntent = new Intent(this,OtherActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openIntent, 0);
notification.setLatestEventInfo(this, "标题", "内容", contentIntent);
mNotificationManager.notify(0,notification);
}
}
源码在二楼 |
|