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

2016-12-21  本文已影响0人  小飞侠在吗

拨打电话

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

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);

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

上一篇下一篇

猜你喜欢

热点阅读