我有一个应用程序拨打特定的电话号码,如果号码没有响应应用程序的行动,我的问题是:我怎么知道是否有回复?!
这是我的代码:
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
Button emr = (Button) findViewById (R.id.emergButton);
emr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Model m = new Model () ;
num=m.getAdminPhone();
String Numb = "tel:"+num;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(Numb));
startActivity(callIntent);
if () // here i want to making a check...
{answer = true;}
}
});
答案 0 :(得分:0)
This answer应该有帮助。
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
try {
if (state == TelephonyManager.CALL_STATE_OFFHOOK){
// Call wasn't answered
}
} catch (RemoteException e) {}
}
};
答案 1 :(得分:0)
似乎无法从拨号器获得结果。 This topic可能会帮助您实现这一点。因此,使用@Cameron方法似乎更好。
填写答案以接受另一个答案是不是很有趣? ;)