android 实现点击号码打开第三方软件

拨打电话

拨打电话功能相信大家都用过,拨打电话有两个界面,一个是打电话界面,一个是拨号界面,现在实现一下:

1、添加权限

<uses-permission android:name="android.permission.CALL_PHONE" />

android 6.0需要动态设置权限

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 
   //在这里面向系统请求权限,如果没有在这里面处理,不会执行下面的方法了    
//这里就是向系统请求权限了,这里我还做了一个判断. sdk是M(M = 23 android L)才做这个请求,否则就不做.   
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {    
    requestPermissions(new String[]{"android.permission.CALL_PHONE"}, 111);  
  }
    return;
}

2、跳转到拨号页面

//用intent启动拨打电话
 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "15224778580");
 if (ActivityCompat.checkSelfPermission(ContactActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
 // TODO: Consider calling
 // ActivityCompat#requestPermissions 
// here to request the missing permissions, and then overriding
 // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
// int[] grantResults) 
// to handle the case where the user grants the permission. See the documentation 
// for ActivityCompat#requestPermissions for more details. 
return; 
} 
this.startActivity(intent);
 }

**3、立即拨打 **

//用intent启动拨打电话 
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "15224778580"); 
if (ActivityCompat.checkSelfPermission(ContactActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 
// TODO: Consider calling 
// ActivityCompat#requestPermissions 
// here to request the missing permissions, and then overriding
 // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
// int[] grantResults)
 // to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
 return;
 }
 this.startActivity(intent);

上面代码是android6.0动态权限,当设置 targetSdkVersion 23时,就需要这样添加权限。

打开qq聊天界面

打开qq界面就没有拨打电话那么麻烦,不用添加什么权限,实现方法如下:

String url = "mqqwpa://im/chat?chat_type=wpa&uin=1548602276";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

发送邮件

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

在此记录以下,方便日后使用!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 6.0 运行时权限处理 标签(空格分隔): android 运行时权限介绍 Android 6.0...
    曹国强阅读 1,612评论 0 1
  • 本文转自:http://www.cnblogs.com/dsxniubility/p/5596973.html 方...
    Lewis海阅读 3,788评论 0 1
  • 独倚高楼望天际,混天夜里,惟闻雨声落地。杯酒入肠触情起,不语谁会凭阑意。拟把霖雨作玉具①,斩断凡尘,强乐还无趣。青...
    元鸷阅读 2,118评论 0 2
  • (二)皇后娘娘的故事 花歆婷也顺势咳嗽了一声作掩饰,她的小伎俩被阴狠歹毒的李鸿山一眼识破。李鸿山...
    公子凌希阅读 3,199评论 5 19
  • 首先 Python是一门易学难精的语言,其实绝大多数编程语言都是如此大概在大三的时候,我也有如你一样的困惑,那时我...
    Python程序媛阅读 5,840评论 0 7

友情链接更多精彩内容