A day with .Net

My day to day experince in .net

Archive for the ‘Android c#’ Category

Location Permission in Android Version 6 (android 6.0 marshmallow) With API Level 23

Posted by vivekcek on January 2, 2018

I was developing an android taxi app with gps location. Initially i targeted the app for API level 26 and later i decided for API level 23. In the app i need to get location permission at run time. I placed required attributes in android manifest as below.

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Then i asked for permission using the code below. Unfortunately after deploying the app in a marshmallow, the app never asked for permission. Then i went to App manager and gave permission manually.

  if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {


After some research i learn that to get run-time location permission in marshmallow, you have to try below steps in your Activity.

1. Override below method.

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case LOCATION_REQUEST_CODE: {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                } else {
                    Toast.makeText(getApplicationContext(), "Please provide the permission", Toast.LENGTH_LONG).show();

2. Request permission using below code.

if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(DriverMapActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);

Posted in Android c# | Tagged: , , , , | Leave a Comment »

Android development with c#

Posted by vivekcek on February 5, 2012

Software Requirements

1. Visual studio 2010

2. If you have previous installation of android SDK manger update it latest version.

3. You must have API LEVEL 14 and its ARM image file installed in android SDK.

4. Go to http://xamarin.com/monoforandroid and download evaluation version of ‘mono for android’ for windows.

5. xamarin installer will install.

    a) JDK 1.6.
    b) ANDROID SDK(if installed earlier,the installer will skip SDK installation).
    c) GTK C#.
    d) Mono develop(an alternative for visual studio).
    e) Mono for android.

6. Xamarin will install all the above components, If anything went wrong you can found setup’s in C:\Users\vivek \AppData\Local\Temp.

Apply a date modified sort in your temp folder to get .exe for all individual software’s.


1. Open Visual Studio 2010.

2. Click On Tools, Select ‘Start android emulator manager’.

3. On the emulator manager ensure API 14 SDK and ARM EABI V7a image are installed.

4. On the emulator manager click Tools and select ‘Manage AVDs’.

5. Create a new AVD with API LEVEL 14 and 512 MB ram.

6. Start newly created AVD.


1. Ensure your emulator is running.

2. In visual studio create new project using template ‘MonoAndroidApplication’.

3. The template will create an Activity.cs file.

4. Click debug, select emulator

It will take some time to install mono framework and your app to deploy in emulator



1. Create AVD

a) Open emulator

b) Manage AVD

c) Create AVD

2. Create Visual studio project

3. Checking package API 14 components

4. Final

Posted in Android c# | Tagged: , , | 3 Comments »