Android(安卓)file transfer/Upload
16lz
2021-12-04
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 intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("yourapp/yourtype");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f) );
startActivity(intent);
更多相关文章
- Android中自动跳转到系统设置界面
- xUtils3.3.x注解使用实例
- EditText在输入法上显示搜索按钮
- android-控件样式(Theme)自定义
- Android(安卓)SQLiteOpenHelper(手机数据库)
- Android(安卓)Studio中Textview里字体颜色的的设置
- 【android】设置View字体点击变色和边框背景设置
- Android不让弹出键盘挡住View
- Android点击WebView网页中的email发送邮件调用