1

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();
                    }
                }
           }
Community
  • 1
  • 1
Moudiz
  • 7,211
  • 22
  • 78
  • 156

1 Answers1

0

You can get the filename now using photo.getName() as that is a File object.

See java documentation

Victory
  • 5,811
  • 2
  • 26
  • 45
  • I am sorry I edit it , the `File` String filePath1 = null; File photo = new File(filePath1); is causing error nullexception. I dont know why – Moudiz Sep 06 '15 at 14:58