Block incoming calls vs a system service - android

I wrote an application which has the capability of hanging up phone calls when they are received. In order to that I'm using the telephony manager and this permission is required:
android.permission.MODIFY_PHONE_STATE
However, this permission makes my app a system app and therefore I won't be able to place it in the play store later.
But I've seen apps in the play store that successfully block incoming calls ("Calls Blacklist" for example).
I wonder, does anyone know what API these apps are using in order to block an incoming call and also allow these apps in the play store ?
Thanks.

You need to make use of Broadcastreceiver class.
and also need to add this line in manifest to get persmission.
<uses-permission android:name="android.permission.READ_PHONE_STATE">
follow this.
http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
Make sure TelephonyManager.CALL_STATE_RINGING is only incoming call.
You cannot detect outgoing call state whether it is ringing or answered.
for outgoing there only two states:
TelephonyManager.CALL_STATE_IDLE
&
TelephonyManager.CALL_STATE_OFFHOOK

Related

Android: which api to use to record all incoming and outgoing call (Since in changelogs Android blocked call recording)

Is there is api where i can record all the incoming and outgoing call in android pie version . It seems nearly impossible to record a call. Please suggest what can be done in this scenario
Android disabled the api with their security update policy. Looking at the permissions list the closest you can find is the MANAGE_OWN_CALLS, meaning that the best solution for you is to implement a standalone application for calling where you should be able to interact with microphone directly.

Alternative to READ_PHONE_STATE permission for getting notified of call

I'm currently using the READ_PHONE_STATE permission in Android to pause my media player when there's a call, and to resume playback when the call is over. The permission seems to scare a lot of people, so I was wondering if there was an alternative to catching the starting and stopping of a phone call without it. Any help is appreciated. Thanks!
If you want to adjust your audio output in response to something else wanting to perform audio output (e.g., an incoming phone call), look into Android's audio focus support.
READ_PHONE_STATE, as noted, is a bit of a scary permission. Moreover, it only deals with phone calls, and not other things that might need the same capability (e.g., VOIP calls, as AFAIK those don't tie into READ_PHONE_STATE-enabled stuff).
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.

Android app in unrooted phone and telephony API usage

Is it possible using the telephony (or other) APIs on an unrooted Android phone, for an application to listen for the Telephony intents (ringing / Incoming-call), and if calling party matches a criteria (such as, from a black-list), disconnect the call, without requiring a confirmation by the user ?
Also, it is possible for an application on such (an unrooted) Android phone to initiate an outgoing call without user's intervention (s.a. at a particular time or when certain conditions are met) ?
In my research so far, I've found that I'd have to use a BroadcastReceiver with the right priority, to be able to "trap" the 'ringing event', and use ITelephony.aidl to reject the call. However, it wasn't clear if I can do the latter on an unrooted phone or not.
For the second requirement, it is not clear if app can make an going call -- again, on an unrooted Android phone.
Is it possible using the telephony (or other) APIs on an unrooted Android phone, for an application to listen for the Telephony intents (ringing / Incoming-call), and if calling party matches a criteria (such as, from a black-list), disconnect the call, without requiring a confirmation by the user ?
You can easily get the state of the current call. However, hanging up yourself without user interaction is only possible through reflection.
Also, it is possible for an application on such (an unrooted) Android phone to initiate an outgoing call without user's intervention (s.a. at a particular time or when certain conditions are met) ?
You can dial a number without asking the user by using:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
Keep in mind that you must have the android.permission.CALL_PHONE permission, and that replacing ACTION_CALL with ACTION_DIAL will ask the user to confirm. ACTION_CALL places the call directly.

PhoneStateListener onMessageWaitingIndicatorChanged() not being called reliably

I have some code that detects when there is new voicemail. It's based on a PhoneStateListener.onMessageWaitingIndicatorChanged() implementation (so technically it fires only when the MWI indicator changes, not necessarily for every new voicemail).
It has been working perfectly for many months until 4.x.x updates to the devices.
Now, this works when the device is rebooted, otherwise its very unreliable. I can see the voicemail icon appear in the notification bar, but the debug logs in onMWIChanged stay silent.
I know that with 4.x.x there is a voicemail provider API. Thinking that this may have a connection, I added the android.intent.action.NEW_VOICEMAIL and android.intent.action.PROVIDER_CHANGED intents to my receiver, but they don't fire (in my BroadcastReceiver onReceive) either (my app's minSdkVersion is 8).
This is a post from Android Developers about the Android 4.0 APIs.
http://developer.android.com/about/versions/android-4.0.html
If you scroll down there is a section about Voicemail Providers where it explains:
Because the APIs currently do not allow third-party apps to read all the voicemails from the system, the only third-party apps that should use the voicemail APIs are those that have voicemail to deliver to the user.
However, I assume if you are trying to receive voicemails from a third party and not from your service then this still may be possible. Check out this link about VoicemailContracts where I believe it says you need the permission ADD_VOICEMAIL in your manifest to use the actions you are using above.
http://developer.android.com/reference/android/provider/VoicemailContract.html
There are also samples that I did not get a chance to look at called Voicemail Provider Demo in your SDK. I hope this helps.
It does require the READ_PHONE_STATE permission. Although, if it worked before you must of had it set.
See LISTEN_MESSAGE_WAITING_INDICATOR.

How to send fake call broadcast on android

I am trying to send a broadcast to simulate an incoming call.
I added the permission in AndroidManifest.xml file,
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
When I try to run the program, the phone reboots.(Emulator too).
Intent intent = new Intent();
intent.setAction("android.intent.action.PHONE_STATE");
intent.putExtra(TelephonyManager.EXTRA_STATE, TelephonyManager.CALL_STATE_RINGING);
intent.putExtra("EXTRA_INCOMING_NUMBER", "923982398");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendBroadcast(intent);
I may be wrong as I can't find anything in the docs but I'd say it's not possible to 'spoof' a call ringing broadcast. It's almost certainly reserved as 'system only'.
Think about it - if apps could do this, it may simply result in 'mischief' rather than anything malicious but it isn't something that I'd like to happen on my phone.
Create your own 'phone ringing' action to use for testing purposes and have your BroadcastReceiver listen for it. When you come to release the app then simply change the BroadcastReceiver's intent filter to listen for the real one.
I Downloaded some of the fake Caller Apps from play store and tested them.
I found that the App Raises an Event which displays the pre-mentioned GUI on the Top of Lock Screen and adds the entry into call logs using the insert method of ContentResolver.
The app does not use the inbuild Calling (Broadcast) mechanism. it just fakes the GUI on the Screen and plays the Default Ringtone/Vibration.
As per my Knowledge, I think it is not possible to fake a call ringing broadcast

Categories

Resources