Cannot download unknown extensions - android

I cannot download (from web & from e-mail) unkwown extentions such as (*.ini, *.zip, *.ddd)
unless there exists an app that can understand the extention.
For example, I couldn't download *.ini file from the browser (or email) until I downloaded 'Astro' app.
How can you by pass so that they are downloadable?
How can you register your app to understan certain extention so that it can be downloadable?

How can you by pass so that they are downloadable?
You don't.
How can you register your app to understan certain extention so that it can be downloadable?
Ideally, you don't. You do it by MIME type. File extensions are very fragile. However, either can be achieved via the use of the <data> element in your activity's <intent-filter>. You will also want the BROWSEABLE category and probably the VIEW action.
For example, here is how you would arrange to be an option for viewing PDF files:
<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:mimeType="application/pdf" />
</intent-filter>

<activity
android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="file" />
<data
android:pathPattern=".*\\.ini" />
<data
android:host="*" />
</intent-filter>
</activity>
Above code allowed me to download *.ini files.
Thank you for your help.

Related

It is mandatory to specify the "android:host" for all url in android for Deep Link?

I have to filter two URL for an activity. I'm using Deep Links to App Content by specifying a url for the Deep Link Screen.
These are my urls
appdemo://deeplink
native://
I'm already added these two scheme to my Android Manifest file, looks like
<data android:scheme="appdemo" android:host="deeplink" />
<data android:scheme="native" />
my question is that, by providing scheme and host on the Android Manifest file, native:// this link does not work. it requires the android:host name also
(native://deeplink).
It is mandatory to specify the "android:host" for all url in android?
If no, how can i specify the different scheme.
The idea beside deep links is to use the same structure as normal links:
scheme://host/path
The main benefit is that you can teach your app even to open some Internet links, e.g. to open youtube (Android will ask, if you want to open in browser or YouTube app or your app):
<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:host="youtube.com"/>
<data android:host="www.youtube.com"/>
<data android:host="m.youtube.com"/>
<data android:host="youtu.be"/>
<data android:pathPattern=".*"/>
</intent-filter>
So, answering your questions:
Yes, it is mandatory to specify both scheme and host.
A good practice of handling two different links in one activity is to use different paths. Like this:
<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="appdemo" android:host="deeplink" android:pathPrefix="/path1/"/>
</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="appdemo" android:host="deeplink" android:pathPrefix="/path2/"/>
</intent-filter>
Then you can get your path in onNewIntent:
Uri data = intent.getData();
String path = data == null ? null : data.getPath();
...and build some logic depending on this path.
The above answer is acceptable and, in my case i want to navigate a new activity through this intent filter, and i got some information to the above answer and made some changes in my code and fix the issue.
Also I'm not specifying the host name for my second intent.
<activity
android:name=".DeepLinkActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Launcher">
<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="appdemo" android:host="deeplink" />
</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="native" />
</intent-filter>
</activity>
Now my both url navigate to DeepLinkActivity.
appdemo://deeplink
native://
Do you think this is not an optimized way?
Any other suggestions for that please mention.

Discarding deep link if it contains specific path

I have an implementation of deeplink in my manifest which is working fine
<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="blablabla.com"
android:scheme="https" />
<data
android:host="${applicationId}"
android:scheme="bla" />
</intent-filter>
I am wondering is there any way to NOT ACCEPT a deep link URL if it contains a specific path? E.g. Do not accept (don't open the app) if blablabla.com/specificPath but do accept any other paths with the same hostname.
Android Deep Links does not provide a way to explicitly exclude URLs, the best practice is define specifically the urls that you want to access to your app using deep Links.
In this case to access URLs like :
www.blablabla.com/specificPath
www.blablabla.com/specificPath/
www.blablabla.com/specificPath/default.aspx
www.blablabla.com/specificPath/other/
You will define the configuration of your intent filter using android:pathPrefix as:
<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="blablabla.com"
android:scheme="https"
android:pathPrefix="/specificPath" />
</intent-filter>

Missing URL error on VIEW Intent filter if I specify mimeType for action PICK

I have an app that could view different kinds of video files using intent filters from different sources. To allow the app to appears always as choice when I try to open whatever video file, I have placed this code in the manifest
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.PICK"/>
<data android:mimeType="video/*" />
</intent-filter>
So I can receive the Uri in the app handling It in the main activity.
Although everything seems working as supposed, every time that I try to edit the manifest Android Studio marks all intent filter code with a red underline reporting the error missing url.
The error disappears If I remove <data android:mimeType="video/*" /> but If I do this the app appears as choice not only for video files.
The guys at Google seem to like hinting rather than answering questions deep-linking.
It is important to specify the schema correctly. For files in older versions it is "file", in newer versions of Android it is "content". For links, these are http and https.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="application/octet-stream"
android:pathPattern=".*\\.ext"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="application/octet-stream"
android:pathPattern=".*\\.ext"
android:scheme="content" />
</intent-filter>
#AndreaF I have tha same issue. You can just suppress this warning.
To suppress try this:
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.PICK"/>
<data android:mimeType="video/*" />
</intent-filter>
add xmlns:tools="http://schemas.android.com/tools" to your initial manifest tag if it's not already there.
Prompt missing url not because action.PICK, the error related to action.VIEW
<intent-filter>
<action android:name="android.intent.action.VIEW"/> //delete this line
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/> //add this line
<category android:name="android.intent.category.OPENABLE"/> //and this
<data android:mimeType="video/*" />
</intent-filter>
for action.VIEW,you could define a different intent-filter.

Android Deeplinking not working with multiple schemes

I am stuck with the following scenario. I defined the following deep link intent filters in the AndroidManifest.xml
Expected behavior is when I found a url of format http://​www.domain.com/a/blabla or when there is link in SMS/eMail of format domain/xyz the system should trigger my activity.
Case #1: Working fine
<activity
android:name=".MYActivity">
<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="xyz"
android:scheme="domain" />
</intent-filter>
</activity>
Case #2: Working fine
<activity
android:name=".MYActivity">
<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="www.domain.com"
android:pathPrefix="/a"
/>
</intent-filter>
</activity>
Case #3: NOT working
<activity
android:name=".MYActivity">
<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="xyz"
android:scheme="domain" />
<data
android:scheme="http"
android:host="www.domain.com"
android:pathPrefix="/a"
/>
</intent-filter>
</activity>
Any suggestions/points/help is really appreciated
I placed both the deeplinks in two different intent filters and it worked!!!.
See the documentation of <data>: it states that:
All the <data> elements contained within the same <intent-filter> element contribute to the same filter.
Hence
<intent-filter>
<data
android:host="xyz"
android:scheme="domain" />
<data
android:scheme="http"
android:host="www.domain.com"
android:pathPrefix="/a" />
<intent-filter>
is interpreted equivalently as (not real code)
<intent-filter>
<data
android:host="xyz"
android:scheme="domain"
android:scheme="http"
android:host="www.domain.com"
android:pathPrefix="/a" />
<intent-filter>
which clearly has some contradictions, for example host being xyz VS www.domain.com.
From Android official documentation site :
Although it's possible to include multiple elements in the same
filter, it's important that you create separate filters when your
intention is to declare unique URLs (such as a specific combination of
scheme and host), because multiple elements in the same intent
filter are actually merged together to account for all variations of
their combined attributes.
You will have to create separate intent-filters.
Slightly off topic but relates the the OP question above with extra information that might help someone else.
If you have intent filters with deeplinks across multiple manifests and want to merge them without overriding each other you can add a unique android:label on your <intent-filter>.
Example:
main/AndroidManifest.xml
(These deeplinks are available to all app flavours, debug, prodcution etc)
<intent-filter android:label="main_deeplink1">
<data
android:host="domain.com"
android:scheme="https" />
<intent-filter>
debug/AndroidManifest.xml
(These deeplinks are available only to the debug build flavour)
<intent-filter android:label="debug_deeplink1">
<data
android:host="dev.domain.com"
android:scheme="https" />
<intent-filter>
The merged Manifest file will now contain both deeplinks without overriding each other.
Here is the tutorial I hop it helps
Tutorial link

Application appears in the “share” list ANDROID

How can I do that my application appears in the “share” list of another application? For example, I want to choose a pdf file and send it to my application.
I can’t find the solution, any idea?
Thanks
You can add an intent filter in your AndroidManifest.xml
for example for a pdf you can indicate the mimeType application/pdf.
<activity name="package.name.MyActivity">
<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:mimeType="application/pdf" />
</intent-filter>
</activity>
Look at the documentation at http://developer.android.com/guide/components/intents-filters.html#Receiving

Categories

Resources