Điều này được thực hiện với bộ lọc ý định. Thêm thẻ sau đây vào tệp kê khai của bạn:
<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>
Bây giờ ứng dụng của bạn sẽ xuất hiện trong danh sách khi người dùng muốn chụp ảnh.
EDIT:
Đây là cách thích hợp để trở lại một 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));
}
Bạn cũng có thể kiểm tra android built-in Camera app source code.
xin lỗi, đã quên mất điều gì đó- tôi vừa chỉnh sửa câu hỏi – stoefln
Tôi đã chỉnh sửa câu trả lời của mình. – Dalmas
Không có vấn đề gì với việc đưa hình ảnh lớn vào phần Extras? Nó sẽ không tốt hơn để trả lại đường dẫn đến hình ảnh? – stoefln