通知列非常之簡單
可以和Service(http://cookiesp.pixnet.net/blog/post/93705950)結合喔!!
範例奉上(因為裡面用到預設的震動所以要加上震動權限喔
<
uses-permission
android:name
=
"android.permission.VIBRATE"
/>
)
//取得Notification服務 NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); //設定當按下這個通知之後要執行的activity Intent notifyIntent = new Intent(JudgeHotspotService.this,MapViewActivity.class); //還可設定Bundle Bundle bundle =new Bundle(); bundle.putInt("searchMode",2); bundle.putString("keyword",null); notifyIntent.putExtras(bundle); notifyIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent appIntent=PendingIntent.getActivity(JudgeHotspotService.this,0,notifyIntent,0); Notification notification = new Notification(); //設定出現在狀態列的圖示 notification.icon=R.drawable.set_statistics_icon; //顯示在狀態列的文字 notification.tickerText="時間:"+ new Date().toString(); //會有通知預設的鈴聲、振動、light notification.defaults=Notification.DEFAULT_ALL; //設定通知的標題、內容 notification.setLatestEventInfo(JudgeHotspotService.this,"時間顯示器","顯示現在時間",appIntent); //送出Notification notificationManager.notify(0,notification);
文章標籤
全站熱搜