我必须从相机应用程序中拍照并将其发送到邮件中。
我的问题是当我从相机应用程序中拍摄照片时,它不会将其保存到图库中。当我使用函数 getlastimageid(它获取相机拍摄的最后一张图像的地址)时,它会获取未拍摄图像的地址通过我的相机应用程序,但它需要相机最后拍摄的图像的 id。注意:在三星手机中它可以正常工作,即照片自动保存到画廊,但不能在其他中。
我的代码是
public class CameraProject extends Activity {
Button button;
Bitmap btm;
Bitmap thumbnail;
String filePath;
File pic;
final static int CameraData = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_project);
button = (Button) findViewById(R.id.cont);
}
//start camera activity
public void camera(View v) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CameraData);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
btm = (Bitmap) extras.get("data");
}
if(resultCode == RESULT_OK)
{
//it moves to another activity
Intent intent1=new Intent (CameraProject.this,INF.class);
startActivity(intent1);
}
else {
//if discard it reopen camera activity
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CameraData);
}
}
public void exit(View v)
{
finish();
}
}
我用来获取相机拍摄的最后一张照片的imageid的功能是:
private int getLastImageId(){
final String[] imageColumns = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA };
final String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);
if(imageCursor.moveToFirst()){
int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
fullPath = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
Log.d(TAG, "getLastImageId::id " + id);
Log.d(TAG, "getLastImageId::path " + fullPath);
imageCursor.close();
return id;
}else{
return 0;
}
}