Garvit
Garvit

Reputation: 47

App stuck on splash screen in android 13 only

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

Upvotes: 1

Views: 2701

Answers (1)

Malik Bilal
Malik Bilal

Reputation: 1101

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

Upvotes: 2

Related Questions