in this question explain how to get the name of an image
File f = new File(picturePath);
String imageName = f.getName();
however I am getting the image as an intent , how to get the name of it ?
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
another sub question.
I am uploading an image from gallery to server, so I though the name of the image uploaded to the server should be the same founded in gallery adding date to it ? is there another way you advice for me ?
this is php that name the file its static now which is bad
$base=$_REQUEST['image'];
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploaded_images.jpg', 'wb');
fwrite($file, $binary);
edit
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
// startActivityForResult(
// Intent.createChooser(intent, "Complete action using"),2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
//file name
filePath = data.getData();
try {
// Bundle extras2 = data.getExtras();
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
// imageview.setImageBitmap(bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte imageInByte[] = stream.toByteArray();
Intent i = new Intent(this,
AddImage.class);
i.putExtra("image", imageInByte);
startActivity(i);
} catch (IOException e) {
e.printStackTrace();
}
}
}