[java] view plaincopyprint
01final String start = EnvironmentgetExternalStorageState();
02private static final String PHOTOPATH = "/photo/";
03
04if(startequals(EnvironmentMEDIA_MOUNTED)){
05Intent intent = new Intent(MediaStoreACTION_IMAGE_CAPTURE);
06File file = new File(EnvironmentgetExternalStorageDirectory()+PHOTOPATH);
07if(!fileexists()){
08filemkdirs();
09}
10tempphontname = SystemcurrentTimeMillis()+"jpg";
11bufferappend(EnvironmentgetExternalStorageDirectory()+PHOTOPATH)append(tempphontname);
12intentputExtra(MediaStoreEXTRA_OUTPUT, UrifromFile(new File(buffertoString())));
13startActivityForResult(intent, 1);
14}
final String start = EnvironmentgetExternalStorageState();
private static final String PHOTOPATH = "/photo/";
if(startequals(EnvironmentMEDIA_MOUNTED)){
Intent intent = new Intent(MediaStoreACTION_IMAGE_CAPTURE);
File file = new File(EnvironmentgetExternalStorageDirectory()+PHOTOPATH);
if(!fileexists()){
filemkdirs();
}
tempphontname = SystemcurrentTimeMillis()+"jpg";
bufferappend(EnvironmentgetExternalStorageDirectory()+PHOTOPATH)append(tempphontname);
intentputExtra(MediaStoreEXTRA_OUTPUT, UrifromFile(new File(buffertoString())));
startActivityForResult(intent, 1);
}
其次是从本地相册选:依旧是Intent
如下代码:
[java] view plaincopyprint
01if(startequals(EnvironmentMEDIA_MOUNTED)){
02 Intent getImage = new Intent(IntentACTION_GET_CONTENT);
03 getImageaddCategory(IntentCATEGORY_OPENABLE);
04 getImagesetType("image/jpeg");
05 startActivityForResult(getImage, 0);
06}
if(startequals(EnvironmentMEDIA_MOUNTED)){
Intent getImage = new Intent(IntentACTION_GET_CONTENT);
getImageaddCategory(IntentCATEGORY_OPENABLE);
getImagesetType("image/jpeg");
startActivityForResult(getImage, 0);
}
接下来是主要的:因为调用完系统的方法后,回返回到回调方法onActivityResult(int, int, Intent)中,
在里面进行主要的照片上传服务器的 *** 作,
见代码:
[java] view plaincopyprint
01@Override
02 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
03 ContentResolver resolver = getContentResolver();
04 if(requestCode==1)//
05 {
06 if(resultCode==ActivityRESULT_OK)
07 {
08 if(EnvironmentgetExternalStorageState()equals(EnvironmentMEDIA_MOUNTED))
09 {
10ew Thread(new Runnable()
11 {
12 @Override
13 public void run() {
14//进行上传 *** 作
15}
16}start();
转载
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)