package com.cn.ffff;
import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class FfffActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
LinearLayout l = new LinearLayout(this);
Button btn = new Button(this);
btn.setWidth(80);
btn.setHeight(30);
btn.setText("点击进入图库");
l.addView(btn);
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 1);
}
});
imageview = new ImageView(this);
l.addView(imageview);
setContentView(l);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
ContentResolver cr = this.getContentResolver();
try{
Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
imageview.setImageBitmap(bitmap);
}catch(FileNotFoundException e){
e.printStackTrace();
}
}
}
}
import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class FfffActivity extends Activity {
/** Called when the activity is first created. */
ImageView imageview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
LinearLayout l = new LinearLayout(this);
Button btn = new Button(this);
btn.setWidth(80);
btn.setHeight(30);
btn.setText("点击进入图库");
l.addView(btn);
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 1);
}
});
imageview = new ImageView(this);
l.addView(imageview);
setContentView(l);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
ContentResolver cr = this.getContentResolver();
try{
Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
imageview.setImageBitmap(bitmap);
}catch(FileNotFoundException e){
e.printStackTrace();
}
}
}
}