2016-09-15 4 views
1

Ich habe eine Xamarin Android-Anwendung zu behandeln, und ich will ich den Fehler habe eine pdf file.After der letzten Zeile des Codes öffnenKeine Aktivität Intent Android

Android.Content.ActivityNotFoundException: Keine Aktivität gefunden zu handhaben Intent {act = android.intent.action.VIEW dat =/storage/emulierten/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); 

Mein Manifest ist:

<?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> 

Wie kann ich es beheben?

Antwort

0

Nach einigen Änderungen funktioniert es.

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); 
Verwandte Themen