【发布时间】:2019-02-09 10:59:22
【问题描述】:
我正在处理来电的应用来电屏幕。我无法在 android marshmallow 和 nougat API 级别 23 到 25 上接受来电。
公共无效acceptCall() { TelecomManager TelecomManager = null;
//API level >=26
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
telecomManager = (TelecomManager) getApplicationContext().getSystemService(Context.TELECOM_SERVICE);
telecomManager.acceptRingingCall();
}
//API level >=22
else if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
try {
Runtime. getRuntime (). exec ("input keyevent " +
Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
} catch (IOException e) {
// Runtime.exec(String) had an I/O problem, try to fall back
String enforcedPerm = "android.permission.CALL_PRIVILEGED";
Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK));
Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(btnDown, enforcedPerm);
context.sendOrderedBroadcast(btnUp, enforcedPerm);
}
}
//API level =23 || API=25||API=26
if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.M || android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 ||
android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
//what code should i do here?
}
}
【问题讨论】: