android PGo音乐小部件报错

复现问题,就是在没有进入音乐播发器之前就去添加音乐小部件play all,然后点击播放,就会报错。
报错信息:

01-08 13:48:56.116380  6294  6294 E AndroidRuntime: FATAL EXCEPTION: main
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: Process: com.android.music, PID: 6294
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=music_notification_channel pri=0 contentView=com.android.music/0x7f04000f vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 vis=PRIVATE)       
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1765)
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:193)
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6702)
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
01-08 13:48:56.116380  6294  6294 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

通过log可以看出是channel问题,查看源码发现,它只是定义了channel=music_notification_channel字符串,其他的没有做,没有发现定义NotificationChannel,所以自己定义一个,发现问题解决。

 Notification status = new Notification.Builder
          (context, MusicBrowserActivity.MUSIC_NOTIFICATION_CHANNEL).build();

修改文件:
alps/vendor/mediatek/proprietary/packages/apps/Music/src/com/android/music/MediaPlaybackService.java

	import com.mediatek.bluetooth.avrcp.ServiceAvrcpStub;
	/// BT AVRCP End @}
	//Redmine161113 modified for Music player error  2019/1/16 begin
	import android.app.NotificationManager;
	import android.app.NotificationChannel;

	//Redmine161113 modified for Music player error  2019/1/16 end
    private boolean mTaskRemoved = false;
    private boolean misAVRCPseeking = false;
    private boolean mPlayBeforeseek = false;
    //Redmine161113 modified for Music player error  2019/1/16 begin
    public static final String MUSIC_NOTIFICATION_CHANNEL = "music_notification_channel";
    //Redmine161113 modified for Music player error  2019/1/16 end

    private void updateNotification(Context context, Bitmap bitmap) {
      	.......
         intent = new Intent("com.android.music.PLAYBACK_VIEWER");
        /// M: Create NotificationChannel
        //Notification status = new Notification();
        //Redmine161113 modified for Music player error  2019/1/16 begin
        /// M: Create NotificationChannel
        NotificationManager mgr = (NotificationManager)this.
          getSystemService(Context.NOTIFICATION_SERVICE);
        mgr.createNotificationChannel(new NotificationChannel(
          MUSIC_NOTIFICATION_CHANNEL, "MUSIC", NotificationManager.IMPORTANCE_LOW));
        Notification status = new Notification.Builder
          (context, MUSIC_NOTIFICATION_CHANNEL).build();
        //Redmine161113 modified for Music player error  2019/1/16 end
        status.contentView = views;
        status.flags |= Notification.FLAG_ONGOING_EVENT;
        status.icon = R.drawable.stat_notify_musicplayer;
        status.contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
        mMediaplayerHandler.removeMessages(DEALY_STOPFORGROUND);
        startForeground(PLAYBACKSERVICE_STATUS, status);


}

问题解决,如有问题,可以留言,大家一起学习,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值