Android 打开系统应用

总结一下Android 打开系统常用应用的方法,如打开文件选择器、打开文档阅读、等等

  1. 打开文件选择器

    val intent = Intent(Intent.ACTION_GET_CONTENT)
    intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
    intent.type = "/"
    //intent.type ="application/pdf"
    intent.addCategory(Intent.CATEGORY_OPENABLE)
    /*var mineTypes = arrayListOf("application/pdf", "text/plain")

    intent.putExtra(Intent.EXTRA_MIME_TYPES, mineTypes)*/
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
    startActivityForResult(
    Intent.createChooser(intent, "Select file"),
    REQUEST_CODE_SELECT_FILE)

  2. 打开PDF

    val intent = Intent(Intent.ACTION_VIEW)
    intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_CLEAR_TOP
    intent.setDataAndType(uri, "application/pdf")
    startActivity(intent)

  3. 打开浏览器

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.baidu.com")); //打开浏览器
    startActivity(intent);

  4. 打开拨号面板

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:13800008888")); // 打开拨号面板
    startActivity(intent);

5.打开短信

复制代码
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SENDTO);             //  打开短信发送面板
intent.setData(Uri.parse("smsto:13800001111"));
intent.putExtra("sms_body","短信内容");
startActivity(intent);

6.打开图库

复制代码
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);       //打开图片库
//  intent.setType("image/*");      //  选择照片
//  intent.setType("audio/*");      //  选择音频
//  intent.setType("video/*");      //  选择视频(mp4,3gp)
//  intent.setType("video/;image/");      //  选择视频和照片
startActivityForResult(intent, 10001);

7.打开相机,拍照

java 复制代码
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); //打开系统相机
startActivityForResult(intent,1);       //  返回图片对象
相关推荐
莞凰2 小时前
昇腾CANN的“灵脉根基“:Runtime仓库探秘
android·人工智能·transformer
NiceCloud喜云3 小时前
Claude Files API 深入:从上传、复用到配额管理的工程化指南
android·java·数据库·人工智能·python·json·飞书
ujainu3 小时前
CANN pto-isa:虚拟指令集如何连接编译与执行
android·ascend
赏金术士4 小时前
第六章:UI组件与Material3主题
android·ui·kotlin·compose
TechMerger5 小时前
Android 17 重磅重构!服役 20 年的 MessageQueue 迎来无锁改造,卡顿大幅优化!
android·性能优化
yuhuofei20218 小时前
【Python入门】Python中字符串相关拓展
android·java·python
dalancon8 小时前
Android Input Spy Window
android
dalancon10 小时前
InputDispatcher派发事件,查找目标窗口
android
我命由我1234510 小时前
Android Framework P3 - MediaServer 进程、认识 ServiceManager 进程
android·c语言·开发语言·c++·visualstudio·visual studio·android runtime
天才少年曾牛11 小时前
Android14 新增系统服务后,应用调用出现 “hidden api” 警告的原因与解决方案
android·frameworks