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);       //  返回图片对象
相关推荐
用户2018792831671 分钟前
Java 泛型:快递站老板的 "类型魔法" 故事
android
Knight_AL15 分钟前
浅拷贝与深拷贝详解:概念、代码示例与后端应用场景
android·java·开发语言
夜晚中的人海1 小时前
【C++】智能指针介绍
android·java·c++
用户2018792831671 小时前
后台Activity输入分发超时ANR分析(无焦点窗口)
android
用户2018792831671 小时前
Activity配置变化后ViewModel 的 “不死之谜”
android
游戏开发爱好者82 小时前
BShare HTTPS 集成与排查实战,从 SDK 接入到 iOS 真机调试(bshare https、签名、回调、抓包)
android·ios·小程序·https·uni-app·iphone·webview
2501_916008893 小时前
iOS 26 系统流畅度实战指南|流畅体验检测|滑动顺畅对比
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915106325 小时前
苹果软件加固与 iOS App 混淆完整指南,IPA 文件加密、无源码混淆与代码保护实战
android·ios·小程序·https·uni-app·iphone·webview
2501_915921435 小时前
iOS 26 崩溃日志解析,新版系统下崩溃获取与诊断策略
android·ios·小程序·uni-app·cocoa·iphone·策略模式
齊家治國平天下7 小时前
Android 14 Input 事件派发机制深度剖析
android·input·hal