简体   繁体   English

xamarin表格android需要使用我的应用打开pdf(未显示)

[英]xamarin form android need to open pdf with my app (no show)

I'm using this guide to open a pdf inside my app. 我正在使用本指南在应用内打开pdf文件。 All I want is to see my app in the list of apps that can be aple to open a file (pdf) when I press 'share'. 我只想在应用程序列表中看到我的应用程序,当我按“共享”时可以打开文件(pdf)。 So, until now my iOS project works so it's an Android settings problem. 因此,到目前为止,我的iOS项目可以正常运行,因此这是Android设置问题。

MainActivity: 主要活动:

[Activity(Label = "Test", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true)]
[IntentFilter(
    new[] { Intent.ActionView },
   Categories = new[]
  {
      Intent.CategoryDefault,
      Intent.CategoryBrowsable,
  },
  DataScheme = "file",
  DataMimeType = "*/*",
  DataPathPattern = ".*\\.pdf"
)]

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        string action = Intent.Action;
        string type = Intent.Type;

        global::Xamarin.Forms.Forms.Init(this, bundle);

        var application = new App();

        if (Intent.ActionView.Equals(action) && !String.IsNullOrEmpty(type))
        {
            Android.Net.Uri fileUri = Intent.Data;

            if (fileUri != null)
            {
                var fileContent = File.ReadAllBytes(fileUri.Path);
                var name = fileUri.LastPathSegment;
                application.SetExternDocument(new IncomingFile()
                {
                    Name = name,
                    Content = fileContent
                });
            }
        }

        LoadApplication(application);
    }
}

and Manifest.xml 和Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
android:versionCode="1" 
android:versionName="1.0" 
package="com.bbinternational.inviofatture.BBInvioFatture">

<uses-sdk android:minSdkVersion="21" />

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

As you can see I didn't write anything into the manifest because I used Attributes in the main Activity. 如您所见,我没有在清单中写入任何内容,因为我在主Activity中使用了Attributes。 I tried to use manifest but i can't retrieve the MainActivity android:name property using Xamarin (at runtime it allocates some random values or at least is what I know). 我尝试使用清单,但无法使用Xamarin检索MainActivity android:name属性(在运行时它会分配一些随机值,或者至少是我所知道的)。

Thanks for the help. 谢谢您的帮助。

Cheers guys. 干杯们。

So, after hours of googling this dude saved me. 因此,经过数小时的谷歌搜索,这个家伙救了我。

https://codemilltech.com/sending-files-to-a-xamarin-forms-app-part-2-android/ https://codemilltech.com/sending-files-to-a-xamarin-forms-app-part-2-android/

As i supposed the IntentFilterAttributes were wrong. 正如我认为的IntentFilterAttributes是错误的。 This is the right version 这是正确的版本

[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = @"application/pdf")]

Hope to help somebody. 希望能帮助到别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM