2011-10-04 75 views
0

我很难从活动返回信息,我对实现的理解是不完整的。Android加载图库onclick,返回图像位图

我想要的是用户能够点击一个按钮来加载android画廊,选择一个图像,该图像(或图像链接也许)被转换为位图/绘制出现在我的活动UI布局。 (我知道为什么,画廊应用程序中没有任何意图 - 为了编辑我没有访问权限,但我不知道这是什么意思,但我不知道溶液)

ImageView galleryClick = (ImageView)findViewById(R.id.addgallery); 

    profilePic = (ImageView)findViewById(R.id.profilepic); 

    galleryClick.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
      intent.setType("image/*"); 

      startActivityForResult(Intent.createChooser(intent, "Select Picture"),1); 

     } 

    }); 

我希望是在onActivityFinished会在我的手写的活动被调用,但该方法是从来没有所谓的(我把一个断点在其代码

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

    if (resultCode == RESULT_OK) { 

     if (requestCode == 1) { 
      // currImageURI is the global variable I'm using to hold the content:// URI of the image 
      //currImageURI = data.getData(); 
     } 
    } 
} 

解决方案?

+0

断点不取决于你如何从IDE启动的应用程序始终尊重。在requestCode == 1块中抛出一条日志消息 - 是否显示? –

回答

1

如果我正确理解你的问题,我相信以前在堆栈溢出时会提出类似的问题。这里是一个我在想:

Get/pick an image from Android's built-in Gallery app programmatically

+0

但我的onActivityResult函数永远不会被调用。正如我所提到的那样,我在那里放置了一个断点,它永远不会在那里对图库中选择的内容做任何事情 – CQM

+0

尝试使用'startActivityForResult(Intent.createChooser(intent,“Select Picture”),-1);'而不是'startActivityForResult(Intent.createChooser(intent,“Select Picture”),1);' –

+0

这更贴近我的问题,http://stackoverflow.com/questions/2497205/how-to-return-a-result-startactivityforresult - 从-A-tabhost活动 – CQM