Open Android app from browser - java

I am trying to open an Android app from a browser. I have read several StackOverflow threads describing a solution to the problem and this is what I have so far:
AndroidManifest.xml
<activity
android:name="com.webviewtestapp.MainActivity"
android:label="#string/app_name"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="Testapp" android:host="launch"/>
</intent-filter>
</activity>
And this is the html <a href="Testapp://launch"> open testapp </a
I am using the Firefox browser in Chrome and clicking the link gives a message: Couldn't find an application to open this link
How do I fix this ?

Change:
<action android:name="android.intent.action.MAIN" />
to:
<action android:name="android.intent.action.VIEW" />

Related

PreferenceActivity subclass should not be exported in the manifest (ExportedPreferenceActivity)

Android Studio is throwing a lint warning saying
PreferenceActivity subclass com.myapp.app.SettingsActivity should not be
exported in the manifest
Inspection info:Fragment injection gives anyone who can send your
PreferenceActivity an intent the ability to load any fragment, with any
arguments, in your process. Issue id: ExportedPreferenceActivity
I've never actually noticed when this warning started appearing, but I can't find a way to fix it without breaking the activity. SettingsActivity is an AppCompatPreferenceActivity with two PreferenceFragments and gets created after a SplashScreen. I've tried setting android:exported="false" in my Manifest.xml already, but it gives an error because action.VIEW cannot have export turned off.
Relevant Manifest.xml code:
<activity
android:name=".SettingsActivity"
android:label="#string/app_name"
android:theme="#style/SplashScreen">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
</activity>
don't expose it with a launcher (which sounds alike what it complains about):
<category android:name="android.intent.category.LAUNCHER"/>
If possible remove:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
If you can't remove all of it just delete this line:
<action android:name="android.intent.action.VIEW" />

Android App does not open through schema (default/chrome browsers)

I have searched google every where to find a solution for 'Android App does not open through schema (default/chrome browsers)'. But I could not find a proper solution.
Below code set I added to Android Manifest.xml to link schema with browser.
<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="com.qa-soft.team" />
android:pathPrefix="/"/>
</intent-filter>
<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="com.qa-soft.team" />
</intent-filter>
but when I access ( com.qa-soft.team://OPENPDF-INDEX.pdf ) through default/chrome browser, it will be redirected to google search.
Anyhow when I access through firefox browser, it is working fine. (load the app activity)
what is the real issue for this and how can I overcome it?

Opening Android application from website not working

I want to implement such functionality in my simple Android app: when user visits a certain link (www.example.org let's say) in the web browser - Android OS should open my Android application if it is installed.
I tried to play with intent-filters like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<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="example.org"
android:pathPattern="/.*"
android:scheme="http" />
<data
android:host="www.example.org"
android:pathPattern="/.*"
android:scheme="http"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But it's not working at all in google chrome mobile browser. In firefox, when I visit that link I get such Android icon on the right side of the search bar:
When I press that icon - my app opens. But still it is not what exactly I want to achieve.
Any idea why my code above doesn't work? I tried many variations of intent-filter declarations which I found on internet but nothing seem to work. I have nexus 5 device with Android 6 installed.
I have found a solution to my problem. Whole internet is full of old examples.
Since chrome version 25, google made slight changes in app deep linking functionality. More info: https://developer.chrome.com/multidevice/android/intents
So my working code looks like this:
Intent filter in Android side:
<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="launcher"
android:path="/"
android:scheme="test" />
</intent-filter>
Web page html:
Launch app
Try it like this, removing the path pattern:
<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
More info:
Launch custom android application from android browser
<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="example.org"
android:scheme="http" />
</intent-filter>

Add my Android app to the "send via" menu

I use the OSMand Navi app. In there I want to click on a point a hit the Share button. Then there is a list of apps I can send the coordinates to.
I want my app being in that list. I read about it and added an <intent-filter> to my AndroidManifest.xml.
<application
<activity
android:name=".MyMainActivity"
android:label="My App" >
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
But my app is still not on the list. I even tried to reinstall it and restarted my phone.
"Share" is usually implemented via ACTION_SEND, not ACTION_GET_CONTENT.

URL intent for Android not firing

I've been learning Java for some time now to develop Android-apps. At this point, I want my website to redirect to my app. This should be possible using an Intent-filter for my website-url. I have used the stackoverflow.com homepage as example.
I use this code in a MainActivity section in the Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.example.webitent" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="http" android:host="stackoverflow.com"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
So far, nothing interesting. This is literally a blank activity in a new project with the intent-filter added. I have target-sdk 21 and minimal sdk 16. However, whatever I try, it doesn't fire when I go to stackoverflow.com, neither directly nor through a href.
What is going on, or what am I doing wrong?
When you visit stackoverflow.com in your browser, the intent is not fired. An intent is fired only if the app explicitly does that. This is the case if the app (your browser) is not supposed to open your url scheme. For example mailto is opened in your Mail-App. So you have to create your own URL-scheme like this
<intent-filter>
<data android:scheme="myweb" android:host="stackoverflow.com"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then a link to myweb://stackoverflow.com would open your app.

Categories