Get number from dial in Android? - android

I am working on an application in which I have to make call from my application using my PHP server.
I have a condition in which, whenever user presses the Green call button of Android Device and after dialing number, I have to give user an option to call from my App or normal SIM. I have done that too.
Now I want to get the number which I have dialed on the dialer before switching to the application.
Means if User selects my application to call then I must have number dialed on the phone Dial.
I am using the below code to generate the pop up to use my application for calling. The code is written as Intent filter in my manifest inside the specific activity.
<activity
android:name="com.tv.longdistcall.PlaceLongDistCall"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Please suggest me, how to get the number dialed on the dialer before switching to the activity.

You need to create a new BroadcastReceiver with NEW_OUTGOING_CALL intent filter. This receiver intercepts every call to CALL_PRIVILEGED or CALL actions on the device regardless of what app is the one targeted.
The destination number can be found on the receiver's intent extras in Intent.EXTRA_PHONE_NUMBER.

Related

BroadcastReceiver for contact viewing

I'm trying to design a broadcast receiver for contacts, means it opens my app when other apps or the user wants any contact details. is there any means to do it(i didnt find it in intent filter). or i have to design my own?
basically when any app is trying to access a contact, that request goes through my app. it is just like BroadcastReceiver for change detection in contacts, I want it for when app wants to access a contact.
What you should do:
BroadcastReceivers are not designed for getting info back, instead you can implement a pattern just like the Contacts APIs do it, by implementing your own ContentProvider.
Create a ContentProvider in your app, to allow other apps to query on your ContentProvider just like they do on the Contacts ContentProvider.
See tutorial.
You need to design how you want your content uris to look like, for example:
vnd.android.cursor.item/my_app/contact to get info about a single contact
And you should also consider adding custom permission to your <provider> in your manifest, so also permitted apps can access your data.
Original Answer:
If you already have an Activity for viewing a contact, in your AndroidManifest, add the following intents:
<activity
android:name="..."
...>
<intent-filter>
<action android:name="com.android.contacts.action.QUICK_CONTACT" />
<action android:name="android.provider.action.QUICK_CONTACT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/contact" />
<data android:mimeType="vnd.android.cursor.item/person" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/person" />
<data android:mimeType="vnd.android.cursor.item/contact" />
<data android:mimeType="vnd.android.cursor.item/raw_contact" />
</intent-filter>
</activity>
You'll need to properly handle incoming intents with those mimetypes and data uris in your Activity.
You can an example in the Android system Contacts app manifest: https://android.googlesource.com/platform/packages/apps/Contacts/+/master/AndroidManifest.xml#307
You can test your implementation by adding a widget called "Contact 1x1" (the name may vary depending on the device) to your homescreen, and selecting which contact the widget should launch.
When clicking this widget it should call one of the above intents.

Receive android internal intent Broadcast

What happens when we click the default message app in android.I mean does it broadcast an intent? Actually I am trying to make an app that will ask for a password in an new activity when user clicks on message icon and is redirected to list of messages only if password is correct.But my activity is not shown.Here is how I am trying to do it.Added a receiver in manifest.
<receiver android:name="Receiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.GET_CONTENT">
</action>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType = "vnd.android-dir/mms-sms" />
</intent-filter>
</receiver>
You are asking about "launching" an activity. Typically that is done with an intent created as such:
Intent launch = new Intent(Intent.ACTION_MAIN);
launch.setPackage("com.your.package.name");
startActivity(launch);
Because the package name is set, you cannot intercept this intent. It is not broadcast to any receiver.
If you write a launcher app, you could intercept such a launch request and launch a different app in front of it. But it would not really be possible to prevent users from side-stepping this by returning to the default Android launcher.
However, there are several other means of "launching" the "default" SMS app. For example, an app that requests an SMS be sent through the default SMS app will create an intent like this:
Intent launch = new Intent("android.intent.action.SENDTO");
There are several others as well. And your app can register an activity for these intent in the manifest like this:
<activity
android:name="com.your.package.name.MyMessageActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android-dir/mms-sms" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
In Android KitKat a user must actually set your app as the "Default SMS App" in order for it to be able to write to the SMS provider/database and also to receive the "SMS_DELIVER" intent. In all versions of Android, any app can register for the "SMS_RECEIVED" intent but in KitKat+ it cannot be aborted, like in earlier versions.
You may notice that one filter specified above is similar to yours - using mimeType "vnd.android-dir/mms-sms" as a "DEFAULT" action. This places your app as one option for the user to "Complete Action Using" when, for example, they select a contact they want to message.
If you do all of this, then your activity can require a password in order to "view" messages. However, you should be aware that unless you are using a separate data store for the messages, all SMS can be read through the MMS-SMS provider (assuming the app has requested permission to do so).
What you are trying to achieve is not possible, please see this:
https://stackoverflow.com/a/21469133/2452039
You cannot prevent native applications from opening with an outside app. The only thing you could do would be to intercept incoming messages, preventing them from reaching the SMS app inbox, and store them in your application, and there you could prevent them from opening. I must warn you that since API level 19 that is no longer possible...

Intent filter data attribute parameters for dialer integration

I created a dialer for android. I integrated it with default dialer. Whenever I click call I get complete action using dialog. My App is fine till this point.
I want my app as one of the complete action using options only when the number being dialed is 10+ digits
Now what I want is to avoid some numbers like USSD codes, premium number etc, which can be in user's contact book. So Whenever user clicks on call USSD codes or premium numbers from dialer, I don't want my app as one of the options. How to set intent filter for this. I am assuming my filter has to be in the manifest.
My app should show up only when the number being dialed is 10+ digits
I have found examples for mime type, URLs, but could not find any example for dialer.
here is my manifest entry for activity
<activity android:name=.ActivityCallMore"
android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<!-- <action android:name="android.intent.action.VIEW" /> -->
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Thanks in advance.
Sorry, I don't think this can be done.
I imagined that it would be something like
<data android:pathPattern="...........*" />
but http://developer.android.com/guide/topics/manifest/data-element.html points out that pathPattern is
meaningful only if the scheme and host attributes are also specified for the filter.
and there is no host to specify in a tel://0123456789 URI. A similar problem is listed as a "medium priority defect" since 2009 at https://code.google.com/p/android/issues/detail?id=3368.
Let's hope someone else can prove me wrong.

What is the Intent that needs to be filtered to show a call log

I have an application that has an activity that acts a s a call log, I want the user to be able to decide whether to use the stock android one or use ours. I can't seem to find which intent filter to set up for my activity in the manifest such that our app is listed in the chooser after a call is made and so that it can be set as a default if they wish.
Set <data> mimeType to vnd.android.cursor.dir/calls
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="vnd.android.cursor.dir/calls" />
I know this will prompt the user with a chooser after an outgoing call is terminated.

How can I start the next matching activity if my app is the default one

I have an activity that works as a hook for various intents. Specifically, the VOICE_COMMAND and CALL_PRIVILEGED. (It is a requirement to use these.)
<activity android:name=".MyActivity"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
I ask the user to set my app as the default action for these intents so they don't have to select it every time. This is also a requirement.
The problem is that in certain cases I want my activity to work transparently and pass the intent to the dialer or other app. This should be selectable by the user. I achieved this by using getPackageManager().setComponentEnabledSetting(myCompName, isEnabled, PackageManager.DONT_KILL_APP) on my activity in certain places of the code.
Is there a more elegant way to do this? I tried startNextMatchingActivity(getIntent()) but that does not start anything (returns false). Does this mean that if there is a default action, then everything else is ignored from the intent resolution?
Currently (on Android 2.3) there seems to be no other way of forwarding the intent than doing it manually. Additionally, to send CALL_PRIVILEGED intent the app must have special permissions that only system apps have. (The app will receive not allowed exceptions otherwise.)
All in all, the intent must be converted to some other intent that my app can send and start the next activity manually by retrieving the list of applicable activities from the PackageManager.queryIntentActivities() API.

Categories

Resources