Android 2.2 SDK - Droid X Camera Activity doesn't finish properly

前端 未结 2 1238
再見小時候
再見小時候 2021-01-16 15:22

I noticed the default camera activity I call on a Droid X is different looking than the one on my Droid and Nexus One. After selecting \"OK\" on the Droid and Nexus One, th

相关标签:
2条回答
  • 2021-01-16 15:29

    Dude... it's just a bug. I had the same problem and there's no way to workaround that. It sometimes work, and sometimes it does not. I asked the Motorola's guy for help and they said that there's no support for those Android images.

    0 讨论(0)
  • 2021-01-16 15:29

    I solved this with a really really ugly workaround. I coded two functions to read and write files from sdcard (taken from here: http://www.sgoliver.net/blog/?p=2035).

    private boolean readFile() {
        try
        {
            File sd_path = Environment.getExternalStorageDirectory();
    
            File f = new File(sd_path.getAbsolutePath(), "lock_camera_oncreate");
    
            BufferedReader fin =
                new BufferedReader(
                    new InputStreamReader(
                        new FileInputStream(f)));
    
            String text = fin.readLine();
            fin.close();
            Log.e("Files", "Reading file");
            return true;
        }
        catch (Exception ex)
        {
            Log.e("Files", "Error reading file from SD Card");
            return false;
        }
    }
    
    private void createFile() {
        try
        {
            File sd_path = Environment.getExternalStorageDirectory();
    
            File f = new File(sd_path.getAbsolutePath(), "lock_camera_oncreate");
    
            OutputStreamWriter fout =
                new OutputStreamWriter(
                    new FileOutputStream(f));
    
            fout.write("Semaphore test.");
            fout.close();
            Log.e("Files", "File writed");
        }
        catch (Exception ex)
        {
            Log.e("Files", "Error reading file from SD Card");
        }
    
    }
    

    Then, in onCreate function, I make this:

    public void onCreate(Bundle savedInstanceState) {
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        super.onCreate(savedInstanceState);
    
        if(readFile() == true)
        {
            File sd_path = Environment.getExternalStorageDirectory();
            File f = new File(sd_path.getAbsolutePath(), "lock_camera_oncreate");
            f.delete();
    
            Intent intent = this.getIntent();
            this.setResult(RESULT_OK, intent);
            return;
        }
    
        createFile();
    
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentImagePath)));
        startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
    }
    

    The setRequestedOrientation call solves the issue when you are using your app in portrait mode, but when camera is launched, you put the mobile in landscape and then shoot the photo.

    Then, the ugly readFile thing checks if a lock_camera_oncreate file exists and if it's true, then an additional onCreate call happened, so delete file and RETURN from this activity.

    If activity advances, means the file's not created and there is only one camera activity running.

    Hope it helps, it's ugly but worked for me :D

    0 讨论(0)
提交回复
热议问题