E
E
e-hot2019-05-15 11:49:29
android studio
e-hot, 2019-05-15 11:49:29

How to correctly include the com.android.internel.telephone package and import ITelephony into Android Studio?

Greetings.
I need help in the following situation:
Situation:
in Andriod Studio I am writing code in BroadcastReceiver to programmatically reset an incoming call, I looked at a bunch of code options on the Internet, in all examples there is a use of com.android.internel.telephone.ITelephony, which can only be accessed through the interface Telephony - also rummaged through a bunch of information on installing the com.android.internel.telephone package itself and importing ITelephony - nothing happens. When creating a package com.android.internel.telephone in the java folder, the package being created is "cut" into com and the android.internel.telephone nested in it - should it be so? When creating an interface, ITelephony is also something incomprehensible, there are examples where ITelephony is added as Class java, in others - as ITelephony.aidl - which is correct?
Question:
can someone write down the points where what and how to do, so that in the end you get the correct working result?
Thank you.
PS
1. I tried again adding the com.android.internel.telephone package and importing ITelephony. When creating the package, despite the fact that I added it to the java folder, I still got the structure: app->java->com->android.internel.telephone. Further, when interface ITelephony.aidl was added to android.internel.telephone, the structure changed again: app->java->com->android.internel.telephone - it remained the same, the interface ITelephony.aidl file was not added, but a new structure appeared :
app->aidl->com.android.internel.telephone->ITelephony.aidl - Android Studio ( 3.4 ) does everything right?
2. In ITelephony.

package com.android.internal.telephony;

interface ITelephony {
    boolean endCall();
    void answerRingingCall();
    void silenceRinger();
}

3. In BroadcastReceiver added:
...
import com.android.internal.telephony.ITelephony;
...
public class CallingReceiver extends BroadcastReceiver {
...
}

4. Already in the final method:
public void disconnectPhoneItelephony( Context context ){
ITelephony telephonyService;
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        try {
            Class c = Class.forName(tm.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            telephonyService = (ITelephony) m.invoke(tm);
            telephonyService.endCall();
        } catch (Exception e) {
            e.printStackTrace();
        }
}

and here in telephonyService.endCall(); As a result, he swears: Cannot resolve method 'endCall()'
Question: how to fix Cannot resolve method 'endCall()'? What did I do wrong? Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question