簡體   English   中英

找不到活動來處理Intent Android

[英]No Activity found to handle Intent Android

我有一個xamarin android應用程序,我想打開一個pdf文件。在代碼的最后一行后我得到了錯誤

Android.Content.ActivityNotFoundException:找不到處理Intent的Activity {act = android.intent.action.VIEW dat = / storage / emulated / 0 / docen __。pdf typ = application / pdf flg = 0x80000}

 Stream _IS = this.Assets.Open("doc" + GlobalsAndroid.FixedDocumentationLanguageCode + ".pdf");
                                        byte[] _BA = null;
                                        using (BinaryReader _BR = new BinaryReader(_IS))
                                        {
                                            using (MemoryStream ms = new MemoryStream())
                                            {
                                                byte[] _buffer = new byte[4096];
                                                int count;
                                                while ((count = _BR.Read(_buffer, 0, _buffer.Length)) != 0)
                                                    ms.Write(_buffer, 0, count);
                                                _BA = ms.ToArray();
                                            }
                                        }

                                        string _EP = System.IO.Path.Combine(global::Android.OS.Environment.ExternalStorageDirectory.Path, "doc" + GlobalsAndroid.FixedDocumentationLanguageCode + "__.pdf");
                                        System.IO.File.WriteAllBytes(_EP, _BA);

                                        Intent _I = new Intent(Intent.ActionView);
                                        _I.SetDataAndType(global::Android.Net.Uri.Parse(_EP), "application/pdf");
                                        _I.SetFlags(ActivityFlags.GrantReadUriPermission);
                                        _I.SetFlags(ActivityFlags.NewTask);
                                        _I.SetFlags(ActivityFlags.ClearWhenTaskReset);

                                        this.StartActivity(_I);

我的清單是:

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"  android:versionCode="6" android:versionName="1.3" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="20" />
    <application   android:debuggable="true"></application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.intent.action.VIEW" />

</manifest>

我該如何解決?

經過一些改變后,它有效。

 var path = System.IO.Path.Combine(global::Android.OS.Environment.ExternalStorageDirectory.Path, "doc" + GlobalsAndroid.FixedDocumentationLanguageCode + ".pdf");

                                        var intent = new Intent(Intent.ActionView);
                                        global::Android.Net.Uri pdfFile = global::Android.Net.Uri.FromFile(new Java.IO.File(path));
                                        intent.SetDataAndType(pdfFile, "application/pdf");
                                        intent.SetFlags(ActivityFlags.GrantReadUriPermission);
                                        intent.SetFlags(ActivityFlags.NewTask);
                                        intent.SetFlags(ActivityFlags.ClearWhenTaskReset);

                                        this.StartActivity(intent);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM