Home > Mobile >  App stuck on splash screen in android 13 only
App stuck on splash screen in android 13 only

Time:12-24

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

CodePudding user response:

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" />

CodePudding user response:

Use this dependency for permissions

  implementation 'com.karumi:dexter:6.2.3'

how to implement see here

you can ask permission in the next activity and increase the delay time from 600 to 1500

  • Related