更改android版本后无法打开pdf或任何其他附件

时间:2018-10-29 00:59:45

标签: xamarin.forms xamarin.android android-fileprovider

下面是我的代码:

AndroidManifest

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.rsoftware.androidx.RMobile.Droid.utils.GenericFileProvider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
    </provider>

provider_paths.xml:

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

在我的打开文件方法中:

MimeTypeMap mimeTypeMap = MimeTypeMap.Singleton;
        Intent newIntent = new Intent(Intent.ActionView);
        string mimeType = mimeTypeMap.GetMimeTypeFromExtension(System.IO.Path.GetExtension(fileName).ToLower());
 newIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
        newIntent.SetDataAndType(FileProvider.GetUriForFile(Android.App.Application.Context, "com.tcrsoftware.androidx.TCRMobile.Droid.utils.GenericFileProvider", GetFile(folderPath, fileName)), mimeType);
        newIntent.SetFlags(ActivityFlags.NewTask);
        try
        {
           // Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(newIntent);
            Forms.Context.StartActivity(newIntent);
        }
        catch (Exception ex)
        {
            Toast.MakeText(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, "Not a valid format.", ToastLength.Long).Show();
        }

我得到的错误是:

  

ActivityNotFoundException:无法找到要执行的活动

我做错了什么?

0 个答案:

没有答案