相机意图问题,相机在没有请求的情况下启动

发布于 2024-11-11 18:04:26 字数 2132 浏览 4 评论 0原文

我的相机意图有点问题。据我所知,当相机方向改变时,活动将重新启动。好吧,我正在使用下面的代码。

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = (myApplication)getApplication(); 

    if(savedInstanceState ==null ) getFullImage(null);
    else{
        String somevalue = savedInstanceState.getString("uri");
        getFullImage(somevalue);
        }
}

private void getFullImage(String testValue)
{   if(testValue == null){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(Environment.getExternalStorageDirectory(), UUID.randomUUID()+ ".jpg");
    outputFile = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFile);
    startActivityForResult(intent, TAKE_PICTURE);

}else 
{   
    outputFile = null;
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(testValue);
    outputFile = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, testValue);
    startActivityForResult(intent, TAKE_PICTURE);
    finishFromChild(getParent());
}

捕获图片

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == RESULT_CANCELED) {
        Log.i(TAG, "Back Button"); 
        finishFromChild(this);
    } 
    else
     if(requestCode == TAKE_PICTURE && resultCode == RESULT_OK)
        {   
    //I'm creating new file here (for this question is irelevant)
        } catch (IOException e) {

            e.printStackTrace();
        }

        Intent myIntent = new Intent(getBaseContext(), com.test.activities.SaveFileActivity.class);
        myIntent.putExtra("image", newPath);
        startActivityFromChild(this, myIntent, SAVE_ITEM);  
        finishFromChild(this);
    }

后,

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("uri",outputFile.getPath());
}

我按“完成”按钮,然后转到“SaveFileActivity”。一切正常,直到我尝试从 SaveFIleActivity 转到另一个活动,然后相机再次启动。我应该去哪里寻找问题?也许我应该取消相机的意图,但是什么时候呢?

I have a little problem with my camera intent. As I know, when camera orientation is changed, activity is restarted. Okej, I am using the code bellow.

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = (myApplication)getApplication(); 

    if(savedInstanceState ==null ) getFullImage(null);
    else{
        String somevalue = savedInstanceState.getString("uri");
        getFullImage(somevalue);
        }
}

private void getFullImage(String testValue)
{   if(testValue == null){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(Environment.getExternalStorageDirectory(), UUID.randomUUID()+ ".jpg");
    outputFile = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFile);
    startActivityForResult(intent, TAKE_PICTURE);

}else 
{   
    outputFile = null;
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(testValue);
    outputFile = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, testValue);
    startActivityForResult(intent, TAKE_PICTURE);
    finishFromChild(getParent());
}

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == RESULT_CANCELED) {
        Log.i(TAG, "Back Button"); 
        finishFromChild(this);
    } 
    else
     if(requestCode == TAKE_PICTURE && resultCode == RESULT_OK)
        {   
    //I'm creating new file here (for this question is irelevant)
        } catch (IOException e) {

            e.printStackTrace();
        }

        Intent myIntent = new Intent(getBaseContext(), com.test.activities.SaveFileActivity.class);
        myIntent.putExtra("image", newPath);
        startActivityFromChild(this, myIntent, SAVE_ITEM);  
        finishFromChild(this);
    }

}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("uri",outputFile.getPath());
}

After picture is captured, I press DONE button and I go to SaveFileActivity. Everyting works fine, until I try from SaveFIleActivity to go to another activity, then camera is starting again. Where should I look for the problem ? Maybe I should kill camera intent, but when ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开柳相依 2024-11-18 18:04:26

我怀疑您想使用更简单的 startActivity()finish() 方法,而不是 startActivityFromChild()finishFromChild()。然而,我承认我有点不清楚你的这些东西到底有什么用。

I suspect you want to be using the simpler startActivity() and finish() methods instead of startActivityFromChild() and finishFromChild(). I admit, however, that I'm a bit unclear as to what the use of the ones you are actually for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文