本文介绍了请有意画面上失败三星Galaxy I9000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的codeS从我的应用程序启动相机:

I use the following codes to launch the camera from my app:

private void saveFullImage() {
    String storageState = Environment.getExternalStorageState();
    if (storageState.equals(Environment.MEDIA_MOUNTED)) {
        String path = Environment.getExternalStorageDirectory().getName()
                + File.separatorChar + "Android/data/"
                + RegistrationDetails.this.getPackageName() + "/files/"
                + md5("filedummy") + ".jpg";
        File photoFile = new File(path);
        try {
            if (photoFile.exists() == false) {
                photoFile.getParentFile().mkdirs();
                photoFile.createNewFile();
            }

        } catch (IOException e) {
            Log.e(TAG, "Could not create file.", e);
        }
        Log.i(TAG, path);

        Uri fileUri = Uri.fromFile(photoFile);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        startActivityForResult(intent, TAKE_PICTURE);
    } else {
        new AlertDialog.Builder(this)
                .setMessage(
                        "External Storeage (SD Card) is required.\n\nCurrent state: "
                                + storageState).setCancelable(true)
                .create().show();
    }
}

和我有以下的codeS里的onActivityResult表明该图像拍摄完毕,这样我就可以继续进行下一个步骤:

And I have the following codes in onActivityResult to show that the picture has been taken, so I can proceed the next step:

        } else if (requestCode == TAKE_PICTURE) {
            if (data == null) {
                Toast toast = Toast.makeText(getApplicationContext(),
                        "Take Picture finished", 10);
                toast.show();
            }

和我已经定义在AndroidManifest以下设置:android.permission.CAMERA和android.permission.WRITE_EXTERNAL_STORAG​​E

And I have defined the following settings in AndroidManifest: android.permission.CAMERA and android.permission.WRITE_EXTERNAL_STORAGE

推出相机意图的作品,但是当我做一个图片,然后点击保存,那么它不返回的onActivityResult和我的应用程序崩溃。

The launch Camera intent works, but when I make a picture and click on Save, then it does not return to onActivityResult and my app crashes.

有人可以帮助我?

感谢

推荐答案

我有一些问题的Galaxy S 2.3.4版本和摄像头。

I got some problems with Galaxy S version 2.3.4 and camera.

一些工作之后,它实际上与此code(银河S和Nexus S的测试)工作。
你可以尝试一下,我说,如果你的作品。

After a little work, it actually work with this code (tested with Galaxy S and Nexus S).You can try it and say me if it works for you.

private Uri mCapturedImageURI;


private void takePhoto() {
    String fileName = "temp.jpg";
    if (isGalaxyS()) {
        fileName = Repertoires_S.getInstance().Get_Photos_Path() + fileName;
        File fileTmp = new File(fileName);
        if (fileTmp.exists()) fileTmp.delete();
        mCapturedImageURI = Uri.fromFile(fileTmp);
    } else {
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION, "Image prise via XXX :)");  
        mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    }

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
    startActivityForResult(intent, PICK_FROM_CAMERA);
}


private boolean isGalaxyS() {
    Log.d("Photo", android.os.Build.BRAND + "/" + android.os.Build.PRODUCT + "/"
            + android.os.Build.DEVICE);

    ArrayList<String> devices = new ArrayList<String>();
    devices.add("samsung/GT-I9000/GT-I9000");

    return devices.contains(android.os.Build.BRAND + "/" + android.os.Build.PRODUCT + "/"
            + android.os.Build.DEVICE);
}


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;
    }

    switch (requestCode) {
        case PICK_FROM_CAMERA: {
            Bitmap photo = null;
            String filenameDest = Repertoires_S.getInstance().Get_Photos_Path() + DateTime_BO_S.getInstance().Date_Courante_AAAAMMJJ_HHMMSS() + ".jpg";
            File fDest = new File(filenameDest);
            String capturedImageFilePath;

            if (data == null) {
                // "intent.putExtra(MediaStore.EXTRA_OUTPUT, XXXX);" utilisé
                try {
                    if (isGalaxyS()) {
                        String fileName = "temp.jpg";
                        capturedImageFilePath = Repertoires_S.getInstance().Get_Photos_Path() + fileName;
                    } else {
                        String[] projection = {MediaStore.Images.Media.DATA}; 
                        Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
                        int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
                        cursor.moveToFirst(); 
                        capturedImageFilePath = cursor.getString(column_index_data);
                    }
                    File fSrc = new File(capturedImageFilePath);
                    fSrc.renameTo(fDest);
                    photo = BitmapFactory.decodeFile(filenameDest);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                // "intent.putExtra(MediaStore.EXTRA_OUTPUT, XXXX);" non utilisé -> miniature
                Bundle extras = data.getExtras();
                if (extras != null) {
                    photo = extras.getParcelable("data");
                }
            }

            if (photo != null) {
                try {
                    int tailleMaxPhoto = 800;
                    double rap;
                    int newWidth;
                    int newHeight;
                    if (photo.getWidth() > tailleMaxPhoto || photo.getHeight() > tailleMaxPhoto) {
                        // Si c'est plus grand on redimensionne
                        if (photo.getWidth() > photo.getHeight()) {
                            rap = (double)tailleMaxPhoto / photo.getWidth();
                            newWidth = tailleMaxPhoto;
                            newHeight = (int)((double)photo.getHeight() * rap);
                        } else {
                            rap = (double)tailleMaxPhoto / photo.getHeight();
                            newHeight = tailleMaxPhoto;
                            newWidth = (int)((double)photo.getWidth() * rap);
                        }
                        Bitmap photoSmall = Bitmap.createScaledBitmap(photo, newWidth, newHeight, true);
                        if (photoSmall != null) {
                            FileOutputStream out = new FileOutputStream(filenameDest);
                            if (photoSmall.compress(Bitmap.CompressFormat.JPEG, 90, out)) {
                                mPhotosPrat.add(filenameDest);
                                mPhotoAdapt.notifyDataSetChanged();
                            }
                        }
                    } else {
                        mPhotosPrat.add(filenameDest);
                        mPhotoAdapt.notifyDataSetChanged();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            break;
        }
    }
}

这篇关于请有意画面上失败三星Galaxy I9000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 08:30