Xamarin [文件路径]通过intent.getdata()

时间:2019-01-11 19:44:54

标签: xamarin.forms xamarin.android

您好,我正在尝试制作一个html文件,然后使用Xamarin Froms在Android设备上的浏览器应用程序中将其打开。我可以创建html文件,但似乎无法在手机上打开它。我不断收到一个读取Xamarin [file path] exposed beyond app through intent.getdata()的异常。我在 AndroidManifest.xml 中阅读了有关<Provider>的内容,但似乎无法正确理解。这是我到目前为止的内容:

AndroidManifest.xml

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

MainActivity.cs

    // path to be a public path so external apps can access the file.                                
    var documentsPath =Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDocuments).AbsolutePath;
     Directory.CreateDirectory(documentsPath);
    //This creates the full file path to file
    string filePath = System.IO.Path.Combine(documentsPath, "invoice.html");

    //writes to file 
    File.WriteAllText(filePath, html);

    //opens file
    Android.Net.Uri uri = Android.Net.Uri.FromFile(new Java.IO.File(filePath));

    Intent intent = new Intent(Intent.ActionView, uri);
    intent.AddFlags(ActivityFlags.NewTask);
    intent.AddFlags(Intent.Flags);
    intent.SetClassName("com.android.chrome", "com.google.android.apps.chrome.Main");
    this.StartActivity(intent);//error

0 个答案:

没有答案