Tôi đã tạo một trình chọn để chọn một hình ảnh từ tệp hoặc để tạo hình ảnh.Trình chọn với mục đích máy ảnh và ý định của trình chọn hình ảnh
Mã tôi sử dụng hoạt động tốt trên Nexus 5, tuy nhiên khi tôi thử trên Samsung S5, trình chọn không hiển thị biểu tượng máy ảnh.
public Intent makePhotoIntent(String title, Context ctx, String uniqueImageId){
//Build galleryIntent
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
//Create chooser
Intent chooser = Intent.createChooser(galleryIntent,title);
if (checkexCameraHardware()){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mTempImage = null;
try {
mTempImage = createImageFile(uniqueImageId);
} catch (IOException e) {
e.printStackTrace();
}
if (mTempImage != null){
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempImage)); //add file ure (photo is saved here)
Intent[] extraIntents = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
}
}
return chooser;
}
Khi tôi thay đổi thứ tự trong đó ý đồ được thêm vào tính năng chọn thiết bị Samsung không hiển thị camera nhưng chỉ cho thấy android-hệ thống như tùy chọn tập tin.
public Intent makePhotoIntent(String title, Context ctx, String uniqueImageId){
//Build galleryIntent
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
//Create chooser
Intent chooser = Intent.createChooser(galleryIntent,title);
if (checkexCameraHardware()){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mTempImage = null;
try {
mTempImage = createImageFile(uniqueImageId);
} catch (IOException e) {
e.printStackTrace();
}
if (mTempImage != null){
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempImage)); //add file ure (photo is saved here)
//I have to re-create the chooser here or the Samsung will not show the 'camera' icons.
//I have to add the cameraIntent first.
chooser = Intent.createChooser(cameraIntent,title);
Intent[] extraIntents = {galleryIntent};
//Intent[] extraIntents = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
}
}
return chooser;
}
Lý tưởng nhất là tôi muốn các thiết bị Samsung để hiển thị giống như Nexus một khi tôi thêm mục đích sưu tập đầu tiên. Tuy nhiên tôi có thể không nhận được điều này để làm việc.
mà samsung thiết bị bạn sử dụng – Lokesh