首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android notification 的事例

2012-09-14 
android notification 的例子public class SimpleNotification extends Activity {private NotificationMa

android notification 的例子

public class SimpleNotification extends Activity {        private NotificationManager mNotificationManager;    private int SIMPLE_NOTFICATION_ID;         /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                 mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);       final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis());                Button start = (Button)findViewById(R.id.notifyButton);         Button cancel = (Button)findViewById(R.id.cancelButton);                 start.setOnClickListener(new OnClickListener() {                        public void onClick(View v) {                                             Context context = getApplicationContext();               CharSequence contentTitle = "Notification Details...";               CharSequence contentText = "Browse Android Official Site by clicking me";               Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));               PendingIntent intent =                  PendingIntent.getActivity(SimpleNotification.this, 0,                  notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);                              notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);               mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);            }         });                 cancel.setOnClickListener(new OnClickListener() {                        public void onClick(View v) {                              mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);            }         });     } } //hello word级别的例子。

?

热点排行