我创建了一个应用程序,它可以通过点击一个按钮来调用sharedpreferences中指定的号码。这一切都是完美的。
我的问题是:例如,当你的手机上有一个voip客户端或skype,你选择一个联系人或你拨一个号码,你会得到一个选择,你想要执行电话呼叫。
但在我的应用程序中,它直接进入默认的android调用者。
这是我的代码:
SharedPreferences prefs;
prefs = PreferenceManager.getDefaultSharedPreferences(this);
final String callnumber = prefs.getString("call", "");
callbutton = (Button) findViewById(R.id.callbutton);
// Add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
// Call Button Listener
callbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0)
{
String posted_by = callnumber;
String uri = "tel:" + posted_by.trim() ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
}
});}
我的最后一个问题是:是否有可能,当我点击呼叫按钮在我的应用程序,我将得到哪个应用程序应该执行呼叫的选择?
我从来没有做过这样的实现,但我认为你可以做到。也许如果你在你的应用程序中添加一些IntentFilters,再加上Android启动其他应用程序的能力,你就可以实现你的目标了。
下面的代码显示了如何打开Skype应用程序并通过他的名字拨打给定/传递的联系人:
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + name));
startActivity(sky);
我认为你可以实现一个类似的行为,打开你想要的应用程序,传递给它所需的参数。
我希望它能在某种程度上帮助你!:)