Is it going to be an Android service? - android

I am new in Android Development. I want to create an application which would add a prefix to a calling number and this decision will depend on some parameters.
I want an user to be aware of it but doesn't have to do anything about it, meaning once the application is installed and an user wants to call, they'll just see that a prefix is going to be added to a number they are calling.
The question is not how to do adding a prefix to calling number (although, that's also what I want to know, but I have found an article about it), but rather:
1) is it going to be a service?
2) is it possible to change a calling number by adding a prefix to it and show a changed number to an user so that they don't have to do anything about it (like pressing "yes","no" to accept this)?

You should register for Intent.ACTION_NEW_OUTGOING_CALL
Broadcast Action: An outgoing call is about to be placed.
The Intent will have the following extra value:
EXTRA_PHONE_NUMBER - the phone number originally intended to be
dialed. Once the broadcast is finished, the resultData is used as the
actual number to call. If null, no call will be placed.
It is perfectly acceptable for multiple receivers to process the
outgoing call in turn: for example, a parental control application
might verify that the user is authorized to place the call at that
time, then a number-rewriting application might add an area code if
one was not specified.
For consistency, any receiver whose purpose is to prohibit phone calls
should have a priority of 0, to ensure it will see the final phone
number to be dialed. Any receiver whose purpose is to rewrite phone
numbers to be called should have a positive priority. Negative
priorities are reserved for the system for this broadcast; using them
may cause problems.
Any BroadcastReceiver receiving this Intent must not abort the
broadcast.
Emergency calls cannot be intercepted using this mechanism, and other
calls cannot be modified to call emergency numbers using this
mechanism.
Some apps (such as VoIP apps) may want to redirect the outgoing call
to use their own service instead. Those apps should first prevent the
call from being placed by setting resultData to null and then start
their own app to make the call.
You must hold the PROCESS_OUTGOING_CALLS permission to receive this
Intent.
This is a protected intent that can only be sent by the system.
Constant Value: "android.intent.action.NEW_OUTGOING_CALL"

Related

Android'd ForegroundDispatch for NFC

What is the purpose of foreground dispatch and how does it differ from adding intent-filters in the AndroidManifest? Currently I can read from and write to NFC tags and I haven't written any foreground dispatch code.
It mostly depends on your requirements. When you register an IntentFilter in the manifest, you specify an Activity that will be started and given the detected tag data in the Intent. This means that your app can be started at any time to handle the tag. For instance, the user can be on the launcher and hold a tag to their phone, and have your app as an option to handle the NFC detection event.
However, assume you have a scenario where it only makes sense to detect the tag while your application is in the foreground. For instance, maybe your app requires the user to be logged in in order to do something with the tag data. In that case, you can use the foreground dispatch mechanism, and start it from any of your Activity classes to receive a result only when your app is active.
It's quite similar to BroadcastReceivers, which can also either be something dynamically registered, or specified in the manifest. In the former case, the lifecycle of the receiver is under your control. In the latter case, you're saying that your app may be started at any time.

Android Block All Numbers Except Whitelisted

I would like to block all numbers except for a select few whitelisted numbers on my Android phone.
In the Android docs I see that there is an API for blocking specific numbers. I was wondering if there is a similar more broad API which rejects all incoming communication unless a number is whitelisted.
Or perhaps an intent I could hook an app up to which would screen each number before ringing the phone.
Use a broadcast receiver to get the state when incoming call is coming.
Then in that event get the number of the caller.
Match the number with your list of numbers,if it equals your whitelisted one allow else disconnect the call programmatically.

BroadcastReceiver which allows call to proceed, but prevents other receivers from processing it?

I have an App which is a BroadcastReceiver and which processes NEW_OUTGOING_CALL intents. There are also other apps on my phone that are registered as receivers for these intents, but mine is registered with a higher priority intent filter, so my BroadcastReceiver gets to see the intents first.
I would like to programmatically be able to prevent any other registered BroadcastReceiver for NEW_OUTGOING_CALL from processing these intents, but I would like to allow the phone call to proceed. Is this possible?
I don't think you can actually do what you want to do. The documentation for this action describes pretty clearly how the system expects this broadcast to be handled:
For consistency, any receiver whose purpose is to prohibit phone calls should have a priority of 0, to ensure it will see the final phone number to be dialed. Any receiver whose purpose is to rewrite phone numbers to be called should have a positive priority. Negative priorities are reserved for the system for this broadcast; using them may cause problems.
If you want to see the number first, you can do that (with a higher priority), but then you have to live with other receivers seeing it after you do. Alternatively, you can see the number last (by lowering your priority to 0), but then you have to live with other receivers seeing the number before you do.
Note that another person suggested aborting the broadcast. Not only does this not make sense since the system needs the result of the broadcast, it also is stated explicitly in the documentation not to abort this broadcast.
Any BroadcastReceiver receiving this Intent must not abort the broadcast.

What does enableForegroundDispatch and disableForegroundDispatch do?

I read the documentation and I don't quite understand what either do. Considering Android made the puzzling decision that we now need to use Android Beam to send data from 1 one phone to another and there is no way to simultaneously send data from both to both, I don't see the use.
Can't I just call setNdefPushMessage on one phone, and have an onNewIntent callback in the other phone which does something if NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()) is true?
What is the point of enableForegroundDispatch and disableForegroundDispatch?
enableForegroundDispatch gives your current foreground activity priority in receiving NFC events over all other actvities.
For instance, consider the following example:
Your activity and another activity (either from the same app or from another app) registered an intent filter for the same NDEF record type in the manifest.
Your device receives an NDEF message containing that record type as its first record.
If the current foreground activity did not register with the foreground dispatch system, an activity chooser will be shown and the user can choose between the two activites.
If the current foreground activity, however, did register with the foreground dispatch system (to receive that type of record), it will get priority over all manifest-registered intent filters and will receive the NDEF message without any additional user interaction.
Some more things:
The Android Application Record (AAR), if appended to an NDEF message, will have a similar effect as it will force the NDEF message to be delivered only to a particular app.
If an NDEF message contains an AAR for a different app, you could still use the foreground dispatch system to force delivery of the NDEF message to your app. So the foreground dispatch has priority over the AAR.
Note that the foreground dispatch system is not only used for peer-to-peer mode data exchange, but also for reading NFC tags. In that case, there exist tags that do not contain NDEF messages and are, therefore, significantly more likely to result into multiple activities being registered for the same tag type. Thus, in that case its again useful to give your activity priority over any other activities that are registered for the same tag type.

Are there any broadcast receivers to be able to tell when messages have been read?

I've written a program which uses Broadcast receivers to identify when certain events happen - e.g. new SMS/MMS message, missed call and new gmails.
When the broadcast receivers are triggered I'm setting variables to store the new states that have happened. What I'm looking for is a way to be able to change the setting upon the user seeing these messages - i.e. viewing the SMS, reading the e-mail or viewing the call log - or once they've clicked on the notification. Are there any broadcast receivers to be able to do this, or is there another way?
I ideally want to avoid having to poll for these changes and want to reflect the changes when they happen. Even if polling I'm not sure what I'd look for to see when a user had viewed the call log - for the others I can see how I could use the content provider to handle them.
if i remember well , registerContentObserver(Uri.parse("content://mms-sms"),true,m_MMSObserver)
return something every time something is modified in the database (either adding line or modifying a line) , it should do the trick

Categories

Resources