I am making an App that should be able to detect call state, earlier I was advised to use PreciseCallState since by default android cannot detect exactly what state the call is in, PreciseCallState is in the Telephony Extension, which is in the android_frameworks_base, how to I get my Imports to work?, and for the most part will this work on Android < 5 or its only 5>?
- 23,503
- 10
- 80
- 110
- 197
- 1
- 3
- 14
3 Answers
try this,
first of all you take permission like
<uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
and then create receiver in manifest.xml file like,
<receiver android:name=".OutCallLogger">
<intent-filter>
<action android:name="android.intent.action.PRECISE_CALL_STATE" />
</intent-filter>
</receiver>
and implement onReceive() like this,
public class OutCallLogger extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getIntExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, -2) {
case PreciseCallState.PRECISE_CALL_STATE_IDLE:
Log.d(This.LOG_TAG, "IDLE");
break;
case PreciseCallState.PRECISE_CALL_STATE_DIALING:
Log.d(This.LOG_TAG, "DIALING");
break;
case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
Log.d(This.LOG_TAG, "ALERTING");
break;
case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
Log.d(This.LOG_TAG, "ACTIVE");
break;
}
}
}
- 1,234
- 2
- 9
- 16
-
1Useful, but doesn't answer the question(s). How to include the library in a project, and what SDK is required – Tim Sep 28 '15 at 11:57
-
@TimCastelijns exactly, how do I include the Library because it seems this does not come with the default SDK its more like hidden API – Chrome Landos Sep 28 '15 at 17:06
-
Do I need to download the Telephony Extension SDK (tho already tried it and it does not work) or download the Entire SDK? – Chrome Landos Sep 28 '15 at 17:23
-
Not sure if this helps - https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/ – headuck Oct 01 '15 at 04:57
-
@androiddeveloper I am facing one issue regarding call blocking. Can you please help me out https://stackoverflow.com/questions/53866038/how-to-block-a-call-when-first-call-is-ongoing – Suhas Bachewar Dec 20 '18 at 13:59
-
For those looking for the required SDK, ask Google about "hidden/internal android sdk". A repository which contains what you need would be this, for example (the one I'm currently using): https://github.com/anggrayudi/android-hidden-api. – DADi590 May 24 '22 at 10:27
What you need is the "Android Hidden/Internal SDK" (or "API"), as it's called on the Internet. Search Google for that, it will answer some questions you might have (which I no longer remember too much). A place to get started immediately with it would be this: https://github.com/anggrayudi/android-hidden-api. Have fun messing with the internal SDK!
By the way, just a note. Google blocked the internal APIs from Android Pie onwards: https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces. There are also ways to get past those anyway xD: https://stackoverflow.com/a/55970138/8228163 (or search for "bypass android hidden/internal sdk limitations").
Or you could also go with reflection and not use the internal SDK at all. Though, I still prefer the SDK. When I update the SDK, if some class/method/constant is no longer on it, Android Studio will throw a compilation error and I will know I must go find a replacement immediately - won't happen with reflection. (Aside from having the documentation right there and just calling a function instead of trying magic with hidden functions and try/catch things which I don't like too much in these cases.)
("Internal" because of android.internal.*, and "Hidden" because of the "@hide" attribute on classes/methods/constants.)
- 427
- 1
- 6
- 22
But the permission is defined for special-use applications such as dialers, carrier applications, or ims applications. So how should ordinary applications handle it.
READ_PRECISE_PHONE_STATE public static final String READ_PRECISE_PHONE_STATE Allows read only access to precise phone state. Allows reading of detailed information about phone state for special-use applications such as dialers, carrier applications, or ims applications.
Constant Value: "android.permission.READ_PRECISE_PHONE_STATE"
-
This is a comment and not an definitive answer. Please keep comments to the post itself. – yams Feb 07 '22 at 17:43