我的活动中有3个按钮和一个切换按钮。切换时,按钮应打开相机以捕获图像或提示从图库中选择一个图像并保存'它。未切换时,按钮应显示用于在主ImageView中拍摄的图像。
三个按钮:
//buttons 1,2,3 are the same
Button button1 = (Button) findViewById(R.id.some_button);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(toggled == true){
takePictureIntent();
}
else {
//display the picture
}
}
});
我的相机/图库代码来自在线教程/论坛:
private void takePictureIntent() {
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
cameraIntents.add(intent);
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
startActivityForResult(chooserIntent, 1);
//}
}
有人可以指导我如何按下按钮&#34;记住&#34;通过它拍摄的照片,当切换关闭时,它会显示它吗?
我一直试图解决这个问题几个小时,感谢任何帮助。