Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: how to register my app as "camera app"

Tags:

android

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?

like image 213
stoefln Avatar asked Dec 18 '11 20:12

stoefln


People also ask

How to create an application that starts the camera in Android?

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.

How do I add a camera app to a group?

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.

How do I access specific cameras on an Android 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.

How to create an Android app?

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.


2 Answers

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.

like image 159
Dalmas Avatar answered Oct 04 '22 21:10

Dalmas


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!

like image 42
Dimitris Makris Avatar answered Oct 04 '22 23:10

Dimitris Makris