简单显示顶部通知的Demo
16lz
2021-01-26
- package com.saiermeng.notifiy;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View view){ @SuppressWarnings("deprecation") Notification notification = new Notification(R.drawable.ic_launcher, "酷狗音乐正在播放", 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) getSystemService(NOTIFICATION_SERVICE); nm.notify(0, notification); }}
更多相关文章
- 使用异步任务下载--疯狂android讲义实例
- 安卓 简易版音乐播放器——初稿
- 播放raw中的音乐范例
- Android(安卓)应用界面开发笔记 Service
- android 静默安装并自启
- Adb连接超时错误
- android启动蓝牙的过程 (高通方案)
- Android(安卓)Service播放音乐
- 用命令行使用7z压缩