I am facing a peculiar issue where resolveActivity returns null. I know there are similar questions already and solutions are provided, but I am specifically facing the issue for android 14. I have added the queries for the intent in my manifest file. Yet the issue only persists for android 14 devices.
Here is a snippet of my manifest file
<uses-feature android:name="android.hardware.camera" android:required= "true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
android:icon="@drawable/logo"
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
<application
android:name=".model.Multi_Dex"
android:allowBackup="true"
android:hardwareAccelerated="false"
...
And here is the snippet for the method used to launch the camera intent.
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(Build.VERSION.SDK_INT>33){
takePictureIntent.setPackage(context.getPackageName());
}
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.ft.fifthwheel.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(takePictureIntent, REQUEST_CAMERA);
}
}
}
Okay, so I have currently resolved this by using the
queryIntentActivitiesmethod. I have fetched the list ofResolveInfoobjects, created a newIntentfor everyintentmentioned in my manifest file and added each intent to a list of intents. Then I created a chooser Intent to trigger a choice of options to pick my photo, currently, I am only allowing the camera option to take the photo, but I might add more intents inside myqueriesin the manifest file.Here is the sample code
I would appreciate better solutions or improvements if there are any.