Android 通知Notification的两种实现方法
16lz
2021-01-23
public class NotificationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); } public void notifyNew(View view){ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification.Builder builder = new Builder(this); builder.setContentTitle("通知标题"); builder.setContentText("帖子内容"); builder.setSmallIcon(R.drawable.ic_launcher); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); Notification notification = builder.build(); nm.notify(0, notification); } @SuppressWarnings("deprecation") public void notifyOld(View view){ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, "通知来了", System.currentTimeMillis()); Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:123456")); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(this, "标题", "内容", contentIntent); nm.notify(0, notification); }}
更多相关文章
- Android点击通知栏,不启动新的activity
- android 通知 Notification
- Android自定义Toast 解决关闭通知 Toast无法弹出
- Android APP 版本更新通知代码
- Android 记录gitignore文件内容
- Android的系统通知栏小例子
- Android UI控件详解-Notification(通知)
- 【notification】Android 中创建状态栏通知
- Android - 自定义标题栏(TitleBar)