我想知道如何告诉android我的应用程序是一个相机应用程序,所以其他应用程序知道他们可以启动我的应用程序来获取图片.例如,使用pixlr-o-matic,您可以从图库中选择图像,也可以从您选择的相机应用程序中请求图像.
编辑:如何将图片返回到调用应用程序?
Dal*_*mas 11
这是通过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>
Run Code Online (Sandbox Code Playgroud)
现在,当用户想要拍照时,您的应用程序将出现在列表中.
编辑:
这是返回位图的正确方法:
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));
}
Run Code Online (Sandbox Code Playgroud)
您还可以查看android内置的Camera应用程序源代码.
| 归档时间: |
|
| 查看次数: |
2652 次 |
| 最近记录: |