文件夹拿取文件 上传

/*
*首先判断是否有权限
*/

权限处理块
    XXPermissions.with(this).permission(ss).request(new OnPermission() {
            @Override
            public void hasPermission(List<String> granted, boolean isAll) {

            }
            @Override
            public void noPermission(List<String> denied, boolean quick) {
                JumpPermissionSet.showHinDialog(ActualCompletionAct.this);
            }
        });

/*
有权限打开文件夹 , 没权限申请权限
*/

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {
            //打开文件夹
            startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
        } catch (android.content.ActivityNotFoundException ex) {
            MyToastUtil.showToast(this, "打开文件管理器失败");
        }

/*
打开文件夹 选择文件返回 获取文件的url值 获取url值 请看上篇文章 url转换路径
*/

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String path = null;
        if (resultCode == RESULT_OK && requestCode == FILE_SELECT_CODE) {
            Uri uri = data.getData();
         try {
                path = PathUtils.getPath(ActualCompletionAct.this, uri);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!TextUtils.isEmpty(path)) {
                File file = new File(path);
                if (f != null && f.exists()) {
                    long l = (f.length() / 1024) / 1024;
                    if (l > 15) {
                        MyToastUtil.showToast(this, "只能上传小于15MB的文件");
                        return;
                    }else{
                      网络请求
                      Uploadfiles(file);
                    }
                }
            }
        }
    }
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值