我一直在尋找周圍這個問題的簡單的解決方案,但還沒有能夠找到一個,所以這裏有雲:呼叫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