App does not contain a definition for UiParent - xamarin

I've got an Azure AD B2C set up, and have configured external identity providers. I'm trying to follow this tutorial and have gotten stuck right here MainActivity.cs (Android project in my Xamarin solution):
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
LoadApplication(new App());
App.UiParent = new UIParent(Xamarin.Forms.Forms.Context as Activity);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
}
}
I'm getting red squiggled on App.UiParent, saying "UiParent" is not on App.
I've added the 1.1 release of Microsoft Authentication Library / Microsoft.Identity.Client, and even futzed around with the dev releases and got the same result.
As a bonus, I'm also getting Forms.Context is obsolete.

You are missing the public variable in your Application subclass:
public class App : Application
{
public static IAuthenticate AuthenticationProvider { get; private set; }
public static UIParent UiParent = null;
public App()
{
~~~~
Re: App.cs#L12

Related

EventBus Xamaring. Custom method of activity not found using reflection

I've added EventBus as a binding library in my Xamarin Android project.
I can compile without errors but when I'm trying to register, I get the following error:
Here is the code for the activity
[Activity(Icon = "#mipmap/ic_launcher"]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Forms.Init(this, savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
CrossCurrentActivity.Current.Init(this, savedInstanceState);
LoadApplication(new App());
EventBus.Default.Register(this);
}
protected override void OnDestroy()
{
base.OnDestroy();
EventBus.Default.Unregister(this);
}
[Subscribe]
public void onEvent(DeviceConnectionEvent my_event)
{
throw new NotImplementedException();
}
protected override void OnActivityResult(int requestCode, Result resultVal, Intent data)
{
if (requestCode == 1)
{
wifiManagerInstance.onNetworkDataReceived();
}
base.OnActivityResult(requestCode, resultVal, data);
}
}
It looks like my method is not being detected when eventbus uses reflection
methods = findState.clazz.getDeclaredMethods();
Other methods of the activity are detected as can be seen in the following picture.
Is there anything I can do?
Thanks in advance.
Since I don't have a binding library for EventBus, I couldn't test it, but
you could check to see if your package is imported correctly when you use [Subscribe] attribute.
Here you should use org.greenrobot.eventbus.Subscribe; rather than com.google.common.eventbus.Subscribe;
I think you could also use MessagingCenter to do what you want.

CS1729 'Application' does not contain a constructor that takes 1 arguments

I created a OAuth2Service class in my Xamarin Forms Android Project which inherits a IOAuth2Service interface.I need this to be available in my class library so i can perform google authentication in my Xamarin forms Application. But I keep getting the error message mentioned above despite the fact that i setup the application class to accept an argument of type IOAuth2Service. Here's my "App.Xaml.cs" which contains the Application class. What should i do?
public partial class Application : Xamarin.Forms.Application
{
public Application(IOAuth2Service oAuth2Service)
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage(oAuth2Service));
}
protected override void OnStart()
{
AppCenter.Start("android=ced94d85-cb85-4ec2-8411-96864a7ec23e;" +
"uwp={Your UWP App secret here};" +
"ios={Your iOS App secret here}",
typeof(Analytics), typeof(Crashes));
}
}
The IOAuth2Service is actually a Interface and not a class. I don't think you can create an instance object from an interface. And i'm correct cause after making the changes you suggested. I get the error:"Cannot create an instance of the abstract class or interface 'IOAuth2Service'"
Why not the instantiate the OAuth2Service class in the Constructor of Applicationlike following code? Put OAuth2Service class in PCL.
public Application()
{
InitializeComponent();
OAuth2Service oAuth2Service=new OAuth2Service ();
MainPage = new NavigationPage(new LoginPage(oAuth2Service));
}
If IOAuth2Service in the xxxxx.Droid or xxxxx.IOS folder. You need transfer IOAuth2Service to the PCL. In Android, You can instantiate it in OnCreate method of MainActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
OAuth2Service oAuth2Service = new OAuth2Service ();
LoadApplication(new App(oAuth2Service));
}
In IOS, You can instantiate it in FinishedLaunching method of AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
OAuth2Service oAuth2Service = new OAuth2Service ();
LoadApplication(new App(oAuth2Service));
return base.FinishedLaunching(app, options);
}
Here is Application class.
public partial class Application : Xamarin.Forms.Application
{
public Application(OAuth2Service oAuth2Service)
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage(oAuth2Service));
}
}

Xamarin.Forms maps on MVVMCross

I want to use maps with MVVMCross. In iOS everything is OK, but in Android I don't have Bundle in the OnCreate() method, so I don't know where I should initialize Xamarin.FormsMaps.Init(this, bundle);
My MainApplication.cs looks like this:
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
{
public MainApplication(IntPtr handle, JniHandleOwnership transer)
: base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
RegisterActivityLifecycleCallbacks(this);
//A great place to initialize Xamarin.Insights and Dependency Services!
}
public override void OnTerminate()
{
base.OnTerminate();
UnregisterActivityLifecycleCallbacks(this);
}
public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
{
}
public void OnActivityDestroyed(Activity activity)
{
}
public void OnActivityPaused(Activity activity)
{
}
public void OnActivityResumed(Activity activity)
{
}
public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
{
}
public void OnActivityStarted(Activity activity)
{
}
public void OnActivityStopped(Activity activity)
{
}
}
I don't know if I have to create another view or something like that.
Any thoughs?
I think, You can override the onCreate Method that will accept the instance details.
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
RegisterActivityLifecycleCallbacks(this);
global::Xamarin.FormsMaps.Init (this, bundle);
}

how to disable camera using XposedHook?

I want to disable my camera using xposed. So I am not able to understand which native method should I hook so that my phone camera gets disabled.
I tried this:-
public class main1 implements IXposedHookLoadPackage {
#Override
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable{
if(!lpparam.packageName.equals("android.hardware.camera2"))
return;
findAndHookMethod("android.hardware.camera2.CameraManager", lpparam.classLoader, "openCamera", String.class, CameraDevice.StateCallback.class, Handler.class, new XC_MethodReplacement() {
#Override
protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
XposedBridge.log("CameraBlocked");
return null;
}
});
XposedBridge.log("Loaded app: " + lpparam.packageName);
}
}
But it doesn't work. Please help me out with this.

Error inflating Mvx.MvxLinearLayout after updating to MvvmCross 4.2.2 from 3.5.1

I just updated my project from MvvmCross 3.5.1 stable to 4.2.2. After fixing some other runtime exceptions that popped up after the update, I'm stuck with this one.
I am inflating a layout in an MvxFragment:
_rootView = this.BindingInflate(Resource.Layout.my_layout, null);
This throws a Java.Lang.ClassNotFoundException for Mvx.MvxLinearLayout. With the messages:
Binary XML file line #1: Error inflating class Mvx.MvxLinearLayout
Didn't find class \"Mvx.MvxLinearLayout\" on path: DexPathList[[zip file \"/data/app/com.myapp…
I have already installed the MvvmCross.Binding nuget package.
I the following base activity (which worked fine on 3.5.1):
MvxActionBarActivity
/// <summary>
/// Mvx support for the native ActionBarActivity
/// </summary>
public abstract class MvxActionBarActivity
: MvxActionBarEventSourceActivity
, IMvxAndroidView
{
protected MvxActionBarActivity()
{
BindingContext = new MvxAndroidBindingContext(this, this);
this.AddEventListeners();
}
public object DataContext
{
get { return BindingContext.DataContext; }
set { BindingContext.DataContext = value; }
}
public IMvxViewModel ViewModel
{
get { return DataContext as IMvxViewModel; }
set
{
DataContext = value;
OnViewModelSet();
}
}
public void MvxInternalStartActivityForResult(Intent intent, int requestCode)
{
base.StartActivityForResult(intent, requestCode);
}
public IMvxBindingContext BindingContext { get; set; }
public override void SetContentView(int layoutResId)
{
var view = this.BindingInflate(layoutResId, null);
SetContentView(view);
}
protected virtual void OnViewModelSet()
{
}
MvxActionBarEventSourceActivity
public class MvxActionBarEventSourceActivity : AppCompatActivity
, IMvxEventSourceActivity
{
protected override void OnCreate(Bundle bundle)
{
CreateWillBeCalled.Raise(this, bundle);
base.OnCreate(bundle);
CreateCalled.Raise(this, bundle);
}
protected override void OnDestroy()
{
DestroyCalled.Raise(this);
base.OnDestroy();
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
NewIntentCalled.Raise(this, intent);
}
protected override void OnResume()
{
base.OnResume();
ResumeCalled.Raise(this);
}
protected override void OnPause()
{
PauseCalled.Raise(this);
base.OnPause();
}
protected override void OnStart()
{
base.OnStart();
StartCalled.Raise(this);
}
protected override void OnRestart()
{
base.OnRestart();
RestartCalled.Raise(this);
}
protected override void OnStop()
{
StopCalled.Raise(this);
base.OnStop();
}
public override void StartActivityForResult(Intent intent, int requestCode)
{
StartActivityForResultCalled.Raise(this, new MvxStartActivityForResultParameters(intent, requestCode));
base.StartActivityForResult(intent, requestCode);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
ActivityResultCalled.Raise(this, new MvxActivityResultParameters(requestCode, resultCode, data));
base.OnActivityResult(requestCode, resultCode, data);
}
protected override void OnSaveInstanceState(Bundle outState)
{
SaveInstanceStateCalled.Raise(this, outState);
base.OnSaveInstanceState(outState);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
DisposeCalled.Raise(this);
}
base.Dispose(disposing);
}
public event EventHandler DisposeCalled;
public event EventHandler<MvxValueEventArgs<Bundle>> CreateWillBeCalled;
public event EventHandler<MvxValueEventArgs<Bundle>> CreateCalled;
public event EventHandler DestroyCalled;
public event EventHandler<MvxValueEventArgs<Intent>> NewIntentCalled;
public event EventHandler ResumeCalled;
public event EventHandler PauseCalled;
public event EventHandler StartCalled;
public event EventHandler RestartCalled;
public event EventHandler StopCalled;
public event EventHandler<MvxValueEventArgs<Bundle>> SaveInstanceStateCalled;
public event EventHandler<MvxValueEventArgs<MvxStartActivityForResultParameters>> StartActivityForResultCalled;
public event EventHandler<MvxValueEventArgs<MvxActivityResultParameters>> ActivityResultCalled;
}
Switching my base activity to MvxAppCompatActivity fixed the issue.

Resources