本文主要是介绍重命名照片后修改android相册表的数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
final EditText mm=new EditText(mContext);mm.setText(((ImageEntity)data.get(position)).getTitle().toString());
new AlertDialog.Builder(mContext).setTitle("请输入文件名!").setIcon(
android.R.drawable.ic_dialog_info).setView(
mm).setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
String path=((ImageEntity)data.get(position)).getFilePath();
File m=new File(path);
if(m.exists()){
StringBuffer buffer=new StringBuffer(path);
StringBuffer newpath=buffer.replace(path.lastIndexOf("/")+1,path.lastIndexOf("."),mm.getText().toString());
Log.e(buffer.toString(), newpath.toString());
try{
Boolean flag=m.renameTo(new File(newpath.toString()));
if(flag==true){
((ImageEntity)data.get(position)).setTitle(mm.getText().toString());
mvedioname.setText(((ImageEntity)data.get(position)).getTitle());
((ImageEntity)data.get(position)).setFilePath(newpath.toString());
// 更新ID为重名命的记录
Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ( (ImageEntity)data.get(position)).getID());
ContentValues values = new ContentValues();
// 修改重命名后的值
values.put(MediaStore.Images.Media.TITLE, mm.getText().toString());
values.put(MediaStore.Images.Media.DATA, newpath.toString());
// 获得ContentResolver,并更新
mContext.getContentResolver().update(uri, values, null, null);
Toast.makeText(mContext, "命名成功!", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mContext, "名字重复啦,请重命名!", Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
Toast.makeText(mContext, "名字重复啦,请重命名!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
})
.setNegativeButton("取消", null).show();
}
});
这篇关于重命名照片后修改android相册表的数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!