2014-01-15 44 views
1

我在所有屏幕底部使用了選項卡,並且我使用onactivityresult()方法從圖庫和camera.my代碼中選擇圖像,但沒有選項卡活動。但是當我使用我的代碼時,Tabactivity不起作用。,我2天尋找,但沒有解決不饒人,我做什麼..,我所以從這個frusted,請幫助我..,thankyou.here是onactivityresult()方法:android如何通過tabhost活動調用onactivityResult?

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch (requestCode) { 
    case 1: 
     if (resultCode ==RESULT_OK) 
     { 
      Uri chosenImageUri = data.getData(); 
      String imagepath= getpath(chosenImageUri); 
      Bitmap bitmap = BitmapFactory.decodeFile(imagepath); 
      customImageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false)); 
      Constant._profilePicBase64=Constant.convertBitmapToBase64(bitmap); 
      getprofilepic(); 

     }else{ 
      Toast.makeText(SettingsActivity.this, "Unable to get Image", Toast.LENGTH_SHORT).show(); 
     } 
     break; 
    case 2: 
     if (resultCode ==RESULT_OK) 
     { 
      try{ 
       Bitmap bitmap = (Bitmap) data.getExtras().get("data"); 
       customImageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false)); 

       Constant._profilePicBase64=Constant.convertBitmapToBase64(bitmap); 
       getprofilepic(); 

      }catch (OutOfMemoryError e) { 
       e.printStackTrace(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     }else{ 
      Toast.makeText(SettingsActivity.this, "Unable to get Image", Toast.LENGTH_SHORT).show(); 
     } 
     break; 
    } 
} 

回答

1

我可能會遲到,但無論如何這就是答案:

您的onActivityResult應放在TabActivity組

與你的startActivityForResult應該叫指父活動

例如:

TabActivityGroup parentActivity = (TabActivityGroup) getParent(); 
Intent gallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 

parentActivity.startActivityForResult(gallery, IMAGE_PICKER_REQUEST); 
+0

thnaku..but我有解決方案... :) – rajshree

+0

那麼,爲什麼不公佈它,而不是:1.解答未回答的問題和2.不接受@ beginner1答案? – momo

相關問題