我想知道如何告诉android我的应用程序是一个相机应用程序,这样其他应用程序就知道他们可以启动我的应用程序来获取照片。例如,使用pixlr-o-马季奇,您可以从图库中选择图像,也可以从您选择的相机应用程序中请求图像。
编辑:如何将图片返回给调用app?
发布于 2011-12-19 04:40:07
这是通过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));
}你也可以查看android内置的Camera app source code。
发布于 2011-12-19 04:39:45
你应该为你的活动指定一个意图过滤器,它将指定你的应用程序可以启动来拍照。
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>希望这能有所帮助!
https://stackoverflow.com/questions/8554600
复制相似问题