[英]How to get contact when user choose my app from Contacts's Complete Action Using menu
I am writing auto dialer. 我正在写自动拨号器。 My main activity has an edittext to enter the telephone no or retrieve from contacts when they click "Add from Contacts". 我的主要活动有一个edittext,用于输入电话号码或在点击“从联系人添加”时从联系人中检索。 It is working fine. 它工作正常。
Now, my requirement is that I need to add my app into Contact's Complete Action Using menu. 现在,我的要求是我需要将我的应用程序添加到Contact的Complete Action Using菜单中。
It is also done. 它也完成了。 But when user choose my app from complete action using menu, I want that selected phone no and set the phone no. 但是当用户使用菜单从完整操作中选择我的应用程序时,我希望选择的手机没有,并设置手机号码。 on my main screen. 在我的主屏幕上。
Now only my app is opened and phone no. 现在只有我的应用程序打开,电话号码。 is black. 是黑色的。
I would like to know how to get that selected phone no. 我想知道如何获得所选手机号码。 when they start my app from contacts. 当他们从联系人开始我的应用程序。
Here is my answer for my question. 这是我对我的问题的回答。
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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.