Receive android internal intent Broadcast - android

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...

Related

prevent the app to be displayed in ( open as dialog ) for specific keywords in url using manifest intent filter

Right now in my manifest code I have
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter
android:autoVerify="true"
android:label="#string/app_name" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:scheme="http" />
<data
android:name="default-url"
android:host="#string/bc"
android:scheme="#string/bc" />
</intent-filter>
which allow the user to get open with dialog if he click on URL that start with domain of my application for example: pop-up dialog to select the app
and its working fine, however, I'm facing an issue when the user request forgets password he receives a link on his email to reset his password.
the link he received is like this: www.domain.com/forget_password/email.
what I want is to keep the app link working but if the domain contains /forget_password open the browser by default, not the application.
Sorry, there is no "exclude" logic in <intent-filter>. You cannot create an <intent-filter> that says "I accept everything except this".
You will need to handle the forget_password path in your app, perhaps by launching a Web browser yourself.

How to launch the app from SMS content (link)

i need to launch my app when click on link that is received by sms or email.I mean, the person who receives the SMS simply taps on the link provided, and that launches the application.
Which ever Activity you want to open, when Link is clicked
Need to be use IntentFilter in Menifest like this
<activity
android:name=".interacting.InteractWithApps"
android:parentActivityName=".index.IndexActivity">
<intent-filter>
<data
android:host="www.domain.com"
android:scheme="http" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
You also need to define link schema and host
You should follow as per this link

Android Contacts Plugin or option

I need an option say "Chat with this Contact" included in the options list when you click Contacts in Android and then select options.
Basically what I want to find out is if I can link my application feature say chat directly with the contacts menu in Android? Are there any examples for that?
I don't think we can do that. The options we see on pressing the hard option key ( or soft one on recent handsets) are generated from either xml or by programatically. They are not some kind of a global properties to be set (kind of like Blackberry apps). So, NO...
If you want to send user to your chatting/communication application, you can do that by registering the android.intent.action.SENDTO and/or android.intent.action.SEND intent filters with your activity.
Here's how I did it.
<activity
android:name=".EventCreaterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<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" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
If you set these intent filters appropriately, on clicking any contact user will get a prompt to chose between the default messaging application and your application which, I think, fairly serves your purpose.

How can I add my application to the android default Dialer selection?

My Question is how can I add my application to the android default Dialer selection, to be more specific without using the android.intent.action.CALL_PRIVILEGED?
Now I am using this code below, this works fine:
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
HOWEVER Google recently posted: http://productforums.google.com/forum/#!topic/mobile/wXqnbynsL8Y
And mailed this to the programmes who does use the intent android.intent.action.CALL_PRIVILEGED:
Issue:
Users of your application may not be able to make emergency
phone calls through the system phone dialer if they've elected to have
your application route calls. As noted in the documentation,
applications that listen for the CALL_PRIVILEGED Intent action will
intercept emergency service calls from the system, but may not be able
to route them properly. Please note that CALL_PRIVILEGED is a
restricted API, not intended for use within third party applications
that cannot route emergency calls properly.
Solution:
• Remove CALL_PRIVILEGED from Intent filters in Java code and AndroidManifest.xml.
• Update your Google Play listing
description to include a statement that using your app as a default
dialer may interfere with dialing 911 emergency services.
The easiest solution my be deleting but then the application would use functionality. But is there another way to add the application to the default Dialer selection? but then without the CALL_PRIVILEGED intent?
Thanks in advance
Just an example of the default Dialer selection
Edit:
My other intents that I use:
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
More important is that privileged call action is needed in intent filter with data as "tel" for uri.
Also below permission tag is need to allow phone call.
Missing in your code in category Launcher.
<uses-permission android:name="android.permission.CALL_PHONE" />
You don't need to intercept CALL_PRIVILEGED to make a dialer. There are 3 intents of interest:
ACTION_DIAL: invokes the dialer. You should intercept this.
CALL: places a call. I suppose you need to intercept this if you are routing the call via VoIP, else just pass it on to the system.
CALL_PRIVILEGED: places an Emergency call (911 in US etc). You don't need to intercept this, since these calls are routed specially, even without a SIM card, and without charging the user.
For what it's worth, I got the same email from Google. My app doesn't even use CALL or CALL_PRIVILEGED intents. There was however, a check in the code that the passed intent was not this action (just for the sake of completeness). So, I think they just scan the data section of the apk to see if this string is used anywhere.
Edit try this, it works for my app:
<activity android:name=".ActivityName"
android:label="#string/activity_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias android:targetActivity="fully.qualified.ActivityName"
android:name="fully.qualified.ActivityName_HTC_hack"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity-alias>
Try "android.intent.action.DIAL". The user has to start the call manually, but i think it's the best solution.
Input: If nothing, an empty dialer is started; else getData() is URI of a phone number to be dialed or a tel: URI of an explicit phone number.
ref: developer page

Android, How to add my application to appear when user clicks on an e-mail address

Using Android, when I click on an e-mail address in my default browser, a menu list pops up with Gmail, (an built-in email client), and K-9 (another e-mail application).
I would like to add my android application to appear in this list. Is this possible and how do I do this?
add this intent-filter to your activity in manifiest:
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
You need to create an IntentFilter this requires both Java code, where you create an Activity that is triggered when the system notifies someone is trying to send an email, and changes to your AndroidManifest where you subscribe to the Intent action. Here is an SO Post that explains which intent filters you need: android intent-filter to listen for sent email addresses?
You add these to your Activity entry in your AndroidManifest and then when someone clicks an email it'll show your app. when someone clicks it, it'll open that specific Activity you are going to want to read about pulling data out of intents. Specifically you'll want to pull out: http://developer.android.com/reference/android/content/Intent.html#EXTRA_EMAIL from the extras.
Read about intent-filter here:
https://developer.android.com/training/sharing/receive.html

Categories

Resources