jcb*_*wni 4 xamarin.android xamarin.forms
我正在尝试使用以下代码在我的应用程序中使用默认的Android pdf查看器查看托管的PDF文件
var intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.Parse("http://sample/url.pdf"), "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
Android.Content.Context.StartActivity(intent);
Run Code Online (Sandbox Code Playgroud)
我在Native项目中使用过这段代码,所以我知道它在Android活动中有效.对于Xamarin Forms,我是否有办法从内容页面启动Android活动,反之亦然?
Yor*_*hen 10
您可以使用DependencyService来实现此功能:
INativePages
在PCL
:
public interface INativePages
{
void StartActivityInAndroid();
}
Run Code Online (Sandbox Code Playgroud)
在Xamarin.Android
以下位置实现接口:
[assembly: Xamarin.Forms.Dependency(typeof(NativePages))]
namespace PivotView.Droid
{
public class NativePages : INativePages
{
public NativePages()
{
}
public void StartAc()
{
var intent = new Intent(Forms.Context, typeof(YourActivity));
Forms.Context.StartActivity(intent);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Activity
在PCL中启动Android :
private void Button_Clicked(object sender, EventArgs e)
{
Xamarin.Forms.DependencyService.Register<INativePages>();
DependencyService.Get<INativePages>().StartAc();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6218 次 |
最近记录: |