Android Notification使用詳解
Notification
核心代碼(鏈式調用):適用于Android 4.0以上(不兼容低版本)
Notification noti = new Notification.Builder(this).setContentTitle("標題名稱").setContentText("標題里的內容").setSmallIcon(R.drawable.new_mail).setLargeIcon(BitmapFactory.decordResource(getResources(), R.drawable.ic_launcher)).build();NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);nm.notify(0, noti);兼容版本
Notification notification = new Notification(R.drawable.ic_launcher, "xxxxxx", System.currentTimeMillis());//點擊事件真正想執行的動作Intent intent = new Intent();intent.setAction(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:110"));PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);notification.setLatestEventInfo(this, "標題", "內容", contentIntent);NotificationManager nm = (NotificationManager) getSystemManager(NOTIFICATION_SERVICE);nm.notify(0, notification);感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答