Android=TelephonyManager(Intent.ACTION\u调用)
当TelephonyManager状态IDLE检测到calleded变量上的真实值时,我想进行调用 第一次呼叫正常,但当从摘机更改为空闲时,我需要执行新的呼叫意图,但没有显示呼叫 我错过了什么 谢谢你抽出时间Android=TelephonyManager(Intent.ACTION\u调用),android,android-intent,telephonymanager,phone-state-listener,Android,Android Intent,Telephonymanager,Phone State Listener,当TelephonyManager状态IDLE检测到calleded变量上的真实值时,我想进行调用 第一次呼叫正常,但当从摘机更改为空闲时,我需要执行新的呼叫意图,但没有显示呼叫 我错过了什么 谢谢你抽出时间 import android.Manifest; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Boolean CallEnded = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TelephonyManager telephoneM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener listener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if(CallEnded){
performDial();
}
break;
case TelephonyManager.CALL_STATE_RINGING:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
CallEnded=true;
}
}
};
telephoneM.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
performDial();
}
});
}
private void performDial() {
Intent dial = new Intent(Intent.ACTION_CALL);
dial.setData(Uri.parse("tel:911"));
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){
return;
}
}
显示
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
第一个问题是,你不被允许
打行动电话
紧急电话,比如你的911
不是系统应用程序。
意图将转换为操作拨号
意图,导致系统电话应用程序出现,并允许用户手动拨打该号码(如果她选择)
我会先尝试使用标准电话号码,以确保这不是问题所在
第二个问题与在Android上两次调用相同的意图有关。
在某些情况下,Android可能会检测到完全相同的意图,并且会忽略新的意图。
如果这可能是问题所在,请尝试向url数据添加一些不断变化的值,如:
Intent dial = new Intent(Intent.ACTION_CALL);
dial.setData(Uri.parse("tel:212-555-1234" + "?time=" + System.currentTimeMillis()));
谢谢,非常有用的随机值转换器代码。