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);

更多相关文章

  1. Android input 输入系统学习
  2. android修改系统源码(重新编译源码)
  3. 【分享】大量android软件开发资料和实例代码【转】
  4. android adb命令 抓取系统各种 log
  5. 获得Android Linux系统增删文件的权限
  6. android 文件系统(
  7. Eclipse Android 代码自动提示功能
  8. 【Android 应用开发】 Android 相关代码规范 更新中 ...

随机推荐

  1. 优雅的获取表单元素、dom树的遍历与常用
  2. MyCms 自媒体 CMS 系统 v2.6,SEO 优化升级
  3. Linux上搭建meterSphere
  4. Go语言什么时候该使用指针
  5. C语言设计模式之命令模式介绍
  6. 修改 asp.net core 5 程序的默认端口号
  7. SpringBoot基于Redis的分布式锁实现过程
  8. 在NET Core 中获取 CPU 使用率
  9. 表单元素获取,dom树的遍历与常用属性,dom
  10. MySQL 字符串转换为数字的方法小结