0

So for a few days i've been struggling to get my app to ask for all the needed permissions on startup. Ive got it coded in to ask for Read and write external storage, Internet, and Access network state. When the app opens it only asks for Storage permissions, and in settings->apps->my app in permissions the only thing there is Storage. any help would be greatly appreciated.

here is my code

package gstankdev.gstank.mobilesvn;

import android.Manifest;
import android.content.Intent;    
import android.content.pm.PackageManager;
import android.net.Uri;
import android.provider.Settings;
import android.support.annotation.NonNull; 
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;




public class MobileSVN extends AppCompatActivity{
private static final int REQUEST_PERMISSIONS = 10;
public static MobileSVN mobsvn;

protected void onCreate(Bundle savedInstanceState) {
    mobsvn = this;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mobile_svn);
    if (ContextCompat.checkSelfPermission(MobileSVN.this, Manifest.permission.READ_EXTERNAL_STORAGE)
            + ContextCompat.checkSelfPermission(MobileSVN.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            + ContextCompat.checkSelfPermission(MobileSVN.this, Manifest.permission.INTERNET)
            + ContextCompat.checkSelfPermission(MobileSVN.this, Manifest.permission.ACCESS_NETWORK_STATE)
            != PackageManager.PERMISSION_GRANTED) {
        //permsGranted = false;
        if (ActivityCompat.shouldShowRequestPermissionRationale(MobileSVN.this, Manifest.permission.READ_EXTERNAL_STORAGE) ||
                ActivityCompat.shouldShowRequestPermissionRationale(MobileSVN.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ||
                ActivityCompat.shouldShowRequestPermissionRationale(MobileSVN.this, Manifest.permission.INTERNET) ||
                ActivityCompat.shouldShowRequestPermissionRationale(MobileSVN.this, Manifest.permission.ACCESS_NETWORK_STATE)) {
            Snackbar.make(findViewById(android.R.id.content), getString(R.string.app_name),
                    Snackbar.LENGTH_LONG).setAction((R.string.enable),
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ActivityCompat.requestPermissions(MobileSVN.this,
                                    new String[]{
                                            Manifest.permission.INTERNET,
                                            Manifest.permission.READ_EXTERNAL_STORAGE,
                                            Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                            Manifest.permission.ACCESS_NETWORK_STATE},
                                    REQUEST_PERMISSIONS);
                        }
                    }).show();
        } else {
            ActivityCompat.requestPermissions(MobileSVN.this,
                    new String[]{
                            Manifest.permission.READ_EXTERNAL_STORAGE,
                            Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            Manifest.permission.INTERNET,
                            Manifest.permission.ACCESS_NETWORK_STATE},
                    REQUEST_PERMISSIONS);
        }
    }

}
@Override
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String permissions[],
                                       @NonNull int[] grantResults) {
    switch (requestCode) {
        case REQUEST_PERMISSIONS: {
            if ((grantResults.length > 0) && (grantResults[0] +
                    grantResults[1]) == PackageManager.PERMISSION_GRANTED) {
                //do nothing
            } else {
                Snackbar.make(findViewById(android.R.id.content), R.string.app_name,
                        Snackbar.LENGTH_LONG).setAction(R.string.enable,
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent();
                                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                intent.addCategory(Intent.CATEGORY_DEFAULT);
                                intent.setData(Uri.parse("package:" + getPackageName()));
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                                intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                                startActivity(intent);
                            }
                        }).show();
            }
        }
    }
}





public Button begin;

public void init(){
    begin = (Button)findViewById(R.id.begin);
    begin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MobileSVN.this, svnsetup.class));
        }
    });
        }








@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    init();

}}

2 Answers2

1

Android Permissions are divided into normal and dangerous permissions. We (developers) only need to check and ask for the dangerous permissions at runtime, the normal are always granted from the manifest.

Here you can see the complete list dangerous permissions: https://developer.android.com/guide/topics/permissions/requesting.html#normal-dangerous

Budius
  • 39,391
  • 16
  • 102
  • 144
1

When the app opens it only asks for Storage permissions

Because the other two permission :

Manifest.permission.INTERNET
Manifest.permission.ACCESS_NETWORK_STATE

are classified as PROTECTION_NORMAL. so for api 23 you don't need runtime permission for them.

Check this for list of permissions

You only need to request permission for those which are classified as Dangerous permissions

Like:

GET_ACCOUNTS
ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
Community
  • 1
  • 1
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • I did not know this i assumed that's why my coding for a button to start a download from a server wasn't working but apparently it's back to the drawing board. thanks – Greg Stanke Apr 25 '17 at 00:54