开发者

Displaying phone numbers in Android

What's the easiest way to display an active (initiatin开发者_运维问答g a call on click) phone number in an Android app?

It would have been great if there was a View subclass, called something like PhoneNumberView, that has all the functionality and UI integrated.


You can just use

<TextVIew
   ...
   android:autoLink="all"
/>

It will highlight phone and make it clickable. http://developer.android.com/reference/android/widget/TextView.html#attr_android:autoLink


Displaying the number can be as easy as putting it in a text view. to add touch behavior, you can define an "on touch listener"

view.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        //define behavior here
    }
});

As far as the code for dialing the phone, look into the google api's for the right method. You need to create the proper intent and then call startActivity(...). you can find information about using intents to start apps here (this should start the phone's normal dial interface and call the number so you wont have to create your own)


True, as Lin points out, the question is about a number already dialed. But the right way to handle the situation might very well be to take over the phoning and dialing with Intent.ACTION_DIAL and Intent.CALL_ACTION. The OP should read the documentation on how to service these Intents and decide if that is an adequate solution. Otherwise he will have to read the Android source code for the built-in dialer and see if it publishes the phone number dialed: I don't think it does.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜