2

I have an android application that needs following permission to run.

ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE, WRITE_EXTERNAL_STORAGE, RECORD_AUDIO

My AndroidManifest.xml is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.volkswagenits.passengerapp">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>


    <application
        ...
</manifest>

My Splash activity is:

public class SplashActivity extends Activity {
    private static final String TAG = SplashActivity.class.getSimpleName();
    private static int SPLASH_TIME_OUT = 10000;
    private final int REQ_SOLVE_SERVICES_CODE = 15005;
    private int REQ_PERM_CODE = 1010;
    public static AudioInput AUDIO_INPUT;
    private static final String[] requiredPermissions = new String[] { ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE, WRITE_EXTERNAL_STORAGE, RECORD_AUDIO};


    private void requestPermissionIfNeeded() {
        boolean allGranted = allPermissionsGranted(this, requiredPermissions);
        if (!allGranted) {
            ActivityCompat.requestPermissions(this,
                    requiredPermissions, REQ_PERM_CODE);
        } else {
            //If all permissions are granted, check that PlayServices are available
            checkPlayServices();
        }
    }

    private void initializeGlass() {

    }




    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQ_PERM_CODE) {
            boolean allGranted = true;
            for (int result : grantResults) {
                if (result == PackageManager.PERMISSION_DENIED) {
                    allGranted = false;
                    break;
                }
            }
            if (!allGranted) {

            } else {
                //If all permissions are granted, check that PlayServices are available
                checkPlayServices();
            }
        }

    }


    private void checkPlayServices() {
        int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
        if (status != ConnectionResult.SUCCESS) {
            if (GoogleApiAvailability.getInstance().isUserResolvableError(status)) {
                GoogleApiAvailability.getInstance().getErrorDialog(this, status, REQ_SOLVE_SERVICES_CODE).show();
            } else {
                Toast.makeText(this, "Bus Sewa can not run without GoolgeServices.", Toast.LENGTH_SHORT).show();
                finish();
            }
        } else {
            bootGlasAndContinue();

        }
    }


}

Code for all permission granted:

public static boolean allPermissionsGranted(Context context, String[] permissions) {
    for (String perm : permissions) {
        if (ContextCompat.checkSelfPermission(context, perm) == PackageManager.PERMISSION_DENIED) {
            return false;
        }
    }
    return true;
}

When an application starts it does ask for permission to access fine location. It does ask for permission to record audio. However, it doesn't ask for permission for write external storage.

I have created a small demo application. This code seems to work there. What am I missing?

Final Edit: Removed irrelevant code.

Harshil
  • 883
  • 1
  • 8
  • 25
Amit
  • 152
  • 1
  • 2
  • 12
  • Why do you request ACCESS_FINE_LOCATION permission two times ? As it defines in Array. – Kuls Oct 11 '17 at 05:30
  • 2
    Possible duplicate of [Proper Way of Requesting WRITE\_EXTERNAL\_STORAGE Permission](https://stackoverflow.com/questions/43385895/proper-way-of-requesting-write-external-storage-permission) – Tigger Oct 11 '17 at 05:35
  • what is Set requiredPermissions = GlasAI.instance().requiredPermissions(); from where you getting that array check that if it contains write external permission – Pavan Oct 11 '17 at 05:36
  • @KulsDroid I have removed it. Edited the code. – Amit Oct 11 '17 at 05:47
  • @Pavan see the edited code. And yes GlasAI.instance().requiredPermissions() did have WRITE_EXTERNAL_STORAGE. Anyway even hardcoding it is not working – Amit Oct 11 '17 at 05:48
  • @Tigger no that thread doesn't help. Before posting i already had gone down through that thread. – Amit Oct 11 '17 at 05:50
  • Can you share the code of allPermissionsGranted ? because it seems this function edits your required_permissions array and removes write_external_storage directly before you ask. – Dany Minassian Oct 11 '17 at 06:59
  • public static boolean allPermissionsGranted(Context context, String[] permissions) { for (String perm : permissions) { if (ContextCompat.checkSelfPermission(context, perm) == PackageManager.PERMISSION_DENIED) { return false; } } return true; } – Amit Oct 11 '17 at 09:03

2 Answers2

2

The cause of the issue must be an external library pulled in using gradle which had its own manifest requesting something like this

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18">

So in the app manifest file you need to put a permission like this

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" /> 

This overrides the permission set by the other app, HockeyApp in your case

Harshil
  • 883
  • 1
  • 8
  • 25
-1

It worked:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>

Hockey app was a problem.

Amit
  • 152
  • 1
  • 2
  • 12