用于实现类似音乐播放器通知栏功能(播放、暂停、上下一曲)

1、自定义通知栏

  NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "default");                builder.setSmallIcon(android.R.drawable.sym_def_app_icon);                RemoteViews rv = new RemoteViews(getPackageName(), R.layout.message);                rv.setTextViewText(R.id.tv, "泡沫");//修改自定义View中的歌名                //修改自定义View中的图片(两种方法)                rv.setImageViewResource(R.id.iv, R.mipmap.ic_launcher);                rv.setImageViewBitmap(R.id.iv, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));                builder.setContent(rv);//设置button监听为发送广播------------------                Intent previous = new Intent("com.example.Bean.MyBroadcastReceiver");                PendingIntent pi_previous = PendingIntent.getBroadcast(Tongzhi.this, 0,                        previous, PendingIntent.FLAG_UPDATE_CURRENT);                rv.setOnClickPendingIntent(R.id.btn1, pi_previous);//----------------------------------------                Notification notification = builder.build();                NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);                notificationManager.notify(0x1, notification);
<?xml version="1.0" encoding="utf-8"?>            

2、自定义广播

public class MyBroadcastReceiver extends BroadcastReceiver {    @Override    public void onReceive(Context context, Intent intent) {        Toast.makeText(context, "okgb", Toast.LENGTH_SHORT).show();    }}
................                                        

发送这条广播测试广播是否注册成功

  Intent integer = new Intent("com.example.Bean.MyBroadcastReceiver");                sendBroadcast(integer);

 

更多相关文章

  1. Android之MVC——Model通知View去更新(实用)
  2. Android通知Header详解
  3. 26. android Notification 状态栏通知
  4. Android中添加常驻通知栏
  5. Android Notification 通知封装成工具类
  6. Android 自定义通知Notification 适配不同背景颜色
  7. Android通知的使用及设置
  8. Android之RemoteViews篇上————通知栏和桌面小控件
  9. Android通知MediaScanner扫描指定的文件

随机推荐

  1. ( 转)关于Android的nodpi,xhdpi,hdpi,mdp
  2. android notification
  3. [React Native Android(安卓)安利系列]原
  4. Android导入工程提示 Invalid project de
  5. Android(安卓)项目结构图
  6. [Android]生成heap dump文件(.hprof)
  7. Android的布局和Intent笔记和常用实例
  8. Android好博客文章汇总
  9. Android(安卓)中 "@+id"的作用是什么?以及
  10. Android解决AVD Hardware Buttons 和DPAD