
当用户单击textVIEw时,如何在android中打个电话,然后自动在textVIEw中打个电话?
TextVIEw tv=(TextVIEw) findVIEwByID(R.ID.tv_contact); String url = tv.getText().toString();Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); tv.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub startActivity(intent); } });'解决方法:
在AndroIDManifest.xml文件中添加调用权限.
<uses-permission androID:name="androID.permission.CALL_PHONE"/>首先通过在layout.xml中添加以下内容来使您的TextVIEw可点击
<TextVIEw ......androID:clickable="true"></TextVIEw>然后在您的Activity类中,在特定TextVIEw的OnClickListener内添加以下代码
if (Build.VERSION.SDK_INT > 22) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MoreProgramDetailActivity.this, new String[]{Manifest.permission.CALL_PHONE}, 101); return; } Intent callintent = new Intent(Intent.ACTION_CALL); callintent.setData(Uri.parse("tel:+" + tv.getText().toString().trim())); startActivity(callintent); } else { Intent callintent = new Intent(Intent.ACTION_CALL); callintent.setData(Uri.parse("tel:+" + tv.getText().toString().trim())); startActivity(callintent); } 总结 以上是内存溢出为你收集整理的android-TextView上的电话单击全部内容,希望文章能够帮你解决android-TextView上的电话单击所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)