I have an error, when changing the style to dark from the system.
error in MainActivity.cs
base.OnCreate(savedInstanceState);
error text:
System.NotSupportedException: 'Unable to find the default constructor on type Xamarin.Forms.Platform.Android.ShellItemRenderer.Please provide the missing constructor.'
The function:
protected override void OnCreate(Bundle savedInstanceState)
{
CrossFingerprint.SetCurrentActivityResolver(() => this);
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState); **// in this line**
Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
Xamarin.FormsGoogleMaps.Init(this, savedInstanceState);
LoadApplication(new App());
}
Related
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.
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));
}
}
I am having a strange issue where by the below code returns null, but if I look in the folder, the image jpg has saved to file
public partial class TaskPage : ContentPage
{
private async void TaskPageTaskAnswer_Clicked(object sender, EventArgs e)
{
MediaFile mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { PhotoSize = PhotoSize.MaxWidthHeight, MaxWidthHeight = 1024 });
}
permissions checking is just this at the moment after various attempts
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
CrossCurrentActivity.Current.Init(this, savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Forms.Init(this, savedInstanceState);
FormsMaterial.Init(this, savedInstanceState);
Xamarin.FormsMaps.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
Also I am having trouble getting the Permissions plugin to return after it has requested permissions. They may be related issues?
I have followed all the steps but there seems to be contrasting info regarding the setup. Some places say to have a MainApplication.cs in the android project, yet the sample for this doesn't have that?
I get this error when use of Plugin.Permissions in xamarin.forms:
Can not resolve reference: Plugin.Permissions, referenced by MyProject. Please add a NuGet package or assembly reference for Plugin.Permissions, or remove the reference to MyProject. MyProject.Android
but I added plugin.permission in all Projects (Forms, android, ios)
I added this method in 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);
}
and added after base.OnCreate(savedInstanceState) below line:
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());
}
Now, everything works fine!
thanks for your helps!
I want to show a marker with the image of a profile picture using the Picasso Library.
I can't determine how. The userProfilePicture is the URL of the profile picture of the user, and I am storing on userProfilePictureReceived.
public class GoogleMaps extends Activity implements OnMapReadyCallback {
protected GoogleMap map;
protected String userNameReceived;
protected String userProfilePictureReceived;
protected Bitmap bmp;
protected BitmapDescriptor icon;
protected Canvas canvas1;
protected ImageView icon2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_maps);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
userNameReceived = MainActivity.userName;//using global variable userName from MainActivity class
userProfilePictureReceived = MainActivity.userProfilePicture;
// icon2 = (ImageView) findViewById(R.id.imageView2);
icon2.draw(canvas1);
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
bmp = Bitmap.createBitmap(80, 80, conf);
canvas1 = new Canvas(bmp);
}
#Override
protected void onRestart() {
super.onRestart();
}
#Override
protected void onStart() {
Picasso.with(GoogleMaps.this)
.load(userProfilePictureReceived)
.resize(100, 100)
.config(Bitmap.Config.ARGB_4444)
// .error(R.drawable.abc_btn_radio_to_on_mtrl_015) // en caso de no tener imagen pone una predeterminada
.transform(new RoundedTransformation(50, 4))
.into(icon2);
icon2.draw(canvas1);
// BitmapDrawable drawable = (BitmapDrawable) icon2.getDrawable();
//userPictureAsGeoPoint = drawable.getBitmap();
//icon = BitmapDescriptorFactory.fromBitmap(userPictureAsGeoPoint);
super.onStart();
}
#Override
protected void onResume() {
super.onResume();
}
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onStop() {
super.onStop();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
#Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title(userNameReceived))
.setIcon(BitmapDescriptorFactory.fromBitmap(bmp));
//marker.showInfoWindow
//marker.showInfoWindow
//setVisibility
}
}