GridLayoutManager – how to auto fit columns?

You can calculate available number of columns, given a desired column width, and load the image as calculated. Define a static funtion to calculate as: public class Utility { public static int calculateNoOfColumns(Context context, float columnWidthDp) { // For example columnWidthdp=180 DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); float screenWidthDp = displayMetrics.widthPixels / displayMetrics.density; int noOfColumns = (int) … Read more

Xamarin – How to update Mono.Android version to resolve dependencies?

tried changing my target android version to 8.1 You need to change the Target Framework that is used to compile your android application, not the Target Android version (but assumably you would set these two to the same, read the Understanding Android API Levels link below. Visual Studio for Windows: Visual Studio for Mac: Target … Read more

Write device platform specific code in Xamarin.Forms

This is a scenario which is easily resolved with dependency injection. Have a interface with the desired methods on your shared or PCL code, like: public interface IUserPreferences { void SetString(string key, string value); string GetString(string key); } Have a property on your App class of that interface: public class App { public static IUserPreferences … Read more

Xamarin (Android) Unit Tests in Visual Studio 2017

There are three basic levels of testing: The classic unit testing of pure .Net/Mono code via xUnit|NUnit Nothing new here, this is the same testing that .Net programmers have been doing all long and has nothing to do with the Xamarin platform frameworks Note: These tests are totally independent of Xamarin.Android|iOS|Mac On platform testing (including … Read more

Xamarin AlarmManager Android

The problem is that your BroadcastReceiver does not have the [BroadcastReceiver] attribute. This code works: AlarmReceiver.cs [BroadcastReceiver] public class AlarmReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra(“message”); var title = intent.GetStringExtra(“title”); var resultIntent = new Intent(context, typeof(MainActivity)); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var pending = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.CancelCurrent); … Read more