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);       //  返回图片对象
相关推荐
一条上岸小咸鱼1 小时前
Kotlin 类型检查与转换
android·kotlin
闲暇部落1 小时前
android studio配置 build
android·android studio·build
_祝你今天愉快2 小时前
Android FrameWork - Zygote 启动流程分析
android
龙之叶4 小时前
Android系统模块编译调试与Ninja使用指南
android
源码哥_博纳软云5 小时前
JAVA国际版多商户运营版商城系统源码多商户社交电商系统源码支持Android+IOS+H5
android·java·ios·微信·微信小程序·小程序·uni-app
用户2018792831675 小时前
bindService是如何完成binder传递的?
android
洞见不一样的自己5 小时前
Android 小知识点
android
tangweiguo030519877 小时前
Flutter性能优化完全指南:构建流畅应用的实用策略
android·flutter
AI大法师13 小时前
Android应用性能监测与调优:掌握Profiler和LeakCanary等关键工具
android
2501_9151063217 小时前
iOS混淆工具实战 金融支付类 App 的安全防护与合规落地
android·ios·小程序·https·uni-app·iphone·webview