androidlive-wallpaperactivitynotfoundexception

How to determine live wallpaper intent is valid programmatically?


I add a live wallpaper feature in our app, but got some exception in firebase. I tested on our ten android devices and got no exception, I wonder if I can determine live wallpaper is supported in a specific device programmatically (I don't want to filter devices in Google Play Console, as it kick out tow much devices)? thanks.

Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.service.wallpaper.CHANGE_LIVE_WALLPAPER (has extras) }
       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2067)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
       at android.app.Activity.startActivityForResult(Activity.java:5383)
       at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java)
       at android.app.Activity.startActivityForResult(Activity.java:5341)
       at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java)

Solution

  • may be you could check if an activity is available before starting the intent.

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent);
    }