How to determine live wallpaper intent is valid programmatically? - android

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)

may be you could check if an activity is available before starting the intent.
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent);
}

Related

How to resolve ANR errors in Google Play Store

I have a Flutter app targeting Android.
Recently I started getting ANR errors in Google Play Console pre-launch report. I have not made any significant changes to my app to trigger this, so it seems it is something Google is suddenly doing differently.
Errors are below:
ANR in com.google.android.apps.messaging;PID: 12100;Broadcast of Intent { act=com.google.android.gms.phenotype.UPDATE flg=0x30 pkg=com.google.android.apps.messaging cmp=com.google.android.apps.messaging/com.google.apps.tiktok.experiments.phenotype.ConfigurationUpdatedReceiver_Receiver (has extras) };
ANR in com.google.android.dialer;PID: 8132;Broadcast of Intent { act=com.google.android.gms.phenotype.UPDATE flg=0x30 pkg=com.google.android.dialer cmp=com.google.android.dialer/com.google.apps.tiktok.experiments.phenotype.ConfigurationUpdatedReceiver_Receiver (has extras) };
ANR in com.google.android.apps.photos;PID: 9438;Broadcast of Intent {
act=com.google.android.gms.phenotype.UPDATE flg=0x30
pkg=com.google.android.apps.photos
cmp=com.google.android.apps.photos/com.google.android.libraries.phenotype.client.stable.PhenotypeUpdateBackgroundBroadcastReceiver
(has extras) };
ANR in com.google.android.apps.safetyhub;PID: 12115;Broadcast of
Intent { act=com.google.android.gms.phenotype.UPDATE flg=0x30
pkg=com.google.android.apps.safetyhub
cmp=com.google.android.apps.safetyhub/com.google.apps.tiktok.experiments.phenotype.ConfigurationUpdatedReceiver_Receiver
(has extras) };
My app does not use photos, dialer, or any kind of messaging. Not even sure what safety hub is.
Strangely, only one device is reporting these errors (Pixel 6 arm64 API 31). Other devices Google uses for testing are not reporting this. If there was something wrong with my app I suspect all devices would be getting it (or at least all devices on the same API). Or am I missing something here?
What can be done?
Looks like this is a problem with Google Play Store testing devices. The problems went away without me making any significant changes.

Opening link using Intent.ACTION_VIEW caused android.content.ActivityNotFoundException on certain device(s)

Recently I started getting android.content.ActivityNotFoundException: for my app logged on Google Play Console. Codes causing this exception are :
private void openLink(String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Now the exception is rarely happened, it works fine on most of devices, and the url is 100% valid (a link to https://mathsolver.microsoft.com/).
My question is what caused them and what is the best way to handle them.
Is a simple try catch enough or there is way so that user that catch this exception can still open the url from their phone?
Whenever you are starting an activity that is from another app — such as a Web browser — you have to take into account that the user might not have access to such an app. Even something as common as a Web browser might be restricted on some devices (e.g., devices used by children).
As such, you need to wrap such startActivity() calls in a try/catch block and deal with ActivityNotFoundException. Exactly how you deal with it will be up to your app, but you will need to explain to the user that you are unable to start the desired app for some reason.

What is a reliable way to open the Gallery?

The following code works most of the time:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
startActivity(intent);
It throws the following exception sometimes (reported by error log from users):
android.content.ActivityNotFoundException: No Activity found to handle Intent {
act=android.intent.action.VIEW
dat=content://media/internal/images/media }
Stack trace:
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=android.intent.action.VIEW
dat=content://media/internal/images/media } at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1899)
at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1589)
at android.app.Activity.startActivityForResult(Activity.java:4228)
at android.support.v4.app.k.startActivityForResult(SourceFile:50) at
android.support.v4.app.p.startActivityForResult(SourceFile:79) at
android.app.Activity.startActivityForResult(Activity.java:4187) at
android.support.v4.app.p.startActivityForResult(SourceFile:859) at
android.app.Activity.startActivity(Activity.java:4515) at
android.app.Activity.startActivity(Activity.java:4483)
I am wondering if some users' Android devices do not have Gallery.
I am wondering if some users' Android devices do not have Gallery.
There is no requirement for any Android device to have any exported activity that supports that particular Intent structure (ACTION_VIEW for whatever MIME type is tied to that Uri, plus a content scheme).
Beyond that, there is no single app named "Gallery". Out of ~2 billion devices and ~10,000 device models, there may be hundreds of apps that serve this general role, and a device might not have any such app.
What is a reliable way to open Gallery on Android?
See CATEGORY_APP_GALLERY, and be sure to handle the case where there is no matching activity.

Android Usage Access for Android 5 Samsung devices

As you might know, since Android 5 was launched, accessing the recent tasks (usage stats) of your device requires the user to enable this feature manually (Settings->Security->Usage Access).
My app checks if the device uses Android 5, and if so, then it offers the user the possibility of opening the settings screen for enabling usage access:
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivityForResult(intent, 12345);
The problem comes when I try to do this in a Samsung device running Android 5... I got this error when the line shown above is executed:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.USAGE_ACCESS_SETTINGS }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)
at android.app.Activity.startActivityForResult(Activity.java:3913)
It seems that the Settings.ACTION_USAGE_ACCESS_SETTINGS action has not been implemented, which is weird because if you go to Settings the option to enable the app to access this usage stats is there...
Any idea of how to fix this problem for this specific case?
Sorry for the late reply, I hope you have found a good solution, but if not or for other people who have this problem,
this bug seems to exist in some Samsung models, to avoid the crash of your app, maybe you can check if your intent can be handled
PackageManager packageManager = getActivity().getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else {
Toast.makeText(getBaseContext(), "Please open settings, your model can't be forced
to open it", Toast.LENGTH_LONG).show();
}

No Activity found to handle MediaStore.ACTION_IMAGE_CAPTURE Intent

I am using this quite simple piece of code to capture an image on an Android device.
File tmpFile = ...;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tmpFile));
startActivityForResult(intent, CAPTURE_IMAGE);
This works fine for thousands of users except for one running this on a Kindle device without camera. Today I got a crash report from a device with camera:
ANDROID_VERSION=4.2.1
BRAND=Hisense
PHONE_MODEL=M470BSA
STACK_TRACE=android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityForResult(Activity.java:3370)
at android.app.Activity.startActivityForResult(Activity.java:3331)
...
I have put some exception handling around the code to catch the exception and show an error, but I have no idea why this piece of code is failing on this device. The user confirmed that the camera is working fine.
First, there is no requirement that a device have an activity that supports ACTION_IMAGE_CAPTURE, even if the device has an actual camera.
Second, particularly on Android 4.3+ tablets, the person using the device may not have access to an ACTION_IMAGE_CAPTURE activity, even if one is installed, as the person may be running in a restricted profile.

Categories

Resources