No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE } - android

I received the following crash report in my Android application when trying to call the ACTION_IMAGE_CAPTURE intent. This code has been running in my app for months with no issues. I am guessing this is something specific to a certain type of phone but unfortunately Google does not provide me with any additional information outside the stack trace. Any ideas what could have caused this crash report?
Stack Trace
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
at android.app.Activity.startActivityFromChild(Activity.java:3067)
at android.app.Activity.startActivityForResult(Activity.java:2847)
Producing Code
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, MY_CAMERA_ACTIVITY_REQUEST_CODE);
Manifest Entries
<uses-sdk android:minSdkVersion="7" />
<uses-feature android:name="android.hardware.camera" />

A few things come to mind
1.Could be a tablet, the kindle fire does not have a camera.
2. A phone that does not have a camera
3. No SD card installed
I agree you would think it would be a safe operation to call the image capture intent but with so many devices running Android it's impossible to know what device your app is running on.

Related

Why does SHOW_ALARMS need SET_ALARMS permission on GALAXY S21?

Here is my code:-
public void onClick(View v) {
try {
startActivity(new Intent(
"android.intent.action.SHOW_ALARMS"));
} catch (ActivityNotFoundException ignore) {
Toast.makeText(ac, "ActivityNotFoundException",
Toast.LENGTH_LONG).show();
}
}
This works on the Android emulator running Android 12 API 31: it shows the system clock application with the alarms page. On my Samsung Galaxy S21, also running Android 12 API 31, I get this error:-
Process: uk.co.yahoo.p1rpp.secondsclock, PID: 27629
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SHOW_ALARMS cmp=com.sec.android.app.clockpackage/.alarm.activity.AlarmCTSHandleActivity } from ProcessRecord{769a91e 27629:uk.co.yahoo.p1rpp.secondsclock/u0a362} (pid=27629, uid=10362) requires com.android.alarm.permission.SET_ALARM
at android.os.Parcel.createExceptionOrNull(Parcel.java:2437)
at android.os.Parcel.createException(Parcel.java:2421)
at android.os.Parcel.readException(Parcel.java:2404)
at android.os.Parcel.readException(Parcel.java:2346)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2878)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1743)
at android.app.Activity.startActivityForResult(Activity.java:5465)
at android.app.Activity.startActivityForResult(Activity.java:5423)
at android.app.Activity.startActivity(Activity.java:5809)
at android.app.Activity.startActivity(Activity.java:5762)
at uk.co.yahoo.p1rpp.secondsclock.SettingsActivity$25.onClick(SettingsActivity.java:538)
...
Here is the first bit of my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.yahoo.p1rpp.secondsclock">
<uses-permission android:name="android.permission.SET_ALARM" />
...
I'm actually asking for the permission even though I shouldn't need it since I'm asking to look at the alarms, not to set one. Without the permission request in the manifest, it still works on the emulator and fails in the same way on the phone.
I see the same behaviour (on both the emulator and the phone) with both debug and release builds.
In case someone asks why I'm doing this, I've written a home screen seconds clock widget, which will be published on github when I have it fully working. I want clicking on the widget to go to the system's clock app, which doesn't work because of this problem. The code shown is test code to check why the code in the widget fails, because the widget code executes in the context of the home screen launcher and is harder to debug.
I can go to the system clock app by using an Intent with its ComponentName (and this works without an error on the phone), but different Android phone models have different clock apps with different Componentnames, so it will only work on one type of phone. I did have code to search the PackageManager for the ComponentName of a clock, but Google's latest security upgrade in API 31 doesn't allow me to do that any more.
Why is the SecurityException happening and what if anything can I do to prevent it?
Why is the SecurityException happening
Samsung apparently has an android:permission attribute for that <activity> requiring that callers need to hold that permission to be able to start that activity.
what if anything can I do to prevent it?
You cannot prevent it. Samsung requires that permission, either intentionally or due to some screwup. You either need to hold the permission or you need to wrap the startActivity() call in a try/catch and "gracefully degrade" if you get that exception.
It does not required the permission that you have mentioned above rather it requires a different permission.
Replace this
<uses-permission android:name="android.permission.SET_ALARM" />
With
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

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 bluetooth permission denial (although I use permissions)

To cut the story short. My logcat says:
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE
cmp=com.android.settings/.bluetooth.RequestPermissionActivity (has
extras) }
While I'm trying to execute:
Intent discoverIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 600);
startActivity(discoverIntent);
I have included all required permissions in the manifest. Moreover, some time ago I have written another application using bluetooth, which includes exactly this code (and I'm using the same there permissions). In that app everything works properly, here I get this exception while executing startingActivity(discoverIntent).
Do you have any ideas what's going on?
ANSWER ANSWER ANSWER
Maybe it sounds silly, but after restarting(sic!) my mobile phone, everything works perfect and I don't get any exceptions. If you have problem like this, try this simple solution.

android.provider.Settings.ACTION_BLUETOOTH_SETTINGS crashes on Samsung

Anybody have any idea why
Intent pairIntent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivityForResult(pairIntent, 0);
Crashes on all Samsung devices, but works fine on emulator, HTC, Sony, LG etc.
EDITED -----------------------------------
Turns out Samsung also requires BLUETOOTH_ADMIN in the manifest
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
If you have an app in production, you need to have something that will allow you to get crash logs. That could be the default stuff that you get from shipping through the Play Store, or an open source solution like ACRA, or any number of service providers.
With regards to your crash, there is no guarantee that this activity is available. Quoting the documentation:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
The "safeguard" could be wrapping your startActivity() call in an exception handler, watching for ActivityNotFoundException.
Also, please note that you use startActivity(), not startActivityForResult(), with this Intent action. Again, quoting the documentation:
Output: Nothing.
This means that there is no result, and using startActivityForResult() is a waste of time.

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