Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: request permission at runtime

I want to provide a functionality in my App for which I need the permission INTERNET.

However, not all user may want to use this functionality and since this is a very strong permission I don't want to force everyone to give it to the App if they want to use it, only if they want to use this functionality.

So I have to ask for that permission at run-time. the minimum sdk for the App is 15 and I don't want to set it higher.

The method requestPermissions(String[],int), which I can call in my Activity is only available with API 23, but I can callActivityCompat.requestPermissions(this,new String[]{Manifest.permission.INTERNET},0);, but it doesn't no dialog is shown.

And yes, I have checked if the permission is already granted:

if(ContextCompat.checkSelfPermission(this,Manifest.permission.INTERNET)!= 
PackageManager.PERMISSION_GRANTED)
    ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.INTERNET},0);

What am I doing wrong?

like image 434
Ginso Avatar asked Jul 16 '26 03:07

Ginso


2 Answers

android.permission.INTERNET persmission comes under automatically granted persmission therefore there is no need to ask for it.

Here is the list of automatically granted permission list. These permissions will be automatically granted at install time and will not be able to revoke.

android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT

refer this for more

like image 136
Ravi Avatar answered Jul 17 '26 16:07

Ravi


android.permission.INTERNET permission is a normal permission. So it automatically granted without any dialog. See more details here.

like image 44
manao Avatar answered Jul 17 '26 17:07

manao