Android M introduces new run-time permission model which allows you to do this.
answered Sep 30, 2015 at 11:46 1,893 1 1 gold badge 17 17 silver badges 26 26 bronze badgesYes,If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher.
if(ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) < ActivityCompat.requestPermissions(activity, new String[], 1); > int result = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE); if (result == 0) // function which uses the permission >
17.3k 6 6 gold badges 31 31 silver badges 47 47 bronze badges
answered Jan 7, 2016 at 4:48
Nitin Kumar Nitin Kumar
39 2 2 bronze badges
From targetapi>22 android need to have runtime permissions for performing some operations,Following is the code for requesting permission at run time in android
//checking wether the permission is already granted if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) ==PackageManager.PERMISSION_GRANTED)< // permission is already granted >else< //persmission is not granted yet //Asking for permission ActivityCompat.requestPermissions(this,new String[] < Manifest.permission.READ_CONTACTS>,REQUEST_CODE); >
The above code is for requesting read contact permissions. Similarly you can request other permissions also based on your requirement.
19.8k 34 34 gold badges 72 72 silver badges 79 79 bronze badges answered Feb 15, 2017 at 4:21 76 4 4 silver badges 16 16 bronze badgesWhile many will answer this question with NO, and will tell you that it is a security risk, I found a way!
Take a look at ASTRO File Manager, one of the famouse file manager application for android. It can brows your SD-CARD, show your images, videos and the most interesting thing, it can install APKs!
So theoretically if I created an app that did not request for internet access during the install time, I could attach an APK inside my Raw library and install it in run time, and place all my permissions there. After that it's easy only a meter of applications communications. You can do this with broadcast or shared application id(read about it first it might be risky)
From user experience it will looks like you are asking a permission in run time.