3

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?

Ginso
  • 459
  • 17
  • 33

3 Answers3

10

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

Ravi
  • 34,851
  • 21
  • 122
  • 183
1

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

manao
  • 328
  • 5
  • 12
  • but i don't develop for API 23 – Ginso Jun 22 '16 at 07:26
  • I think you misunderstand the purpose of ActivityCompat.requestPermissions. It doesn't set permissons at runtime, but only request to grant dangerous permission that is already added in manifest. – manao Jun 22 '16 at 07:31
  • what is the point in requesting a permission that users have already to give when installing the app? If u read my post u'd know that i DO want to request it at runtime and not just set it – Ginso Jun 22 '16 at 07:37
  • Such behavior is only for Androids below 6.0 and ActivityCompat is added for backward compatibility. You can't use it properly under 6.0 version. Also check this answer: http://stackoverflow.com/questions/2176114/can-android-apps-request-additinal-permissions-at-runtime?rq=1 – manao Jun 22 '16 at 07:41
0

What targetSDKVersion did you set? You have to set it to 23, otherwise permissions policy will be from older platforms.

Tomasz Czura
  • 2,414
  • 1
  • 14
  • 18
  • isn't it possible in older platforms? After all, this method was introduced long before API 23 – Ginso Jun 22 '16 at 07:25
  • In all platform below 23 you request permission at install time, and you have only to register it in manifest. On 23 Google change this behavior, and you can request permission by showing dialog and asking e.g. if you want to allow network connection. You can keep older behaviour (asking at installation time) at 23 by setting targetSdk lower than 23, or use new, by setting it to 23 (or higher), but on older platforms permissions will be still asking at installation time. – Tomasz Czura Jun 22 '16 at 07:45