从手机意图上传文件 [英] Upload files from phone intent

查看:75
本文介绍了从手机意图上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个android应用程序,在活动中,用户从手机的内存中选择一张图片,然后使用动作选择"意图将其上传到服务器上

Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RESULT_LOAD_IMAGE);

但是;现在要求已更改,并且客户希望上传具有任何扩展名的任何文件,为了打开手机的内存(例如文件管理器)并选择我想要的内容,我应该使用什么意图?

现在感谢大家,我正在使用获取内容"意图:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent, 1);

但是问题出在结果的开始活动中

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 1) {
            Log.d("select pivture", "passed her");
            Uri selectedMediaUri = data.getData();

            String Fpath = selectedMediaUri.getPath();

            Log.d("Fpath", Fpath);
}

我得到如下信息:

/document/primary:Download/tool208.pdf

这不是我想要的,我想要这样的路径:

/external/images/media/6634

解决方案

使用以下方法:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

更新

   @Override  
   protected void onActivityResult(int requestCode, int resultCode, Intent data)  
   {  
          super.onActivityResult(requestCode, resultCode, data);  
         if(requestCode==PICKFILE_REQUEST_CODE){  
         }  
 }  

I've an android application where in an activity the user chooses a picture from the phone's memory to upload it to the server using the Action Pick intent

Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RESULT_LOAD_IMAGE);

However; now the requirements has changed and the client wants to upload any file with any extension, what intent should I use in order to open the phone's memory (like the file manager) and choose whatever I want?

Now I'm using the Get content intent thanks to you guys:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent, 1);

but the problem is in the start activity for result

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 1) {
            Log.d("select pivture", "passed her");
            Uri selectedMediaUri = data.getData();

            String Fpath = selectedMediaUri.getPath();

            Log.d("Fpath", Fpath);
}

I get as follows:

/document/primary:Download/tool208.pdf

Which is not what I want, I want path like this one:

/external/images/media/6634

解决方案

Use below method:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

UPDATE

   @Override  
   protected void onActivityResult(int requestCode, int resultCode, Intent data)  
   {  
          super.onActivityResult(requestCode, resultCode, data);  
         if(requestCode==PICKFILE_REQUEST_CODE){  
         }  
 }  

这篇关于从手机意图上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆