Android:autoLink not working fully on my 4.4 device

时光总嘲笑我的痴心妄想 提交于 2019-12-10 13:05:25

问题


I'm new to Android programming, and I had this weird problem, I wanted to make phone numbers in a list clickable, where they send you the the dialer, now this worked on my Android phone, but it seems to only work on numbers of 10-chars, but when I tested it on a virtual device with 4.1.2, it worked well on all numbers in the list, I later tried a 4.4.2 virtual device, and I had the same problem there.

From what I could find on Google, I think the problem starts from Jelly Bean, so, is there a solution to this? I used this in the TextView element in the layout XML fileL android:autoLink="phone"


回答1:


Was facing the same issue, for all the numbers longer than 10digits, solution is to just format them correctly and instead of 00 add a + sign infront of them, like: if number 00447172737475 , autolink wont work, but for +447172737475 it will work , hope it helps




回答2:


In my case I wanted any numbers work as phone autolink, and for me worked only this:

private void setAutoLinkForPhoneWorkaround(TextView textView, final String phoneText) {
    textView.setText(phoneText);
    textView.setPaintFlags(phoneText.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + phoneText));
            startActivity(intent);
        }
    });
}


来源:https://stackoverflow.com/questions/21538201/androidautolink-not-working-fully-on-my-4-4-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!