我試圖從應用回到應用程序調用
打個電話,我想它來調用
回來後返回到應用程序後,我問這個問題在這個論壇上,但我不明白的答案
How to make a phone call in android and come back to my activity when the call is done?
public void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:048598077"));
getContext().startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Log.e("dialing-example", "Call failed", activityException);}
finally {
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
private class EndCallListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_RINGING == state) {
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
//wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
Log.i(LOG_TAG, "OFFHOOK");
}
if(TelephonyManager.CALL_STATE_IDLE == state) {
//when this state occurs, and your flag is set, restart your app
Log.i(LOG_TAG, "IDLE");
}
}
我明白這樣的一些東西,但我沒有在任何時刻開始CallListener
。 那我該怎麼做呢?
我把它在manifest.xml和它仍然stais的通話記錄 – igor
你不需要把它在manifest.xml的manufest。把它放在哪裏,你有一個包含要call.Here數文本視圖.xml文件你有一個例子: –
我在做對吧? 主.XML JAVA FILE private void call(){ try {intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(「tel:xxxxxxx」)); startActivity(callIntent); (「Dialing-example」,「Call failed」,activityException); } –
igor