Android file transfer/Upload
16lz
2021-01-23
Android file transfer/Upload
一. 若想在Android上利用系统已有的Intent 发送/上传文件,可以尝试如下:Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpg");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f) );
startActivity(intent);系统会弹出可供选择的Intent。如果想要指定的Intent,那么再设置component参数即可:setComponent(new Component("com.android.***/*Packagename*/"),("com.android.***.###/*full class name*/"))如果想发生/上传多个文件,那么请使用ACTION_SEND_MULTIPLE
对应的Extra设置方法,需要调整为put*ArrayListExtra,其它依样画葫芦就可以了。
二. 格外补充:
如果希望自行开发的Intent支持类似的功能,那么需要在自己的功能注册进系统中。
在Menifest中的相应Activity中加入类似代码。
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="yourapp/yourtype" />
</intent-filter>别人就是使用如下代码调用了:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("yourapp/yourtype");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f) );
startActivity(intent);
更多相关文章
- Android input 输入系统学习
- android修改系统源码(重新编译源码)
- 【分享】大量android软件开发资料和实例代码【转】
- android adb命令 抓取系统各种 log
- 获得Android Linux系统增删文件的权限
- android 文件系统(
- Eclipse Android 代码自动提示功能
- 【Android 应用开发】 Android 相关代码规范 更新中 ...