无法解析参考Plugin.Permissions

时间:2019-01-20 08:24:54

标签: xamarin xamarin.forms android-permissions

在xamarin.forms中使用Plugin.Permissions时出现此错误:

无法解析引用:MyProject引用的Plugin.Permissions。请为Plugin.Permissions添加NuGet程序包或程序集引用,或删除对MyProject的引用。 MyProject.Android

但是我在所有项目(Forms,android,ios)中添加了plugin.permission

1 个答案:

答案 0 :(得分:0)

我在MainActivity中添加了此方法:

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

,并在以下行的base.OnCreate(savedInstanceState)之后添加:

 protected override void OnCreate(Bundle savedInstanceState)
    {
        var intent = new Intent(this, typeof(MainService));
        StartService(intent);
        layout = FindViewById<LinearLayout>(Resource.Layout.AlertActivity);
        Log.Debug("StartService", "DemoService started");

        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;


        base.OnCreate(savedInstanceState);

        //this line added
        Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this,
savedInstanceState);

        Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }

现在,一切正常! 谢谢您的帮助!