我想知道如何告诉android我的应用程序是一个相机应用程序,所以其他应用程序知道他们可以启动我的应用程序来获取图片。 例如使用pixlr-o-matic,您可以从图库中选择图像,也可以从您选择的相机应用程序请求。android:如何注册我的应用程序为“相机应用程序”
编辑: 如何将图片返回到调用应用程序?
我想知道如何告诉android我的应用程序是一个相机应用程序,所以其他应用程序知道他们可以启动我的应用程序来获取图片。 例如使用pixlr-o-matic,您可以从图库中选择图像,也可以从您选择的相机应用程序请求。android:如何注册我的应用程序为“相机应用程序”
编辑: 如何将图片返回到调用应用程序?
这是用intent-filters完成的。下面的代码添加到您的清单:
<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>
现在,当用户想要拍摄照片应用程序将出现在列表中。
编辑:
这里是返回一个位图的正确方法:
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));
}
您还可以检查内置Camera app source code的机器人。
您应该为您的活动指定一个Intent过滤器,这将指定您的应用可以开始拍照。
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
希望这有助于!
它对你有帮助吗? – 2011-12-19 15:33:54
抱歉,忘记了某些事项 - 我刚刚编辑了问题 – stoefln 2011-12-19 16:58:47
抱歉,忘记了某些事项 - 我刚刚编辑了问题 – stoefln 2011-12-19 16:58:55
我编辑了我的答案。 – Dalmas 2011-12-19 17:12:57
将大图放入Extras时没有问题吗?将路径返回到图像不是更好吗? – stoefln 2011-12-20 08:30:33