douqian1296 2015-09-06 13:16
浏览 50

如何从intent动态命名图像文件

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();
                    }
                }
           }
  • 写回答

1条回答 默认 最新

  • dsyrdwdbo47282676 2015-09-06 14:53
    关注

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

    See java documentation

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)