【问题标题】:Download files always hiddens下载文件总是隐藏
【发布时间】:2016-06-24 21:11:04
【问题描述】:

我正在使用一个应用程序,我正在将文件上传到服务器,例如 png、pdf、jpeg。当我尝试打开文件管理器并打开下载文件夹然后显示的文件被隐藏时,我无法选择这些文件。

下面是代码:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/png,image/jpeg,application/pdf,text/plain");
this.startActivityForResult(intent, FILE_SELECT_CODE);

我该如何解决这个问题,以便我可以从我的手机中的任何地方选择文件。

【问题讨论】:

  • 给出你的多部分请求代码,可能是服务器端有问题。
  • 这里是a link!我想你会在这里找到答案。
  • 为什么在将文件上传到服务器后查看下载文件夹?什么原因?
  • 我认为我的请求没有任何问题,因为我无法从下载文件夹中选择图像,因为我的请求正在从图库中选择文件。
  • @greenapps 用户可以从任何地方上传任何文件,可以是下载文件夹,也可以是图库等。

标签: android file download upload


【解决方案1】:
Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    Log.e("RegisterACtivity", "OpenGallery");
    startActivityForResult(i, 1);

我正在使用此代码,它对我来说工作正常。但是如果您的下载文件夹中有图像,它会打开图库,它肯定会显示给您。

下面是获取结果并在图像视图上设置该路径的代码。我首先在图像视图上设置它。您可以通过将路径转换为字节数组来上传图片

protected void onActivityResult(int requestCode, int resultCode,
        Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    Log.e("RegisterActivity", "" + requestCode + "...." + resultCode);
    switch (requestCode) {
    case 1:
        if (resultCode == RESULT_OK) {
            Uri _image = imageReturnedIntent.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(_image,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            imagePath = cursor.getString(columnIndex);
            cursor.close();
            Log.e("FilePath", imagePath);
            image.setImageBitmap(BitmapFactory.decodeFile(imagePath));
            /*
             * Bitmap bitmap = BitmapFactory.decodeFile(imagePath); Bitmap
             * resized = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
             * Bitmap conv_bm = getRoundedRectBitmap(resized, 200);
             * image.setImageBitmap(conv_bm);
             */

        }
    }
}

【讨论】:

  • 你说得对,但它并没有解决我的问题,因为我也想从下载中选择文件
猜你喜欢
  • 2010-09-28
  • 1970-01-01
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 2011-08-01
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
相关资源
最近更新 更多