【发布时间】:2016-06-28 17:36:11
【问题描述】:
我正在实现电话演示,在我的演示中,我使用 autoLink = phone 生成了到 textview 的链接,但只有当我将此号码保存在我的联系人列表中时它才有效,我无法生成随机号码上的链接..
我也试过 clickable=true。并且还应用 Linkify 类,但这也不起作用。 并且还应用了 autoLink="all" 它也不起作用,我不知道出了什么问题。我还在清单中设置了权限。
这是我的代码:
txtfromnumber = (TextView) findViewById(R.id.txtfromnumber);
int mask = Linkify.ALL;
Linkify.addLinks(txtfromnumber, mask);
txtfromname = (TextView) findViewById(R.id.txtfromname);
txtreceivernumber = (TextView) findViewById(R.id.txtreceivernumber);
int mask2 = Linkify.ALL;
txtreceivernumber.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent dialIntent = new Intent(Intent.ACTION_CALL,
Uri.parse("Tel:"+txtreceivernumber.getText().toString().trim()));
if (dialIntent.resolveActivity(context.getPackageManager()) != null) {
dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialIntent.setPackage("com.android.phone");
}else {
dialIntent.setPackage("com.android.server.telecom");
}
startActivity(dialIntent);
}
}
});
txtfromnumber.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent dialIntent = new Intent(Intent.ACTION_DIAL,
Uri.parse("+"+txtfromnumber.getText().toString().trim()));
if (dialIntent.resolveActivity(context.getPackageManager()) != null) {
dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialIntent.setPackage("com.android.phone");
}else {
dialIntent.setPackage("com.android.server.telecom");
}
startActivity(dialIntent);
}
}
});
这是我的 xml 文件代码:
<TextView
android:clickable="true"
android:autoLink="all"
android:id="@+id/txtreceivernumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="17sp" />
<TextView
android:clickable="true"
android:autoLink="all"
android:id="@+id/txtreceivernumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="17sp" />
这里我的接收者号码 txtview 工作正常 bcz 这个号码保存在我的联系人列表中,但 FromNumber txtview 没有设置任何链接或任何东西。 bcz 它的随机数。
问题 2。
如何直接呼叫而不是打开拨号窗口。?任何帮助都会得到帮助.. 非常感谢。
注意。这个问题解决了。这是工作代码。
【问题讨论】:
标签: android