private static int photo_pick = 1;
/*
调用select picture,如果是想选择audio 则把 “image” 变为 “audio”
有关之类的技巧可以看 http://blog.csdn.net/chenzheng_java/article/details/6266135
*/
private void startSetBackGroundActivty(){
Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
innerIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
/*
此处返回到result是 图片在media的uri
*/
startActivityForResult(innerIntent, photo_pick);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 接收被调方 Activity 返回的数据
switch (resultCode) {
case RESULT_OK:
if(requestCode == photo_pick){
Uri uri = null;
uri = data.getData();
if(uri == null)
break;
Log.i(TAG,"RETURN VALUE "+uri);
ContentResolver resolver = null;
resolver = this.getContentResolver();
Media m = new Media();
Bitmap bm = null ;
try {
bm = m.getBitmap(resolver, uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mDraw = new BitmapDrawable(bm);
this.getWindow().setBackgroundDrawable(mDraw);
mDraw = null;
if(BACKGROUND_FILE.exists()){
BACKGROUND_FILE.delete();
}
try {
if(!mBackGroundDir.exists())
mBackGroundDir.mkdir();
BACKGROUND_FILE.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileInputStream fin = null;
try {
fin = (FileInputStream) resolver.openInputStream(uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(BACKGROUND_FILE);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Log.i(TAG,"-----------------------=== \n");
e.printStackTrace();
}
byte[] buffer = new byte[4096];
int ret = 0;
try {
while((ret = fin.read(buffer, 0, 4096)) > 0 ){
fos.write(buffer, 0, ret);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
*/
}
}