1

My app got stuck on spalsh screen in Android 13 without any crash and even not asking for permissions on lower android versions it's working absolutely perfect

public class SplashScreen extends AppCompatActivity {

String[] permissionsList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        permissionsList = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.POST_NOTIFICATIONS};
    } else {
        permissionsList = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE};
    }

    ((RubberLoaderView) findViewById(R.id.loader1)).startLoading();
    if (Utils.hasPermissions(this, permissionsList)) {
        ActivityCompat.requestPermissions(this, Utils.permissions, Utils.perRequest);
    } else {
        gotoNext();
    }

}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == Utils.perRequest) {
        if (Utils.hasPermissions(this, permissionsList)) {
            ActivityCompat.requestPermissions(this, Utils.permissions, Utils.perRequest);
        } else {
            gotoNext();
        }
    }
}

void gotoNext() {
    new Handler().postDelayed(() -> {
        startActivity(new Intent(SplashScreen.this, Home.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        finish();
    }, 600);
}

This is my code I am not able to understand the issue

Garvit
  • 37
  • 7

1 Answers1

2

As by understanding some of your code you are navigating to the next screen if the user allowed the specific runtime permissions. The issue with that is there are some permission changes in recent versions of Android that your code doesn't respect.

First The WRITE_EXTERNEL_STORAGE permission is deprecated after API Level 28. So if you request that permission it will always return denied.

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

Second The READ_EXTERNAL_STORAGE is deprecated after API Level 32. It will return denied if you use it in Android 13

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

Alternatively, if you want to access Photos & Videos of other apps in Android 13 you can ask for the below permissions.

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

Malik Bilal
  • 869
  • 8
  • 25
  • It worked but I have to give permission mannualy it's not asking for permission any way for it ? – Garvit Dec 23 '22 at 15:36
  • Which permission you're asking for and on which device? There might be a chance that the permission is already granted. – Malik Bilal Dec 23 '22 at 17:43
  • When I add these three permissions beginning with READ_ it seems something missing from the old usage. Are these permissions fully written from READ_MEDIA_* side? @MalikBilal – Bay Jan 21 '23 at 22:34