Android: how to register my app as a “camera app”

I was wondering how to tell android that my application is a camera application, so other applications know that they can run my application to get a snapshot. For example. with pixlr-o-matic, you can either select an image from the gallery or request it from the camera application of your choice.

edit: how to return the image to the calling application?

+7
source share
2 answers

This is done using 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 correct 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 built-in android website Camera source code .

+11
source

You must specify an Intent filter for your activity, which will indicate that your application can be launched 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!

+3
source

All Articles