Android打开第三方应用方法总结

Android打开第三方应用方法总结

在Android开发中,有很多地方都需要启动其他的程序,调起第三方应用(“QQ”、“微信”、“支付宝”、“高德地图”等),还有一些系统应用(“电话”、“短信”、“拍照”、“图库”等),下面一起来看看如何启动这些常用应用。

QQ

1. 第三方应用

1)通过包名启动

PackageManager packageManager = this.getPackageManager();
Intent intent= packageManager.getLaunchIntentForPackage("com.tencent.mobileqq");
startActivity(intent);

2)通过包名和类名启动

Intent intent = new Intent();  
ComponentName comp = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.SplashActivity");  
intent.setComponent(comp);  
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
startActivity(intent);

2. 系统应用

1)从google搜索内容

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_WEB_SEARCH);  
intent.putExtra(SearchManager.QUERY,"搜索内容")  
startActivity(intent); 

2)浏览网页

Uri uri = Uri.parse("http://www.google.com");  
Intent intent = new Intent(Intent.ACTION_VIEW,uri);  
startActivity(intent);  

3)显示地图

Uri uri = Uri.parse("geo:36.899533,66.036476");  
Intent intent = newIntent(Intent.Action_VIEW,uri);  
startActivity(intent);  

4)路径规划

Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4");  
Intent intent = newIntent(Intent.ACTION_VIEW,URI);  
startActivity(intent);  

5)拨打电话

Uri uri = Uri.parse("tel:10086");  
Intent intent = new Intent(Intent.ACTION_DIAL,uri);    
startActivity(intent);  

6)发短信

Uri uri = Uri.parse("smsto:10086");     
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);     
intent.putExtra("sms_body", "SMS Text");     
startActivity(intent); 

7)发送彩信

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hello");
Uri uri = Uri.parse("content://media/external/images/media/23");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(intent);

8)发送Email

Uri uri = Uri.parse("mailto:123456@qq.com");  
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);  
startActivity(intent);  

9)播放多媒体

Intent intent = new Intent(Intent.ACTION_VIEW);  
Uri uri = Uri.parse("file:///sdcard/song.mp3");  
intent.setDataAndType(uri,"audio/mp3");  
startActivity(intent);

10)设置界面

Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
startActivity(intent);

11)拍照

// 打开拍照程序
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
<span style="color:#444444"><code> // 取出照片数据
Bundle extras = intent.getExtras();
Bitmap bitmap = (Bitmap) extras.get("data");
</code></span>

12)选择图片

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 2);

13)打开录音机

Intent intent = new Intent(Media.RECORD_SOUND_ACTION);  
startActivity(intent); 

14)卸载软件

Uri uri = Uri.fromParts("package", strPackageName, null);     
Intent intent = new Intent(Intent.ACTION_DELETE, uri);     
startActivity(intent);  

15)安装软件

<String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk";   
Intent intent = new Intent(Intent.ACTION_VIEW);   
intent.setDataAndType(Uri.fromFile(new File(fileName)),
"application/vnd.android.package-archive");   
startActivity(intent);  

3. 场景应用

检查版本更新,跳转到腾讯应用宝进行下载更新

/** 跳转到腾讯应用宝下载软件 */
public static void goThirdApp() {
    if (isAvilible(this, "com.tencent.android.qqdownloader")) {// 市场存在      
        startAppStore(getApplicationContext(), "项目包名", "com.tencent.android.qqdownloader");
    } else {
        Uri uri = Uri.parse("http://a.app.qq.com/o/simple.jsp?pkgname=项目包名");
        Intent it = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(it);
    }
}
/** 启动到app详情界面 */
public static void startAppStore(Context context, String appPkg, String marketPkg) {
     try {
            if (TextUtils.isEmpty(appPkg))return;
                Uri uri = Uri.parse("market://details?id=" + appPkg);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        
             if (!TextUtils.isEmpty(marketPkg)) {
                intent.setPackage(marketPkg);
             }
              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(intent);               
    } catch (Exception e) {
        e.printStackTrace();               
    }      
}
/** 判断软件是否存在 */
public static boolean isAvilible(Context context, String packageName) {
    try {
        context.getPackageManager().getPackageInfo(packageName, 0);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115014.html原文链接:https://javaforall.net

(0)
上一篇 2021年10月1日 上午10:00
下一篇 2021年10月1日 上午11:00


相关推荐

  • idea永久激活码[在线序列号]

    idea永久激活码[在线序列号],https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日
    137
  • pycharm2021专业版激活码【注册码】

    pycharm2021专业版激活码【注册码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    55
  • 【Cursor 保姆级教程】零基础小白从安装到实战,手把手教你玩转 AI 编程神器! · 测试之家

    【Cursor 保姆级教程】零基础小白从安装到实战,手把手教你玩转 AI 编程神器! · 测试之家

    2026年3月16日
    2
  • SMBus学习记录

    SMBus学习记录SMBus学习记录SMBus是SystemManagementBus的缩写,译为系统管理总线,SMBus是一种二线制串行总线,1996年第一版规范开始商用。它大部分基于I2C总线规范。Overview系统管理总线(SMBus)是一个双线接口,通过它,各种系统组件芯片和设备可以相互通信,也可以与系统的其余部分进行通信。它基于I2C总线的工作原理。SMBus为系统和电源管理相关任务提供控制总线。系统可以使用SMBus将消息传递到设备和设备之间,而不使用单独的控制线。可减少引脚数。本文档描述了

    2025年7月23日
    5
  • 海康服务器协议,国标流媒体服务器GB28181协议和海康设备的交互过程记录

    海康服务器协议,国标流媒体服务器GB28181协议和海康设备的交互过程记录原标题 国标流媒体服务器 GB28181 协议和海康设备的交互过程记录国标 GB28181 协议从 2016 年更新后 变得比之前更火了 到今年已经 4 年了 国标视频流媒体服务器基础的功能都已经发展起来 而更深层次的功能还需要进一步的研发 在日常运用中 海康的摄像头运用较为广泛 本文我准备跟大家分享一下 GB28181 协议和海康设备交互过程记录 1 发送消息的时候要注意头部的 from to 字段中的数据 这标志

    2026年3月17日
    1
  • ubuntu中pycharm无法输入中文

    ubuntu中pycharm无法输入中文一 点击 File Setting Editor FileEncoding 页面 设置 global 和 projectencod 为 UTF 8 然后点击 Apply 二 点击 File Setting Editor FileandCodeT 点击右边的 pythonscript 在编辑框中输入 coding utf 8 保存设置之后 关闭 pycharm 三 下载最新的搜狗输入法安装即可 再打开 p

    2026年3月19日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号