I was wondering how to tell android that my app is a camera app, so other apps know that they can start my app to get a picture. E.g. with pixlr-o-matic you can either select an image from the gallery or you can request it from a camera app of your choice.
edit: how do i return the picture to the calling app?
Follow these steps to create an application that starts the camera in Android. I have included the source code below. Step 1 Open Android Studio and start a new Android Studio Project. You can choose your application name and choose where your project is stored on the location.
First go in your endpoint under Apps -> Android -> click Add+ -> App Type "Android Enterprise system app" and create e. g. your native Samsung camera app, with the corresponding package name (com.sec.android.app.camera). Then just assign this app to a group you created which includes the specific device.
On devices running Android 2.3 (API Level 9) or higher, you can access specific cameras using Camera.open (int). The example code above will access the first, back-facing camera on a device with more than one camera.
The requirement for Android App Development Android Studio ( Download Android Studio ). Step 1. Open Android Studio. Go to File >> New >> New Project. Specify your project name and the location where you want to save your project. Click on Next. Select the API levels. The above picture shows that my app's name is My Application, by default.
This is done with intent-filters. Add the following tag to your manifest :
<activity android:name=".CameraActivity" android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now your application will appear in the list when the user wants to take a picture.
EDIT :
Here is the proper way to return a bitmap :
Uri saveUri = (Uri) getIntent().getExtras().getParcelable(MediaStore.EXTRA_OUTPUT);
if (saveUri != null)
{
// Save the bitmap to the specified URI (use a try/catch block)
outputStream = getContentResolver().openOutputStream(saveUri);
outputStream.write(data); // write your bitmap here
outputStream.close();
setResult(RESULT_OK);
}
else
{
// If the intent doesn't contain an URI, send the bitmap as a Parcelable
// (it is a good idea to reduce its size to ~50k pixels before)
setResult(RESULT_OK, new Intent("inline-data").putExtra("data", bitmap));
}
You can also check the android built-in Camera app source code.
You should specify an Intent filter to your Activity, that will specify that your app can be started to take a picture.
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With