0

in my app i need the android internet permission.

I have insert the permission in the file AndroidManifest.xml (with others permissions)

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />

the build.gradle defaul config have the correct api level:

defaultConfig {
        applicationId "com.mytry"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

and the activity with the internet call is this:

public class ActivityLoginScreen extends Activity{

    final int REQUEST_INTERNET = 1;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.INTERNET)) {
                //permesso già richiesto in precedenza. Negato dall'utente
            } else {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.INTERNET}, REQUEST_INTERNET);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case REQUEST_INTERNET: {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(this, "GRANTED", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this, "NO GRANTED", Toast.LENGTH_SHORT).show();
                }
                return;
            }
        }
    }

But when i launch my app and go to the activity nothing appare. If i go in the app settings emulator, i can see only 2 permissions.

enter image description here Possible solution for this problem? Where i am in wrong?

I have use this type of request in other apps without problems

Thank you.

EDIT:

For all the comments type this: "no necessary the request because: If an app declares that it needs a normal permission, the system automatically grants the permission to the app"

this is correct. sorry for this stupid question. I knew the matter of default permission but my appa did not work anyway because it gave error in Internet permission. I created a new emulator and now seems to be going.

Odino
  • 141
  • 1
  • 6
  • 17
  • 2
    `android.permission.INTERNET` is not considered to be a dangerous permission and thus is granted by default. No app will show the permission in the app settings. You can find a list of all permissions here: https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous – Niels Masdorp Oct 27 '16 at 07:25
  • here is sample https://stackoverflow.com/questions/38141523/directory-creation-not-working-in-marshmallow-android/38141778#38141778 – Sohail Zahid Oct 27 '16 at 07:39

3 Answers3

2

Not all permission need to be granted by user. According to Android Documentation

System permissions are divided into two categories, normal and dangerous:

  • Normal permissions do not directly risk the user's privacy. If your app lists a normal permission in its manifest, the system grants the permission automatically.

  • Dangerous permissions can give the app access to the user's confidential data. If your app lists a normal permission in its manifest, the system grants the permission automatically. If you list a dangerous permission, the user has to explicitly give approval to your app.

You only need to check for permission if the permission is belong to dangerous permission category (Ex: Location, Storage, Camera etc)

Community
  • 1
  • 1
Amad Yus
  • 2,856
  • 1
  • 24
  • 32
0

Internet permission are granted by default.

It does not require user to grant it, so you already have internet permission just enable your internet.

Vishal Sanghani
  • 874
  • 1
  • 10
  • 19
0

Normal permissions cover areas where your app needs to access data or resources outside the app's sandbox, but where there's very little risk to the user's privacy or the operation of other apps. For example, permission to set the time zone is a normal permission. If an app declares that it needs a normal permission, the system automatically grants the permission to the app. For a full listing of the current normal permissions, see Normal permissions.

As of API level 23, the following permissions are classified as PROTECTION_NORMAL:

For these no dailog will shown to user system will automatically grant the permission.

ACCESS_LOCATION_EXTRA_COMMANDS
ACCESS_NETWORK_STATE
ACCESS_NOTIFICATION_POLICY
ACCESS_WIFI_STATE
BLUETOOTH
BLUETOOTH_ADMIN
BROADCAST_STICKY
CHANGE_NETWORK_STATE
CHANGE_WIFI_MULTICAST_STATE
CHANGE_WIFI_STATE
DISABLE_KEYGUARD
EXPAND_STATUS_BAR
GET_PACKAGE_SIZE
INSTALL_SHORTCUT
INTERNET
KILL_BACKGROUND_PROCESSES
MODIFY_AUDIO_SETTINGS
NFC
READ_SYNC_SETTINGS
READ_SYNC_STATS
RECEIVE_BOOT_COMPLETED
REORDER_TASKS
REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
REQUEST_INSTALL_PACKAGES
SET_ALARM
SET_TIME_ZONE
SET_WALLPAPER
SET_WALLPAPER_HINTS
TRANSMIT_IR
UNINSTALL_SHORTCUT
USE_FINGERPRINT
VIBRATE
WAKE_LOCK
WRITE_SYNC_SETTINGS

All dangerous Android system permissions belong to permission groups. If the device is running Android 6.0 (API level 23)

PROTECTION_DANGEROUS permissions :

These permissions will show dialog to users.Sample Code

READ_CALENDAR
WRITE_CALENDAR
CAMERA
READ_CONTACTS
WRITE_CONTACTS
GET_ACCOUNTS
ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
RECORD_AUDIO
READ_PHONE_STATE
CALL_PHONE
READ_CALL_LOG
WRITE_CALL_LOG
ADD_VOICEMAIL
USE_SIP
PROCESS_OUTGOING_CALLS
BODY_SENSORS
SEND_SMS
RECEIVE_SMS
READ_SMS
RECEIVE_WAP_PUSH
RECEIVE_MMS
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
Community
  • 1
  • 1
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41