Sunday, December 9, 2018

1st day with Xamarin

I started to create an app in Xamarin as I have been reading creating-mobile-apps-xamarin-forms by Microsoft. As a beginner, I can say that it has taught me well.

Today I thought to try and spin up a simple app using Xamarin Forms. Let's start from the start I will be putting up all the issues, bus, Environment Setup steps I had to do while doing it.

Let’s get started.

Few conventions

  • #: Issue faced and resolution

First I would suggest going through my friend Kael's blogs to get you started with the Android SDK setup. Few things which are important for Simulator.


Internet connectivity


If you are having internet connectivity issue from the emulator. Read this article

Alright! I faced an internet connectivity problem on the emulator. If you had followed Kael's blogs links and added the entries it should be fine for you. Just make sure you start the emulator from visual studio and not from the Android Device Manager. Because those settings will be applied to the emulator when you run it from visual studio.

Xamarin and Hyper-v



Software and Tools


Software versions being used in the app development
  • Visual Studio 15.9.3
  • Xamarin Forms 3.3.0

Software versions are important because there is issue which is sometimes specific to the software version we are using.

Activity


#As I was working on Xamarin last week and it was working fine for me. Later in the week, I started doing some stuff with Hyper-v and also upgraded my VS to 15.9.3. I started my visual studio new Xamarin emulator and I see this error.


So I Googled this error like any other developer. So what I found that I had one component missing in the windows features.


After installing this feature you need to restart the machine.

Once it was created a new emulator image and it worked. I have an up and running emulator.

Alright, I guess one error is OK. :)

Now let me give you a brief of the app I am going to develop.

Idea!
  1. Show Maps.
  2. Get the selected location from the map.
  3. Background service runs to track the current location.
  4. Send a notification to the user as he/she is nearby of the selected location. 
Code for the app will be hosted in Github at WakeMeUp

Step 1: Showing Maps

Each feature that I add will be in a separate branch so that I know what all code is required to do it, for google map branch is "gmap-integrate". Go through the article about Adding map in the Xamarin forms app.

#: As per the adding map in Xamarin guide, you need to install Xamarin.Forms.Map for all three projects. After installing the package it did not show in any of the projects. Just close VS and reopen it, that should fix it.

If you follow the adding map in Xamarin forms app guide, we should be able to see the maps running in the emulator. But Noooo.. How could this be so easy? 

When I ran the application it crashed with an error in the output window.. saying.. "my location requires permission access_fine_location or access_coarse_location". So it seems we need to request for the permissions we need.

[I guess after the Android marshmallow release application needs to explicitly request for  location permission.]

After doing some research over the internet and found that I can use Plugin.Permissions
[You may be able to find some other solution for this. This is as per my knowledge till now. Please add comments if you find any other better way to do it.]


I followed the steps mentioned in the plugin notes and I got it working.

If you hit the current location on the emulator it will show the location that is set in the settings. To change the location you can go to Location settings of the emulator and add different lat and lon of your choice.


Let's see what I did on Second day with Xamarin

No comments:

Post a Comment