Git Product home page Git Product logo

locationpermissionandroid's Introduction

Runtime Permissions

In Android 6.0 and higher, the Android application permissions model is designed to make permissions more understandable, useful, and secure for users. The model moved Android applications that require dangerous permissions (see Affected permissions) from an install-time permission model to a runtime permission model:

  • Install-time permissions

    (Android 5.1 and lower) Users grant dangerous permissions to an app when they install or update the app. Device manufacturers and carriers can preinstall apps with pregranted permissions without notifying the user.

  • Runtime permissions

    (Android 6.0 – 9) Users grant dangerous permissions to an app when the app is running. When permissions are requested (such as when the app launches or when the user accesses a specific feature) depends on the application, but the user grants/denies application access to specific permission groups. OEMs/carriers can preinstall apps, but can’t pregrant permissions unless they go through the exception process. (See Creating exceptions.)

    (Android 10) Users see increased transparency and have control over which apps have activity recognition (AR) runtime permissions. Users are prompted by the runtime permissions dialog to either always allow, allow while in use, or deny permissions. On an OS upgrade to Android 10, permissions given to apps are retained, but users can go into Settings and change them.


AndroidManifest.xml

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

Interface

<?xml version="1.0" encoding="utf-8"?>  
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  xmlns:app="http://schemas.android.com/apk/res-auto"  
  xmlns:tools="http://schemas.android.com/tools"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent"  
  tools:context=".MainActivity">  
  
  
 <ImageView  android:id="@+id/loc"  
  android:layout_width="100dp"  
  android:layout_height="100dp"  
  android:src="@drawable/ic_baseline_location_on_24"  
  app:layout_constraintLeft_toLeftOf="parent"  
  app:layout_constraintRight_toRightOf="parent"  
  app:layout_constraintTop_toTopOf="parent"  
  app:layout_constraintBottom_toBottomOf="parent"/>  
  
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA

package com.example.requestpermission;  
  
import androidx.annotation.NonNull;  
import androidx.appcompat.app.AppCompatActivity;  
  
import android.Manifest;  
import android.app.Activity;  
import android.content.pm.PackageManager;  
import android.os.Build;  
import android.os.Bundle;  
import android.view.View;  
import android.widget.ImageView;  
import android.widget.Toast;  
  
public class MainActivity extends AppCompatActivity {  
    ImageView loc ;  
  @Override  
  protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
  setContentView(R.layout.activity_main);  
  loc = findViewById(R.id.loc) ;  
  
  
  loc.setOnClickListener(new View.OnClickListener() {  
            @Override  
  public void onClick(View view) {  
                reqLocPerm();  
  }  
        });  
  }  
  
    public void reqLocPerm(){  
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){  
            requestPermissions(new String[] {Manifest.permission.ACCESS_FINE_LOCATION},1200);  
  }  
    }  
  
    @Override  
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {  
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);  
 if (requestCode == 1200 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {  
            Toast.makeText(this, "ok", Toast.LENGTH_SHORT).show();  
  } else {  
            moveTaskToBack(true);  
  android.os.Process.killProcess(android.os.Process.myPid());  
  System.exit(1);  
  }

locationpermissionandroid's People

Contributors

aymen-moulehi avatar

Stargazers

Ktari ayman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.