am使用活動作爲對話框。在那裏我有按鈕來瀏覽並選擇圖像以在圖像視圖中顯示它。從SD卡中瀏覽圖像以在android的圖像視圖中顯示它?
我的對話活動代碼和瀏覽圖像
public class Update_profile extends Activity{
private Uri mImageCaptureUri;
private static final int PICK_FROM_FILE = 1;
private View rootView;
Button save,browse_image;
ImageView profile_pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(new ColorDrawable(0));
setContentView(R.layout.update_profile);
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
});
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
this.rootView=findViewById(R.id.update_profile_details);
profile_pic = (ImageView)findViewById(R.id.update_profile_picture);
save = (Button)findViewById(R.id.save);
browse_image = (Button)findViewById(R.id.browse_image);
browse_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
Bitmap bitmap = null;
String path = "";
if (requestCode == PICK_FROM_FILE) {
mImageCaptureUri = data.getData();
path = getRealPathFromURI(mImageCaptureUri); //from Gallery
Log.v("Path", ""+path);
if (path == null)
path = mImageCaptureUri.getPath(); //from File Manager
Log.v("Path", ""+path);
if (path != null)
bitmap = BitmapFactory.decodeFile(path);
} else {
path = mImageCaptureUri.getPath();
Log.v("Path", ""+path);
bitmap = BitmapFactory.decodeFile(path);
}
profile_pic.setImageBitmap(bitmap);
}
public String getRealPathFromURI(Uri contentUri) {
String [] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(contentUri, proj, null, null,null);
if (cursor == null) return null;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
@SuppressLint("NewApi")
@Override
public boolean onTouchEvent(MotionEvent event) {
Rect rect = new Rect();
rootView.getHitRect(rect);
if (!rect.contains((int)event.getX(), (int)event.getY())){
setFinishOnTouchOutside(false);
return true;
}
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
finish();
}
return true;
}
}
我的清單代碼。當我使用上述普通的活動方式瀏覽圖片的代碼更改活動作爲一個對話框
<activity
android:name="test.Update_profile"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog"
android:windowSoftInputMode="stateHidden" >
</activity>
它獲取的圖像,並在圖像視圖中顯示,但在這個對話框activity.its現在能夠選擇圖像。我想拍照從對話activity.am圖像不能夠解決這個問題。任何人都可以幫助我解決這個問題。
如果我給UA然後你可以在網格視圖中設置所有圖像,然後你也可以在點擊網格視圖元素時顯示你的圖像 –
@BhanuSharma我想要圖像的路徑。 – Yugesh
ohk看到我的答案我給你所有的細節文件路徑也哥們:) –