简体   繁体   中英

How to open the ppt file from phone internal storage using file provider

I am trying to open a pptx file which is already stored in app data directory but I am facing an error to open the ppt file.

I have used the basic method to get the file path and then the Uri, from there passing the file Uri to the intent to open the pptx file.

Since I am having the files in ma app-data (Phone -Internal Storage), I guess i need not use the File Provider. But still i used the file provider still i am facing a issue in opening the file

I am using Recycle view which has card view each has a button to open a specific file , hence I am using an Adapter,viewholder....and the below onclick method is available under the adapter class-->onBindViewHolder function.

this is onClick function used to open the specific file stored

@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {

    holder.fOpen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            File file = new File(holder.mname.getContext().getFilesDir(), "Download");
            File pptFile = new File(file,"Introduction.pptx");
            Uri uri = FileProvider.getUriForFile(holder.mname.getContext(), "com.example.r_source.fileprovider", pptFile);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "application/pptx");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            mainActivity.startActivity(intent);
        }
    });
}

the below is the file path xml for File provider

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="materials" path="Download/"/>
</paths>

the below is the manifest file

<provider
      android:name="androidx.core.content.FileProvider"
      android:authorities="com.example.r_source.fileprovider"
      android:exported="false"
      android:grantUriPermissions="true">
      <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"/>
</provider>

The error message I am getting is :

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.example.r_source.fileprovider/materials/Introduction.pptx typ=application/pptx flg=0x1 }

authorities in click listener is "com.example.r_source.provider"

authorities in provider is "com.example.r_source.fileprovider"

both should be same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM