android:如何将我的应用注册为“相机应用" [英] android: how to register my app as "camera app"

查看:55
本文介绍了android:如何将我的应用注册为“相机应用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何告诉android我的应用程序是相机应用程序,因此其他应用程序知道它们可以启动我的应用程序来获取图片.例如.使用pixlr-o-matic,您可以从图库中选择图像,也可以从您选择的相机应用程序中请求图像.

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?

推荐答案

这是通过意图过滤器完成的.将以下标签添加到清单中:

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.

这是返回位图的正确方法:

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));
}

您还可以检查android内置的

You can also check the android built-in Camera app source code.

这篇关于android:如何将我的应用注册为“相机应用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆