Android 通知Notification的两种实现方法
发布日期:2021-06-30 22:35:20 浏览次数:2 分类:技术文章

本文共 1379 字,大约阅读时间需要 4 分钟。

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); }}

转载地址:https://lovoo.blog.csdn.net/article/details/51255265 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android 内容提供者ContentProvider
下一篇:Cocos2D 初步了解三:CCAction

发表评论

最新留言

不错!
[***.144.177.141]2024年04月22日 09时43分09秒