0

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

Community
  • 1
  • 1
allDroid
  • 395
  • 1
  • 7
  • 21

1 Answers1

0

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/
Bryan Herbst
  • 62,910
  • 10
  • 119
  • 113
  • creating an intent containing url is used if i want to open browser through app – allDroid Oct 23 '15 at 18:40
  • Intents are the mechanism by which Android starts *any* application. That is the only way your application will ever be started. – Bryan Herbst Oct 23 '15 at 18:42
  • my requirement is very similar to this http://stackoverflow.com/questions/21663001/launching-custom-android-application-from-android-browser-chrome – allDroid Oct 23 '15 at 18:45
  • While that may have been Chrome's behavior at one point, it no longer is. Do you have an example of an application exhibiting this behavior using the latest version of Chrome? – Bryan Herbst Oct 23 '15 at 18:48
  • no i dont have application exibiting this behavior but the above provide links in question does similar work and this has been implemented in ios there its working fine ,when url is typed in browser and pressed go it opens the app. – allDroid Oct 23 '15 at 19:07
  • That link is a year and a half old, and the first comment warns that not all browsers will use `ACTION_VIEW` with URLs typed into the browser, which is exactly what I am warning you about. The example provided (StackOverflow) no longer works. iOS is a different operating system, and what works there is not guaranteed to work on Android. – Bryan Herbst Oct 23 '15 at 19:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93206/discussion-between-berry-and-tanis-7x). – allDroid Oct 23 '15 at 19:26
  • i am able to achieve this in opera and firefox browser but not in default browser internet explorer ,if possible can u give any idea on this – allDroid Oct 24 '15 at 08:43
  • You can't control the behavior of other applications. If some browsers don't launch an Intent with `ACTION_VIEW` when you type in a URL, they simply won't support what you want. – Bryan Herbst Oct 24 '15 at 13:05