How can I open a browser intent and point it to a local url in Android?
am start -a android.intent.action.VIEW -d file:///data/local_page/index.html
Doesn't work. This only seems to work with http:// prefix.
Try adding the component part:
am start ... -n com.android.browser/.BrowserActivity ...
That made a local HTML file display in the browser for me, on Android 2.2 (HTC Desire) and 2.3 (Sony-Ericsson Xperia)
Try adding -t text/html
These are the filters the browser uses:
(Not sure what android:scheme="inline" is for... does anyone know?)
<activity android:name="BrowserActivity" android:label="#string/application_name" android:launchMode="singleTask" android:alwaysRetainTaskState="true" android:configChanges="orientation|keyboardHidden" android:theme="#style/BrowserTheme" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<!--
For these schemes were not particular MIME type has been supplied, we are a good candidate.
-->
<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="http"/>
<data android:scheme="https"/>
<data android:scheme="about"/>
<data android:scheme="javascript"/>
</intent-filter>
<!--
For these schemes where any of these particular MIME types have been supplied, we are a good candidate.
-->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:scheme="inline"/>
<data android:mimeType="text/html"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
<data android:mimeType="application/vnd.wap.xhtml+xml"/>
</intent-filter>
<!-- We are also the main entry point of the browser. -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<!--
The maps app is a much better experience, so it's not worth having this at all... especially for a demo! <intent-filter android:label="Map In Browser"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.item/postal-address" /> </intent-filter>
-->
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme=""/>
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable"/>
</activity>
Related
Hi I'm trying to include the app-links as described here:
https://developer.android.com/training/app-links
Everything works fine with a single domain, but when I try to include multiple domains Android's system always shows the disambiguation dialog.
Is there any workaround to include multiple domains (not SUBdomains), in my manifest file avoiding to show disambiguation dialog?
Here my AndroidManifest.xml
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleInstance" android:name="MainActivity" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="exampl1.it" android:scheme="http" android:path="/applink"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="example1.it" android:scheme="https" android:path="/applink"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="p.example2.it" android:scheme="http"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="p.example2.it" android:scheme="https"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="example3.com" android:scheme="http" android:path="/path/to-deep"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="example3.com" android:scheme="https" android:path="/path/to-deep"/>
</intent-filter>
</activity>
See my answer at https://stackoverflow.com/a/60342565/2914140. I divided all <data> tags into attributes:
<data android:scheme="https" />
<data android:host="example.com" />
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="audio/*"/>
<data android:mimeType="text/plain"/>
</intent-filter>
This is not working in Oreo and the same code is working perfectly till android 7.0
Try adding two different intent filters, like:
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="audio/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Reference: https://developer.android.com/training/sharing/receive
I have to activities that i need to deep-link them to two URLS, but every time i click a URL it shows the two activities at the same time, so How can i set the intent-filter to only 1 specific URL ?
1st URL http://www.sample.com/newcars/models/33
and its activity
<activity
android:name=".ui.activities.NewCarModelEngineActivity"
android:label="#string/newCars"
android:screenOrientation="sensorPortrait">
<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="sample.com"
android:pathPrefix="/newcars/engines/"
android:scheme="http"/>
<data
android:host="www.sample.com"
android:pathPrefix="/newcars/engines/"
android:scheme="http"/>
<data
android:host="newengine"
android:pathPattern="/..*/..*/..*"
android:scheme="sample"></data>
</intent-filter>
</activity>
2nd URL http://www.sample.com/usedcars/engines/9876543
and its activity
<activity
android:name=".ui.activities.UsedCarEngineDetailsActivity"
android:label="#string/usedCars"
android:screenOrientation="sensorPortrait">
<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="sample.com"
android:pathPrefix="/usedcars/engines/"
android:scheme="http"/>
<data
android:host="www.sample.com"
android:pathPrefix="/usedcars/engines/"
android:scheme="http"/>
<data
android:host="usedengine"
android:pathPattern="/..*/..*/..*"
android:scheme="sample"></data>
</intent-filter>
</activity>
Try to put your scheme="sample" data in a separate intent filter. It seems like a bug, but sometimes Android just ignores the path prefix when another is present and empty or with wildcards.
You can also use host="*sample.com" to match both sample.com and www.sample.com.
Ex for your first activity:
<activity
android:name=".ui.activities.NewCarModelEngineActivity"
android:label="#string/newCars"
android:screenOrientation="sensorPortrait">
<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="http"
android:host="*sample.com"
android:pathPrefix="/newcars/engines/" />
</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="sample"
android:host="newengine"
android:pathPattern="/..*/..*/..*" />
</intent-filter>
</activity>
I want to open *.gpx files with my app. After some resource I placed these intent filters to my manifest file:
<!-- Intent-filter for Intents that contain the file suffix. -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<!-- For a path to be meaningful, both a scheme and an authority must be specified. -->
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.gpx"
android:scheme="file"/>
</intent-filter>
<!-- Intent-filter for Intents that contain a MIME type -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<!-- This is the original mimeType which was used when creating the file. -->
<data android:mimeType="application/gpx+xml"/>
<!-- Some apps (e.g. some versions of Gmail) use the file suffix as the mimeType! -->
<data android:mimeType="application/gpx"/>
</intent-filter>
<!-- Gmail sometimes uses some strange mimeTypes when opening attachments -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:scheme="content"
android:host="gmail-ls"
android:mimeType="application/octet-stream"/>
</intent-filter>
and it's works with the most of android versions and phones.
BUT as far as I know on the LG F70 with android version 4.4.2 and on the Huawei P8 Lite with android version 5.0.1 using the default file browsers it's not working. See the pictures:
Huawei P8 Lite:
LG F70:
Does anyone experienced this before? Do you have any idea which intent filter would I need?
Any answer would be really apprechiated!
Your second <intent-filter> should be meaningless on all devices, as you cannot have android:host without android:scheme.
Either:
Remove the android:host attribute, or
Move that particular <data> element into its own <intent-filter>, with a copy of the relevant actions/categories, and with an android:scheme of content
The difference between the two is whether you want to try handling application/octet-stream from any source (first bullet) or only from Gmail's content provider (second bullet).
You are on the right track there with your initial code. Here is how you can make it work:
<!-- Handle opening attachments with file explorer -->
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:mimeType="application/xml"
android:pathPattern=".*\\.gpx"
android:scheme="file"/>
</intent-filter>
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.gpx"
android:scheme="content"/>
</intent-filter>
<!-- Handle opening attachments with Downloads app -->
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.GET_CONTENT"/>
<action android:name="android.intent.action.OPEN_DOCUMENT"/>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:mimeType="application/xml" android:pathPattern=".*\.gpx"
android:scheme="content"/>
<data android:mimeType="application/octet-stream" android:pathPattern=".*\.gpx"
android:scheme="content"/>
</intent-filter>
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.GET_CONTENT"/>
<action android:name="android.intent.action.OPEN_DOCUMENT"/>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:mimeType="application/xml" android:pathPattern=".*\.gpx"
android:scheme="file"/>
<data android:mimeType="application/octet-stream" android:pathPattern=".*\.gpx"
android:scheme="file"/>
</intent-filter>
<!-- Handle opening attachments with Gmail -->
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.GET_CONTENT"/>
<data android:host="gmail-ls" android:mimeType="application/octet-stream"
android:scheme="file"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.GET_CONTENT"/>
<data android:host="gmail-ls" android:mimeType="application/octet-stream"
android:scheme="content"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.GET_CONTENT"/>
<data android:host="gmail-ls" android:mimeType="application/xml"
android:scheme="file"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter android:priority="100">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.GET_CONTENT"/>
<data android:host="gmail-ls" android:mimeType="application/xml"
android:scheme="content"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
The key here is to handle proper MIME types and categories, and presume various ways of opening files on devices (i.e. file browsers, downloads app, gmail, etc.).
I want to download files from browser through my application. I am trying to list my app in complete action using dialog. It shows for other action like view files, etc but in case of download files it doesn't show in dialog. how can i list my app like in the image?
I have used these filters in my activity
<intent-filter> <action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.OPENABLE"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="*/*"/>
I have done this by adding these filters and now it's working for all cases.
<intent-filter>
<action
android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.DEFAULT"/>
<category
android:name="android.intent.category.LAUNCHER"/>
<category
android:name="android.intent.category.BROWSABLE"/>
<category
android:name="android.intent.category.APP_BROWSER"/>
<category
android:name="android.intent.category.NOTIFICATION_PREFERENCES"/>
</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="googlechrome"/>
<data
android:scheme="http"/>
<data
android:scheme="https"/>
<data
android:scheme="about"/>
<data
android:scheme="javascript"/>
</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="googlechrome"/>
<data
android:scheme="http"/>
<data
android:scheme="https"/>
<data
android:scheme="about"/>
<data
android:scheme="content"/>
<data
android:scheme="javascript"/>
<data
android:mimeType="text/html"/>
<data
android:mimeType="text/plain"/>
<data
android:mimeType="application/xhtml+xml"/>
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.VIEW"/>
<category
android:name="android.intent.category.DEFAULT"/>
<data
android:mimeType="multipart/related"
android:scheme="file"/>
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.MEDIA_SEARCH"/>
<category
android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action
android:name="android.speech.action.VOICE_SEARCH_RESULTS"/>
<category
android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter
android:priority="-101">
<action
android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category
android:name="android.intent.category.DEFAULT"/>
<data
android:scheme="http"/>
<data
android:scheme="https"/>
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.SEARCH"/>
</intent-filter>
<intent-filter>
<action
android:name="com.sec.android.airview.HOVER"/>
</intent-filter>
add these two tags inside your <intent-filter> tag
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
add this code in your manifest inside your launcher activity tag.
<activity
android:name=".YourActivity"
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" />
</intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</activity>
Try downloading the files using the API http://developer.android.com/reference/android/app/DownloadManager.html