三星Galaxy S3相机意图景观

时间:2013-08-21 02:08:21

标签: java android galaxy android-camera-intent

我已经搜索了2天试图找到问题的答案并且没有找到满意的答案。

我正在创建一个调用相机Intent的应用程序,基本上拍下照片,将其放入ImageView进行预览,然后我有一个按钮将文件保存到我创建的app文件夹中的用户定义文件夹中。

我可以很容易地使用AVD,我的GF的Droid Razr M来运行我的应用程序。但是当我尝试在我的GS3上运行它时,它在图像上接受接受后死亡可怕,除非我强迫应用程序进入景观清单中的模式,并在我拍照时将手机保持在风景中。我认为它与我所看到的onActivityResult数据输入为null有关,因为我得到一个空指针异常,就像它们一样。我正在寻找一个特定于我的问题的解决方案。

我的相机意图:

        if (v.getId() == R.id.snap) {
        //start camera up, and set temp file to store image for viewing inside the app
        String identity =  android.os.Build.MANUFACTURER;
        Intent intent1,cameraIntent;
        File f = new File(Environment.getExternalStorageDirectory(), "photo1.jpg");
        try {
        if (identity.equalsIgnoreCase("samsung")) {

            intent1 = new Intent("android.media.action.IMAGE_CAPTURE");
            Toast.makeText(getApplicationContext(), identity, Toast.LENGTH_LONG).show();

            //File f = new File(Environment.getExternalStorageDirectory(), "photo1.jpg");
            mUri=Uri.fromFile(f);
            intent1.putExtra(MediaStore.EXTRA_OUTPUT, mUri);
            startActivityForResult(intent1, TAKE_PICTURE);
            }
        else {
            cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
            Toast.makeText(getApplicationContext(), identity, Toast.LENGTH_LONG).show();

            //File f = new File(Environment.getExternalStorageDirectory(), "photo1.jpg");
            mUri=Uri.fromFile(f);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUri);

            startActivityForResult(cameraIntent, TAKE_PICTURE);
            }

我知道我真的没有制造商的一部分,但如果我必须实施三星特定的修复,那么框架就在那里。

我的保存栏:

else if (v.getId() == R.id.save){
        //store photo in a bitmap, and set string to make folder to store photos later on
        Bitmap bitmap = mPhoto;
        String root = Environment.getExternalStorageDirectory().toString();
        File newDir;

        if (value.isEmpty())
            newDir = new File(root + "/CamExample/default_folder");

        else
            newDir = new File(root + "/" + "CamExample/" + value);

        //if the chosen directory doesn't exist
        if (!newDir.exists()) {
            newDir.mkdirs();
            Toast.makeText(getApplicationContext(), "folder created successfully", Toast.LENGTH_SHORT).show();
        }

        //if it does exist
        else {
            Toast.makeText(getApplicationContext(), "directory already exists", Toast.LENGTH_SHORT).show();
        }

        //image naming convention to avoid duplicate images, should look like IMG_yyyMMdd_HHmmss.jpg
        String TIMESTAMP = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
        String photoname = "IMG_"+TIMESTAMP+".jpg";
        File file1=new File (newDir, photoname);

        if (file1.exists()) {
            file1.delete();
        }

        try {
            //actually create the jpeg file and put it in file1 in newDir
            FileOutputStream out = new FileOutputStream(file1);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
            out.flush();
            out.close();
            ((ImageView)findViewById(R.id.photo_holder)).setImageDrawable(null);
            mPhoto=null;

            Toast.makeText(getApplicationContext(), photoname+" has been saved properly", Toast.LENGTH_SHORT).show();
        }

        catch (Exception e) {
            Toast.makeText(getApplicationContext(), photoname+" has not saved properly", Toast.LENGTH_SHORT).show();
        }
    }

我的onActivityResult定义:

    public void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {

    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            getContentResolver().notifyChange(mUri, null);
            ContentResolver cr = getContentResolver();

            try {
                mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
                ((ImageView)findViewById(R.id.photo_holder)).setImageBitmap(mPhoto);
            }

            catch (Exception e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

这是我的logcat:

08-20 21:58:26.387: E/AndroidRuntime(10541): FATAL EXCEPTION: main
08-20 21:58:26.387: E/AndroidRuntime(10541): java.lang.RuntimeException: Unable to resume activity {com.example.camexample/com.example.camexample.Main}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity {com.example.camexample/com.example.camexample.Main}: java.lang.NullPointerException
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2639)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2667)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2140)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.access$800(ActivityThread.java:143)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.os.Looper.loop(Looper.java:137)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.main(ActivityThread.java:4950)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at java.lang.reflect.Method.invokeNative(Native Method)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at java.lang.reflect.Method.invoke(Method.java:511)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at dalvik.system.NativeStart.main(Native Method)
08-20 21:58:26.387: E/AndroidRuntime(10541): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity {com.example.camexample/com.example.camexample.Main}: java.lang.NullPointerException
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2626)
08-20 21:58:26.387: E/AndroidRuntime(10541):    ... 13 more
08-20 21:58:26.387: E/AndroidRuntime(10541): Caused by: java.lang.NullPointerException
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.os.Parcel.readException(Parcel.java:1431)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.os.Parcel.readException(Parcel.java:1379)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:452)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.content.ContentResolver.notifyChange(ContentResolver.java:1280)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.content.ContentResolver.notifyChange(ContentResolver.java:1259)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at com.example.camexample.Main.onActivityResult(Main.java:190)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.Activity.dispatchActivityResult(Activity.java:5363)
08-20 21:58:26.387: E/AndroidRuntime(10541):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
08-20 21:58:26.387: E/AndroidRuntime(10541):    ... 14 more

0 个答案:

没有答案