android获取路径怎么写

1.Android开发,图库获取图片路径public class TestCameraActivity extends Activity implements OnClickListener{ private Uri mOutPutFileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button takePiCButton = (Button) this.findViewById(R.id.button1);
takePiCButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
saveFullImage();
break;
default:
break;
}
}
private void saveFullImage(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//文件夹aaaa
String path = Environment.getExternalStorageDirectory().toString()+"/aaaa";
File path1 = new File(path);
if(!path1.exists()){
path1.mkdirs();
}
File file = new File(path1,System.currentTimeMillis()+".jpg");
mOutPutFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mOutPutFileUri);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1){
Uri imageUri = null;
if(data != null){
if(data.hasExtra("data")){
Bitmap thunbnail = data.getParcelableExtra("data");
//处理缩略图
}
}else{
//处理mOutPutFileUri中的完整图像
}
}
}
}
2.怎么获取指定手机存储相片的路径android首先是相册图片的获取:
private final String IMAGE_TYPE = "image/*";
private final int IMAGE_CODE = 0; //这里的IMAGE_CODE是自己任意定义的
//使用intent调用系统提供的相册功能 , 使用startActivityForResult是为了获取用户选择的图片
Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
getAlbum.setType(IMAGE_TYPE);
startActivityForResult(getAlbum, IMAGE_CODE);
//重写onActivityResult以获得你需要的信息
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode != RESULT_OK) { //此处的 RESULT_OK 是系统自定义得一个常量
Log.e(TAG,"ActivityResult resultCode error");
return;
}
Bitmap bm = null;
//外界的程序访问ContentProvider所提供数据 可以通过ContentResolver接口
ContentResolver resolver = getContentResolver();
//此处的用于判断接收的Activity是不是你想要的那个
if (requestCode == IMAGE_CODE) {
try {
Uri originalUri = data.getData(); //获得图片的uri
bm = MediaStore.Images.Media.getBitmap(resolver, originalUri); //显得到bitmap图片
这里开始的第二部分 , 获取图片的路径:
String[] proj = {MediaStore.Images.Media.DATA};
//好像是android多媒体数据库的封装接口 , 具体的看Android文档
Cursor cursor = managedQuery(originalUri, proj, null, null, null);
//按我个人理解 这个是获得用户选择的图片的索引值
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
//将光标移至开头  , 这个很重要 , 不小心很容易引起越界
cursor.moveToFirst();
//最后根据索引值获取图片路径
String path = cursor.getString(column_index);
}catch (IOException e) {
Log.e(TAG,e.toString());
}
}
}
3.android 调用相册的图片 图片无法找到 路径应该怎么写先引入Environment类 , 然后调用getExternalStorageDirectory()函数获得sd卡路径 , 然后连接在你的filename前面 , 应该就可以解决.
具体:
import android.os.Environment;
File f = new File(Environment.getExternalStorageDirectory() + fileName);