当用户从"联系人的完成操作使用"菜单中选择我的应用时,如何获取联系人



我正在编写自动拨号程序。我的主要活动有一个编辑文本,用于在联系人单击"从联系人添加"时输入电话号码或从联系人中检索。它运行良好。

现在,我的要求是,我需要将我的应用程序添加到联系人的"使用完成操作"菜单中。

它也完成了。但当用户使用菜单从完整操作中选择我的应用程序时,我想要所选的电话号码,并在主屏幕上设置电话号码。

现在只有我的应用程序被打开,电话号码是黑色的。

我想知道当他们从联系人启动我的应用程序时,如何获取所选的电话号码。

这是我的问题的答案。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = getIntent();
    String action = intent.getAction();
    if(action != null){
        // Set the user selected phone number when action lunch directly
        // from
        // contacts
        if (action.equalsIgnoreCase(INTENT_CALL_PRIVILEGED)) {
            setCallPrivilegedData();
        }
    }
    setCardSpinner();
}
private void setCallPrivilegedData() {
    phoneNumber = getIntent().getDataString();
    EditText phoneNoEditText = (EditText) findViewById(R.id.phone_no);
    try {
        phoneNoEditText.setText(URLDecoder.decode(phoneNumber.substring(4),
                "utf-8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

相关内容

最新更新