Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...