Bis zu Android 7.1 war es möglich, einen eingehenden Anruf mit der ITelephony.endCall() -Methode zu beenden und Ihre App die Berechtigungen android.permission.CALL_PHONE und Android. permission.READ_PHONE_STATE.Trennen Sie einen Anruf programmatisch nicht funktioniert in Android 8.0 (Oreo)
Wenn auf Android 8.0 Oreo (API 26) das gleiche zu tun, bekomme ich diese Fehler
12-14 17:37:26.160 20962-20962/com.xinthe.carmode W/System.err: java.lang.reflect.InvocationTargetException 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at java.lang.reflect.Method.invoke(Native Method) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at com.xinthe.carmode.listeners.MyPhoneStateListener.disconnectCall(MyPhoneStateListener.java:108) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at com.xinthe.carmode.listeners.MyPhoneStateListener.onCallStateChanged(MyPhoneStateListener.java:51) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at android.telephony.PhoneStateListener$1.handleMessage(PhoneStateListener.java:338) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at android.os.Handler.dispatchMessage(Handler.java:105) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at android.os.Looper.loop(Looper.java:164) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6809) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at java.lang.reflect.Method.invoke(Native Method) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 12-14 17:37:26.161 20962-20962/com.xinthe.carmode W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 12-14 17:37:26.162 20962-20962/com.xinthe.carmode W/System.err: Caused by: java.lang.SecurityException: Neither user 10304 nor current process has android.permission.CALL_PHONE. 12-14 17:37:26.162 20962-20962/com.xinthe.carmode W/System.err: at android.os.Parcel.readException(Parcel.java:1942) 12-14 17:37:26.162 20962-20962/com.xinthe.carmode W/System.err: at android.os.Parcel.readException(Parcel.java:1888) 12-14 17:37:26.162 20962-20962/com.xinthe.carmode W/System.err: at com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:1955) 12-14 17:37:26.162 20962-20962/com.xinthe.carmode W/System.err: ... 10 more 12-14 17:37:26.162 20962-20962/com.xinthe.carmode E/End call error: FATAL ERROR: could not connect to telephony subsystem 12-14 17:37:26.162 20962-20962/com.xinthe.carmode E/End call error: Exception object: java.lang.reflect.InvocationTargetException
Hier ist der Code für READ_PHONE_STATE Laufzeit Erlaubnis.
String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ANSWER_PHONE_CALLS};
void permissionCheck() {
if (!hasPermissions(this, PERMISSIONS)) {
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
}
public static boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
Kann mir bitte jemand helfen?
Sieht so aus, als hätten Sie sich auf eine undokumentierte Methode gestützt, die Sie durch Reflektion aufgerufen haben. Was du getan hast, sollte nicht vom Android-Team gemacht werden, und sie haben dieses Sicherheitsloch wahrscheinlich gerade gestopft. – 323go
zeigen Sie mir Ihren Code, wo Sie Laufzeitberechtigungen hinzufügen –
@WaleedAsim aktualisiert die Frage mit Laufzeitberechtigungscode. Bitte prüfe. – Santosh