Odino Odino - 1 month ago 19
Android Question

android api 23 dialog alert permission does not appear

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.

Answer

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)