-4

This code runs on all version Below 7.0 version of android but doesn't runs on Nougat. When I press the button, it does not go next activity? Please tell us how to add Nougat permission in below code?

currentlocation.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        currentlocation.startAnimation(animTranslate);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(Front.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_PERMISSON_SORAGE);

            }
        } else {
            if (interstitialAd.isLoaded()) {
                interstitialAd.show();
            }
            Intent iu = new Intent(Front.this, MainActivity.class);
            startActivity(iu);
        }
    }
});
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_PERMISSON_SORAGE
            && grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        Intent i = new Intent(Front.this, MainActivity.class);
        startActivity(i);
        //finish();
    } else {
        Toast.makeText(this, "Please Allow permision to use App .", Toast.LENGTH_SHORT).show();
        finish();
    }
}

Here is my manifest showing added 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_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Ivar
  • 6,138
  • 12
  • 49
  • 61

1 Answers1

0

First off, the permission system starts at API 23 and above, so that code should be:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

Secondly, there are more dangerous permissions you haven't requested:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ---> You did request this
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

You only request READ_EXTERNAL_STORAGE. Request the rest as well. Add them into the String array like you did with READ_EXTERNAL_STORAGE

Zoe
  • 27,060
  • 21
  • 118
  • 148