使用意图打开音频文件...(“ audio / wav”)

时间:2018-12-18 03:29:11

标签: android

我一直在尝试使用intent和FileProvider打开文件,但是当我尝试打开文件时应用程序崩溃。这是我在做什么...请帮帮我。

@Override
public void onClick(View view){
final Uri uri = FileProvider.getUriForFile(mCtx, String.valueOf(R.string.file_provider_authority), new File(mydata.get(getAdapterPosition()).getPath()));
    mCtx.grantUriPermission(mCtx.getPackageName() , uri , Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        final Intent intent = new Intent(Intent.ACTION_VIEW)
                .setDataAndType(uri, "audio/wav")
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Intent choose = Intent.createChooser(intent, "See..");
        mCtx.startActivity(choose);
        Toast.makeText(mCtx, "Clicked " + mydata.get(getAdapterPosition()).getPath(), Toast.LENGTH_SHORT).show();
    }

    catch (
            ActivityNotFoundException e
            ){

    }


   }

}

I got following exception --------- beginning of crash

2018-12-18 09:13:40.173 25265-25265 / my.uapp.com E / AndroidRuntime:FATAL EXCEPTION:main     流程:my.uapp.com,PID:25265     java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“ android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager,java.lang.String)”         在android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:605)         在android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579)         在android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)         在my.uapp.com.MyAdapter $ ViewHolder.onClick(MyAdapter.java:73)         在android.view.View.performClick(View.java:6320)         在android.view.View $ PerformClick.run(View.java:25087)         在android.os.Handler.handleCallback(Handler.java:869)         在android.os.Handler.dispatchMessage(Handler.java:101)         在android.os.Looper.loop(Looper.java:206)         在android.app.ActivityThread.main(ActivityThread.java:6749)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)

0 个答案:

没有答案