自定义Notify发送通知,并进行更新,显示播放进度;自定义menu菜单,设置响应事件

        
  1. //更新通知
  2. privatevoidupdateNotify(){
  3. Runnabler=newRunnable(){
  4. @Override
  5. publicvoidrun(){
  6. if(isStop){
  7. return;
  8. }
  9. SongInfosongInfo=mSongInfos.get(mCurrentIndex);
  10. //设置专辑信息
  11. mNotify.contentView.setTextViewText(R.id.notify_album_name,mAlbumName);
  12. mNotify.contentView.setTextViewText(R.id.notify_song_name,songInfo.getSongName());
  13. //获取歌曲长度
  14. Stringduration=CommonUtil.convertTime(songInfo.getDuration());
  15. //获取当前播放时间
  16. StringcurrentTime=CommonUtil.convertTime(mMediaPlayer.getCurrentPosition()/1000);
  17. mNotify.contentView.setTextViewText(R.id.notify_current_time,currentTime);
  18. mNotify.contentView.setTextViewText(R.id.notify_duration,duration);
  19. mManager.notify(R.layout.play_notify,mNotify);
  20. mHandler.postDelayed(this,1000);
  21. }
  22. };
  23. mHandler.postDelayed(r,1000);
  24. }
  25. //通知
  26. publicvoidshowNotify(){
  27. mNotify=newNotification(R.drawable.no_cd,"正在播放",System.currentTimeMillis());
  28. //
  29. mNotify.flags|=Notification.FLAG_ONGOING_EVENT;
  30. //布局,getPackage()上下文方法
  31. mNotify.contentView=newRemoteViews(getPackageName(),R.layout.play_notify);
  32. //通知的图片不用实时刷新,否则在31秒处会出现异常
  33. mNotify.contentView.setImageViewBitmap(R.id.notify_album_icon,mAlbumBitmap);
  34. //
  35. Intentintent=newIntent(this,PlayActivity1.class);
  36. mNotify.contentIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
  37. mManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  38. //发送通知
  39. startForeground(R.layout.play_notify,mNotify);
  40. }

        
  1. //自定义菜单
  2. @Override
  3. publicbooleanonCreateOptionsMenu(Menumenu){
  4. Viewparent=findViewById(R.id.home);
  5. Log.d("mPopupWindow",parent.toString());
  6. if(mPopupWindow.isShowing()){
  7. mPopupWindow.dismiss();
  8. }else{
  9. mPopupWindow.showAtLocation(parent,Gravity.BOTTOM,0,0);
  10. }
  11. returnfalse;
  12. }
  13. @Override
  14. publicbooleanonKeyDown(intkeyCode,KeyEventevent){
  15. if(keyCode==KeyEvent.KEYCODE_BACK){
  16. if(mPopupWindow.isShowing()){
  17. mPopupWindow.dismiss();
  18. returntrue;
  19. }
  20. }
  21. returnsuper.onKeyDown(keyCode,event);
  22. }

本文出自 “android” 博客,谢绝转载!

更多相关文章

  1. Android学习07-----事件处理(2)单选按钮与下拉列表框级联菜单
  2. Android判断某一应用是否正在运行与判断某一Service是否正在运行
  3. 多条未接来电只显示来电数,同时拨号应用通知小圆点一直显示
  4. Android真机调试不打印日志解决
  5. android JiaoZiVideoPlayer问题整理解析
  6. React Native开发error calling appregistry.runapplication的解
  7. Android:Eclipse如何设置格式化Java代码
  8. Android(安卓)4.1正式发布 十大新特性
  9. android自定义Spinner下拉菜单(下拉列表框)样式

随机推荐

  1. Android(安卓)的跑马灯工具类
  2. 使用android的bitmap类实现图片的拼接
  3. Android(安卓)邮箱验证
  4. Android(安卓)BaseAdapter如何获得每一项
  5. android Animation图片渐变动画 Demo
  6. Android(安卓)service
  7. [Android]开启/关闭/监听 飞行模式
  8. 【Android】HTTP请求远端String和byte[]
  9. Android(安卓)Gesture 手势识别
  10. Official Note of Android(安卓)(importa