我一直在寻找周围这个问题的简单的解决方案,但还没有能够找到一个,所以这里有云:呼叫Intent.ACTION_PICK并返回到onActivityResult - 如何?
我有在它tabhost控制单个网页视图的应用程序。如果标签1之后我做的网页视图等一个JavaScript调用,这就是我如何控制这个简单的应用程序的内容。
现在我希望能够推出图像/视频库,并挑选一些媒体,但是这是导致我头疼。它启动了,但是当我选择一些媒体时,应用程序会立即关闭(没有强制关闭,只是消失)。
我已经把一个onActivityResult方法在我的应用程序,但它不会被调用,我不知道为什么。
这是我的一些代码(一切都在同一个活动课):
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Tab1", getResources().getDrawable(R.drawable.iphone)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Tab2", getResources().getDrawable(R.drawable.about)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Tab3", getResources().getDrawable(R.drawable.events)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Tab4", getResources().getDrawable(R.drawable.free)).setContent(R.id.webview));
mTabHost.addTab(mTabHost.newTabSpec("tab_test5").setIndicator("Tab5", getResources().getDrawable(R.drawable.video)).setContent(R.id.webview));
mTabHost.getCurrentView().setVisibility(View.VISIBLE);
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String arg0) {
if(mTabHost.getCurrentTab() == 0)
{
Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab());
side1(mWebView);
}
if(mTabHost.getCurrentTab() == 1)
{
Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab());
side2(mWebView);
}
if(mTabHost.getCurrentTab() == 2)
{
Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab());
side3(mWebView);
}
if(mTabHost.getCurrentTab() == 3)
{
Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab());
side4(mWebView);
}
if(mTabHost.getCurrentTab() == 4)
{
Log.i("***Selected Tab", "Im currently in tab with index::" + mTabHost.getCurrentTab());
side5(mWebView);
openStuff();
}
}
});
public void openStuff()
{
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
}
}
}
则应将您链if语句到交换机。 – JoxTraex