我有两项活动(A1,A2).A1调用A2,从A2调用相机意图,如下所示
launchIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
launchIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoPath);
startActivityForResult(launchIntent,CAMERA_REQUEST);
Run Code Online (Sandbox Code Playgroud)
它打开相机,我可以拍照.但是当我点击保存按钮(s3中的勾选按钮)时出现问题,我的onActivityResult没有被调用,而是调用了A2的onDestroy方法.我在onActivityResult fn中完成的逻辑很少.
我已经阅读了Stackoverflow中的一些关于此的帖子,但我无法从中得到有用的输出.我的第二个活动(A2)有我的清单
android:configChanges="keyboardHidden|orientation|locale"
android:screenOrientation="portrait
Run Code Online (Sandbox Code Playgroud)
注意:在HTC One X中我的onActivityResult fn被调用,但在我的S3中,第二个Activity(A2)被破坏了
Plz分享你对此的想法.提前致谢
我有两个选项"选择照片"和"拍照" - 我的选择照片功能完全正常,但拍照时出现问题.主要是保存的图像在保存后显示在图像视图中.
定义了我的照片位置:
public class photoActivity extends Activity {
private String photoPath;
private ImageView imgView;
{...}
Run Code Online (Sandbox Code Playgroud)
我的相机听众:
bPicFromCam.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
long captureTime = System.currentTimeMillis();
photoPath = Environment.getExternalStorageDirectory() + "/MYAPP" + captureTime + ".jpg";
getPicFromCam(v);
}
else{
Toast.makeText(getApplicationContext(),
"Sorry there is a problem accessing your SDCard, " +
"please select a picture from your gallery instead.", Toast.LENGTH_LONG).show();
}
}
});
Run Code Online (Sandbox Code Playgroud)
然后我的代码启动相机意图(注意photoPath是正确的):
public void getPicFromCam(View view){
System.out.println("photoPath: " + …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我想从中选择图像Gallery并设置图像ListView.在我的ListView I have 16 rows. So when ever item click inListView open the gallery and set the image toListView中,. But my problem is some times afterstartActivityForResult(),oncreate()`方法被调用.这是onclick代码
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, "Select File"),
SELECT_PICTURE);
Run Code Online (Sandbox Code Playgroud)
这是一个非常活跃的结果
public void onActivityResult(int requestcode, int resultcode, Intent data) {
Log.e("result", "result");
displayMetrics = this.getResources().getDisplayMetrics();
Ew = displayMetrics.widthPixels;
Eh = displayMetrics.heightPixels;
switch (requestcode) {
case SELECT_PICTURE:
if (resultcode == RESULT_OK) { …Run Code Online (Sandbox Code Playgroud) 我有下一个问题:
当我尝试启动相机时,我可以拍摄照片,甚至将其保存在sdcard上,但是当我准备在设备上显示该照片的路径时,会出现错误。
我的全局变量为2(我使用了1,但最好使用2来确保这是一个奇怪的错误):
private File photofile;
private Uri mMakePhotoUri;
Run Code Online (Sandbox Code Playgroud)
这是我的入门相机功能:
@SuppressLint("SimpleDateFormat")
public void farefoto(int num){
// For naming the picture
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String n = sdf.format(new Date());
String fotoname = "Immagine-"+ n +".jpg";
//Going through files and folders
File photostorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File photostorage2 = new File(photostorage, "Immagini");
System.out.println(photostorage+"\n"+photostorage2);
photostorage2.mkdirs();
// My file (global)
photofile = new File(photostorage2, fotoname);
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //intent to start camera
// My URI (global)
mMakePhotoUri = Uri.fromFile(photofile);
new Bundle(); …Run Code Online (Sandbox Code Playgroud) variables android global nullpointerexception android-camera-intent