Posts

Showing posts with the label Android

Get started with SQLite in from Xamarin.Forms

Image
Get started with SQLite in from Xamarin.Forms Today I demonstrate how we can leverage sqlite to save data on mobile which can be useful for local application or to store cached data. In this post, I will show how we can use Sqlite from Xamarin.Forms in an Android application. This post will be composed by 3 parts: 1. Get Sqlite.net 2. Dependency service and database path 3. Use Sqlite from Xamarin.Forms 1. Get Sqlite The library that I always use is SQLite.net-pcl from praeclarum https://www.nuget.org/packages/sqlite-net-pcl/ .To not be confused with another SQLite.Net-PCL which is a fork of the original. To get started, simply install Sqlite in the Android project and in the Xamarin.Forms project. Once installed, Sqlite namespace should be accessible. And we should also have access to SqliteConnection . In order to start a connection, we need to provide a database path. The database path is platform specific. It is usually stored in a private folder of the application and is not...

Transform an operation from a Xamarin.Android activity to an awaitable task

Image
Transform an operation from a Xamarin.Android activity to an awaitable task Today I want to share a neat trick which I have been using a lot - transform an asynchronous operation (triggered with StartActivityFromResult) from an Android Activity to an awaitable task - which then can be used with async await keywords in a Xamarin.Forms PCL project. Problem CustomPickActivity TaskCompletionSource in service 1. Problem In order to pick a file from the device local storage and execute an action using the selected file, the pick action (StartActivityFromResult/OnActivityResult) must be turned to an awaitable Task. 2. PickActivity To pick a file from our Xamarin.Forms project, we use a service which starts a picker activity. public class FilePicked : EventArgs { public string AbsolutePath { get; set; } } [Activity] public class PickActivity: Activity { static event EventHandler<FilePicked> OnFilePicked; protected override void OnCreate(Bundle savedInstanceState...

Differences between Internal and External Folders in Xamarin.Android

Differences between Internal and External Folders in Xamarin.Android and Xamarin.Forms When using Xamarin.Forms and Xamarin.Android, chances are that you had at one point of time to access a local file. Whether it is an image or a text file or even a local sqlite database, accessing a file from a Xamarin.Android project can be confusing. Today I will show you how you can get the absolute path of the different folders available in Xamarin.Android and we will see how we can get the paths from Xamarin.Forms. This post is composed 3 parts: 1. Internal folder 2. Public and private external folders 3. Access folder paths from Xamarin.Forms 1. Internal folder The internal folder is a folder specific to your application. It can only be access within your application and no other applications can touch the files within that folder. You can get it using the following: Android.App.Application.Context.FilesDir.AbsolutePath The path looks something like that: /data/user/0/com.kimserey.m...

Why I created Baskee?

Image
Why I created Baskee? Few days ago, I released my first Android app Baskee built with Xamarin and F# . https://www.kimsereylam.com/baskee In this post, I would like to share with you the most common questions my friends asked me and I hope it will help you understand better why Baskee is useful for you! This post answers the following questions: 1. Where did the idea come from? 2. What are the problems Baskee solves? 3. Is Baskee free? 4. How many people worked on it? 5. What stack is it built on? 6. If you had one advice for new developers to start what would it be? 1. Where did the idea come from? I was walking at the supermarket and saw Nescafe coffee tin selling at 6 pounds. I am a big coffee consumer so I regularly buy coffee and I knew other days I did no pay for 6 pounds but I couldn’t remember how much I used to pay and even in which shop it was cheaper. I tried to check online but there was no network at the supermarket. So I didn’t get it and continue to shop. B...

Fix adb server is out of date killing... Android

Fix adb server is out of date killing... Last week I showed you how to fix the error adb server version doesn't match... with Xamarin.Android - https://kimsereyblog.blogspot.co.uk/2016/11/fix-installfailed-error-adb-server.html when trying to deploy an application built in Xamarin.Studio to a Genymotion VM. This was caused by two different versions of ADB being installed on the machine. One installed during Xamarin installation and another one installed separately. The solution was to set the ADB path in the options of Genymotion. I thought all was good but turns out there was another issue. 1. Problem When running adb shell , I had the following error in bash: adb server is out of date killing... 2. Solution Again the problem was due to my machine having two adb versions and the adb location in $PATH was the wrong one. In order to check verify that, I ran echo $PATH and saw that the path was incorrect. In order to rectify that, I modified the ~/.bash_profile which is ...

Fix INSTALL_FAILED error - adb server version doesn't match in Xamarin.Android

Fix INSTALL_FAILED adb server version doesn’t match Xamarin.Android Today I would like to share with you how you can fix the following problem: INSTALL_FAILED /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets: Warning: error: could not install *smartsocket* listener: Address already in use ADB server didn't ACK * failed to start daemon * error: cannot connect to daemon List of devices attached adb server version (32) doesn't match this client (36); killing... 1. Problem You might be running two different ADB and the versions collide. 2. Solution Verify the ADB version used by Xamarin: About Xamarin > Show details > Android SDK: [PATH] Make sure the PATH is the same as the one referenced in Genymotion. Genymotion > Settings > ADB > Use custom Android SDK tools > Put PATH in Android SDK This means that the adb used by Xamarin Studio to perform all deployment commands will be the same as the dae...

How to fix Xamarin Android app instantly closing with error after deployment

Image
Xamarin.Android app instantly closing with error after deployment Last week I had an issue suddenly after updating Xamarin.Android and downloading the latest Android sdk 24. My application kept closing instantely after being deployed showing the following error: Unfortunately, [App name] has stopped. I looked online and all I found was answers which recommended to uninstall the app either through the Android settings or using adb uninstall <package name> , clean and rebuild but nothing did it . It was still crashing. 1. Scoping the issue I wasn’t sure what was going on until I remembered that I could access the logs via adb logcat . After inspecting the logs, I saw the following error message: AndroidRuntime: java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider: java.lang.RuntimeException: Unable to find application Mono.Android.Platform.ApiLevel_24 or Xamarin.Android.Platform! It was that it couldn’t find ApiLevel_24 but my manifest was configure...

What does DP, DPI, PPI and PX represent in Android?

What does DP, DPI, PPI and PX represent in Android? I’ve been playing with Xamarin Android for a while now and one thing that disturbed me when I started was the units of measure. What is the difference between DP, DPI, PPI and PX in Android? I found my answers in the Material design guide and today I would like to share my undertanding of the differences and bring a different explanation which hopefully will help you get a better understanding. This post is composed by three parts: 1. PX - pixels 2. DPI / PPI - pixels per inch 3. DP - density-independent pixel 1. PX - pixels Pixels is the most granular unit of measure. When talking about resolution 1920x1080, 2560x1440, etc… It represents the amount of pixels which fit in the screen. The higher the better but a second aspect equally important has too be taken in consideration - the screen dimension . Two devices with the same resolution but different screen sizes will not have the same display. For a similar resolution, th...

How to make a splash screen with Xamarin.Android

Image
How to make a splash screen with Xamarin.Android The first time I had to implement a splash screen for a Xamarin.Android app, I was completely lost. Xamarin official documentation is great https://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/ but without prior knowledge in Android, it is hard to follow. So today I would like to show you how you can create a splash screen for an Xamarin.Android app and provide more explicit information on what is happening and why is it done this way. This post is composed by 3 parts. 1. What's a splash screen 2. Implement the splash screen 3. Use the splas screen A full sample is available on my GitHub https://github.com/Kimserey/FileFoldersXamarin/tree/master . 1. What’s a splash screen A splash screen is a screen shown to the user while the application is loading in the background. Xamarin.Forms applications take few seconds before being completely loaded, therefore it is important to provide a splash scr...

Publish your Android app to Google Play Store

Image
Publish your Android app to Google Play Store Have you ever wondered what needs to be done to push an app on google play store? How many steps are involved? How much does it cost? What information is required? Few weeks ago I asked myself these questions and to answer it, I decided to publish an app on Google play store. Last week I completed a simple application and pushed it under alpha release on the Play store so today I would like to share what I did so that you will know how to do it too. This post is composed by three parts: 1. Build, signed and aligned the APK 2. Activate the google play developer console 3. Push your app Here’s a preview screen of my app published in alpha release - Baskee . You will see the acronym APK everywhere in this post. APK is the format of the application packages delivered for Android devices. Just in case you are interested, my development stack is VS2015 on Windows10, coding in F#/C# with Xamarin forms and Xamarin Android. 1. Build, si...