Android音乐播放器闪退的可能解决方法

Android音乐播放器闪退的可能解决方法,第1张

Android音乐播放器闪退的可能解决方法:
1、Manifests文件没有加上申请访问外存的权限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

主程序需要手动添加ActivityResultContracts提供的协议

这里我们使用requestPermission协议即可;
例如:

private ActivityResultLauncher launcher=registerForActivityResult(
            new ActivityResultContracts.RequestPermission(),
            new ActivityResultCallback<Boolean>() {
                @Override
                public void onActivityResult(Boolean result) {
                    if(result){
                        //如果申请成功,你要进行的 *** 作
                    }
                }
            }
    );
    /*在需要申请权限的地方调用下面这一行*/
    launcher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);

2、如果添加了权限音乐还是无法播放,可以尝试在manifest文件里的application里加上
android:requestLegacyExternalStorage="true"
3、recyclerView绑定adapter闪退:(主要检查适配器代码问题)
adapter 其中出现问题导致的:可能是函数没有写对;或者

//TextView text=(TextView)view.findViewById(R.id.text);
holder.text.setText(record.getid());

其中record.getid()为int类型,这时就需要把int类型改为String,如下:

holder.text.setText(""+record.getid());

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/989968.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存