如何在Android中为拨号操作设置意图过滤器? [英] How to set intent filter for dial action in android?

查看:64
本文介绍了如何在Android中为拨号操作设置意图过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的拨号盘.我创建了所有内容,现在我希望从其他应用程序接收操作拨号意图.

I am trying to create a simple dial pad. I created all that and now I like to receive action dial intent from other applications.

<intent-filter>

       <action android:name="android.intent.action.DIAL" />

       <category android:name="android.intent.category.DEFAULT" />

       <data android:xxxxxx="XXXXXX" />

</intent-filter>

,现在我不知道应该在动作过滤器中填充什么数据.谁能帮我 ?预先感谢.

and now I don't know what should be filled with the data in action filter. Can anyone help me ? Thanks in advance.

推荐答案

这是应该使用的意图过滤器.

This is the intent filter should be used.

<intent-filter>
<action android:name="android.intent.action.CALL_DIAL" />                
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>

我们可以像这样从 onCreate 方法中读取电话号码.

And we can read the phone number from onCreate methord like this.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //start reading here
        Intent intent = getIntent();
        if(intent.getData()!=null){
            Log.d("intent received",intent.getData().toString());
            String phoneNumber = intent.getData().toString(); //contains tel:phone_no
            phoneNumber = phoneNumber.substring(4);
            Log.d("intent received","Received phone number : "+phoneNumber);
                  /// do what you like here
        }else{
            Log.d("intent received","null intent received");
        }
}

这篇关于如何在Android中为拨号操作设置意图过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆