I Have Been Trying To Open A File using intent and FileProvider but app crashes when i try to open the file..Here's what i am doing...please help me out..
@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 Process: my.uapp.com, PID: 25265 java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:605) at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417) at my.uapp.com.MyAdapter$ViewHolder.onClick(MyAdapter.java:73) at android.view.View.performClick(View.java:6320) at android.view.View$PerformClick.run(View.java:25087) at android.os.Handler.handleCallback(Handler.java:869) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:206) at android.app.ActivityThread.main(ActivityThread.java:6749) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)