2016-09-15 72 views
1

我有一個xamarin Android應用程序,我想打開PDF file.After我得到了錯誤無活動處理意向的Android

Android.Content.ActivityNotFoundException代碼的最後一行:無活動發現處理 意圖{行爲= android.intent.action.VIEW DAT = /存儲/模擬/ 0/docen __ PDF典型值=應用/ 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> 

我怎樣才能解決這個問題?

回答

0

經過一些改變後,它的工作原理。

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); 
相關問題