intent-filter的action,category,data匹配规则

action匹配规则:只要intent中action与intent filter中任意一个能匹配上就可

category匹配规则:intent中所有category都必须在intent filter中有才能匹配上

https://juejin.im/entry/6844903553962606606

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NoNonsense-FilePicker有如下特点: 1.可扩展以适应不同的数据源。 2.支持多选。 3.可以选择目录或者是文件。 4.可以在选择器中新建目录。 NoNonsense-FilePicker不只是另外一个文件选择器而已 我需要的是这样一个文件选择器: 1.容易扩展,文件来源既可以是本地sdcard,也可以是来自云端的dropboxapi。 2.可以在选择器中创建目录。 本项目具备上述的两个要求,同时很好的适配了平板和手机两种UI效果。项目的核心是在一个abstract 类中,因此你可以很方便的继承以实现自己需要的选择器。 项目本身已经包含了一个能够选择本地sdcard文件的实现,但你完全可以扩展实现一个文件列表来源于云端的选择器,比如Dropbox, ftp,ssh等。 选择器是基于activity,在屏幕较小的设备上全屏显示,而在较大的屏幕上则显示成dialog的方式,这个特性是系统主题中做到的,因此为activity选择一个正确的主题至关重要。 使用说明: 该库的核心思想是做到可扩展,但是你只是想选择sdcard中的文件,只需阅读关于如何使用sdcard文件选择器就可以了。 首选需要加上文件访问权限: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 将选择器的app注册到AndroidManifest.xml <activity android:name="com.nononsenseapps.filepicker.FilePickerActivity" android:label="@string/app_name" android:theme="@style/FilePicker.Theme"> <intent-filter> <action android:name="android.intent.action.GET_CONTENT"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> 在java代码中调用选择器: // This always works Intent i = newIntent(context, FilePickerActivity.class); // This works if you defined the intent filter // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // Set these depending on your use case. These are the defaults. i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE); startActivityForResult(i, FILE_CODE); 获取选择的返回值: @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) { if(data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) { // For JellyBean and above if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = data.getClipData(); if(clip != null) { for(int i = 0; i < clip.getItemCount(); i++) { Uri uri = clip.getItemAt(i).getUri(); // Do something with the URI } } // For Ice Cream Sandwich } else{ ArrayList<String> paths = data.getStringArrayListExtra (FilePickerActivity.EXTRA_PATHS); if(paths != null) { for(String path: paths) { Uri uri = Uri.parse(path); // Do something with the URI } } } } else{ Uri uri = data.getData(); // Do something with the URI } } }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值