Start an Android activity in Xamarin Forms?

后端 未结 3 1388
情书的邮戳
情书的邮戳 2020-12-18 03:51

I am trying to view a hosted PDF file with the default Android pdf viewer in my App with the following code

            var intent = new Intent(Intent.Action         


        
3条回答
  •  盖世英雄少女心
    2020-12-18 04:18

    You can use DependencyService to implement this function:

    INativePages in PCL:

     public interface INativePages
    {
        void StartActivityInAndroid();
    }
    

    Implement the interface in 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);
            }
    
        }
    }
    

    Start an Android Activity in PCL :

        private void Button_Clicked(object sender, EventArgs e)
        {
            Xamarin.Forms.DependencyService.Register();
            DependencyService.Get().StartAc();
        }
    

提交回复
热议问题