![Select Image using Android build-in Gallery Select Image using Android build-in Gallery](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXBZVPwaDkxxb52iYPJEl-Yzms_Vfn9Ug66PLZMJYY4L71LP8qTXa5EtsTr-uxvzNo3rrXyjnRJhqPikU1hUVbvYqdEuxtRRi1hGoM7Crz60sef20gd3qxU-cJKNWHdpLqJKaL33bjxJUu/s400/AndroidSelectImage_01.png)
Here is a example:
package com.exercise.AndroidSelectImage;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class AndroidSelectImage extends Activity {
TextView textTargetUri;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonLoadImage = (Button)findViewById(R.id.loadimage);
textTargetUri = (TextView)findViewById(R.id.targeturi);
buttonLoadImage.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
textTargetUri.setText(targetUri.toString());
}
}
}
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:id="@+id/loadimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load Image"
/>
android:id="@+id/targeturi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
![download files download files](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp-WVdVRNoSSItrVOTvl2X9CE0zg_poZkG2QR80L1lOV_t9fi4v9to6WR4WzEi5c3VfhqlH-gQHma-08CHP-Fl3WF3LkFYYfR_d_bIyKuI_wKRIX6jR6qiRpd986VnCkTyUwPToGeHyad9/s200/icons_download.gif)
next:
- Display Gallery selected image using BitmapFactory
related:
- Send email with Image by starting activity using Intent of ACTION_SEND
- Convert Uri return from Gallery to file path
- Convert between Uri and file path, and load Bitmap from.
0 تعليقات