android intent传文件夹,在Android上通过Intent选择任何类型的文件

三星文件浏览器不仅需要自定义操作(com.sec.android.app.myfiles.PICK_DATA),而且部分类(意向。CATEGORY_DEFAULT)和MIME类型应该额外进行传递。

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");

intent.putExtra("CONTENT_TYPE", "*/*");

intent.addCategory(Intent.CATEGORY_DEFAULT);

您也可以使用此操作来打开多个文件:com.sec.android.app.myfiles.PICK_DATA_MULTIPLE无论如何,这是我的解决方案,可在Samsung和其他设备上使用:

public void openFile(String mimeType) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(mimeType);

intent.addCategory(Intent.CATEGORY_OPENABLE);

// special intent for Samsung file manager

Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");

// if you want any file type, you can skip next line

sIntent.putExtra("CONTENT_TYPE", mimeType);

sIntent.addCategory(Intent.CATEGORY_DEFAULT);

Intent chooserIntent;

if (getPackageManager().resolveActivity(sIntent, 0) != null){

// it is device with Samsung file manager

chooserIntent = Intent.createChooser(sIntent, "Open file");

chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent});

} else {

chooserIntent = Intent.createChooser(intent, "Open file");

}

try {

startActivityForResult(chooserIntent, CHOOSE_FILE_REQUESTCODE);

} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT).show();

}

}

该解决方案对我来说效果很好,也许对其他人也很有用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值