How to respond to Home Clicks Android - java

I'd like to create an app that responds to home clicks (double-tap home clicks) and then can launch an app. I need the app to be constantly on, so I understand that I need it as a service... but I have not found a way to respond to home clicks and read/recognize them, is there any possible way that there is something like this in the API?
Thanks

The home-button is supposed to open the (a) launcher. You can define your app to be a launcher by Intent-Filter in the Android Manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The negative impact is that it always opens your app if you push the home button.

Related

How to open installed android application via browser in android?

I want to make my app to get opened when user enters particular url in the browser like chrome or internet.For this i have referred and googled about this topic what i noticed is similar and i have used in my manifest file but still doesnt work.
i have referred below links for my issue
Launching custom Android application from Android browser / Chrome
Launch custom android application from android browser
How to open android application when an URL is clicked in the browser
Intercepting links from the browser to open my Android app
All this have same answer but when i use this it has no effect,when i type url www.myurl.co.gdf or http://www.myurl.co.gdf it doesnt prompt the user it opens in browser itself instead of opening myapp or showing choose dialog box
the code i have used in manifest file is as follows
<application
android:icon="#drawable/logo"
android:label="#string/app" >
<activity
android:name="com.app.secondActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/service"
android:screenOrientation="portrait"
android:theme="#style/aa_theme" >
<intent-filter android:label="#string/app" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:host="www.myurl.co.gdf"
android:pathPrefix="/"
android:scheme="http" >
</data>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.VIEW" />
</intent-filter>
</activity>
<activity
android:name="com.app.firstActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/activity_title"
android:screenOrientation="portrait"
android:theme="#style/aa_theme" />
</application>
If this works fine for others why not for me?
Note:i have changed to above code only in manifest and i have not changed or added any thing extra in .java files or anyother files.
For this to work should i make any device setting changes or should i add Uri intentUri = getIntent().getData(); in .java file (should use then why?)or should i type differently in browser or have i used intentfilter in wrong activity or is there anything i am missing?
one more thing i am using some cordova plugins to this app, i dont think this has to do with opening an app.
I am very new to android please give me some ideas regarding this..
The issue isn't with your code- it is with your testing strategy.
Typing a URL in a browser does not typically start an Intent, and thus Android doesn't check to see if any other apps can handle the URL. When a user types a link into Chrome, for example, Chrome assumes that the user wants to continue using Chrome and will handle browsing to the URL itself.
Instead, you need to create an intent containing your URL to test if Android will handle deep links to your application correctly.
The easiest way to do so is via the following ADB command:
adb shell am start
-W -a android.intent.action.VIEW
-d http://www.myurl.co.gdf/

always start app from root activity

I have an activity for handling deeplink which is a browsable activity
suppose user clicks a link on another app and my browsable activity handles that intent
and start the app, then user minimise the app after use by pressing back button
if user reopen my app from running apps my browsable activity gets started instead of launcher activity
so my question is how can i start my app from launcher activity instead of browsable if user launches my app from running apps
Quora uses the same procedure, you can test by clicking a link of Quora on any other app
manifest of browsable activity
<activity android:name="com.example.android.deeplink"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:host="com.example"
android:scheme="test" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
class code for handling intent data
Uri link = getIntent().getData();
how can i start my app from launcher activity instead of browsable if user launches my app from running apps
There is more then one approach to achieve this goal,
I believe that the best and simplest way would be to add to your "browsable activity" an Activity flag:
android:excludeFromRecents="true"
settings this flag - will make sure that this activity will simply won't be shown in the recent tasks in the first place.
more info in the documentation - http://developer.android.com/guide/topics/manifest/activity-element.html#exclude

Launch an app from a link issue in Android

Suppose I have an app with the following intent filter in an activity in the AndroidManifest.xml file:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="blabla.com"
android:pathPrefix="/element/"
android:scheme="http" />
</intent-filter>
Of course it will cause my app to be launched from the browser, for example. However, when the user clicks on the link, it is asked to select the application for opening that link. If he/she selects a browser instead of my app and, in addition, he/she checks the "don't ask me again" check box, my app will never be launched!
Is there any way to avoid that?
Is there another kind of URI I can use to uniquely open my app? I have been looking for answers in StackOverflow but I have not found any good example of a non browsable URI for launching my app from a link.
Thank you so much,
Use an with a element. For example, to handle all links to twitter.com, you'd put this inside your in your AndroidManifest.xml:
<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.
Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:
<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, in your web app you can put links like:
<a href="my.special.scheme://other/parameters/here">
And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.
Use a custom scheme instead of http. Maybe, x-myapp
<data
android:host="blabla.com"
android:pathPrefix="/element/"
android:scheme="x-myapp" />
Have your blabla.com web server respond to http links (http://blabla.com/element/foo) with a redirect to x-myapp://blabla.com/element/foo for mobile android devices.....or put a link on the page that will have the x-myapp:// link for the user to tap
Now since your app is the only one responding to x-myapp://blabla.com/element/ links, you have avoided step 1.

Can you create an intent filter based on query?

I would like to have my application respond to the market link for my application. So the link is market://details?id=my.package.name. Now the reason I want this is so I can send out a link that will open the app if it is installed and open the market page if the application is not installed. The problem I am running into is that my application will respond to all market links and not just my applications link. The reason is the package name is defined in the query part of the Uri. Is there a way to filter an intent based on the query part of the Uri?
From Android API 19, you can do it, using ssp, sspPrefix or sspPattern. Example:
<intent-filter>
<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"
android:sspPrefix="//play.google.com/store/apps/details?id=com.example.test"
/>
</intent-filter>
With such filter, the OS will offer your app only for URLs with id=com.example.test parameter, and won't offer it when there is no such parameter. But this works only on Android 4.4+, older versions will ignore sspPrefix.
See also this article: https://chris.orr.me.uk/android-ssp-data-intent-filter/.
No, sorry, you cannot. You can constrain a filter based on everything to the left of the ?, but that's it.

Android Default Application open and close event

I need to capture device default application open and close events. as example when user open browsers I need to capture that event. is there any specific permission to capture it and good example?
You can use an intent-filter in your manifest. Read the manual here: http://developer.android.com/guide/topics/intents/intents-filters.html
or check this example I got from SO ( Android Respond To URL in Intent )
<intent-filter><action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.youtube.com" android:scheme="http"></data>
</intent-filter>
You don't need any special permissions by the way.

Categories