I realised an app that read QR code and display result in a modal (then, redirect on a WebView if result is an URL). It works well.
But now what I'd like to do is : When a QR code is scanned with the camera of my device (not my app), then it launch my app and display the result in my modal.
I used intent-filter to do this... And it works well too ! But the problem is that it launchs my app not only if a QR code has been scanned. It launchs my app, for example, when I click on a URL on my phone. And that's not the behavior that I want. I'd like that it starts my app only when a URL has been detected from a QR code. Is it possible ?
Here is my Manifest
<activity
android:launchMode="singleTask"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<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.nfc.action.TECH_DISCOVERED" />
</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="http" android:host="*"/>
<data android:scheme="https" android:host="*"/>
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter" />
</activity>
In order to open your app just for QR code, you'll need to specify custom data schema for your app instead of http and https:
<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="myCustomSchemeName"/>
</intent-filter>
Then QR codes with myCustomSchemeName://openSomething?param=42 will open in your app.
Related
I want to listed my app in app chooser dialog (like google, Mozilla are shown in chooser dialog when we click on any link) and it was perfectly work but when i click in any link from youtube it does not show my app in Android chooser dialog.
My manifest file code is :-
<activity
android:name=".mvp.BroswerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateAlwaysHidden|stateHidden"
android:launchMode="singleTask">
<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="developer.android.com"/>
<data android:scheme="http" android:host="*"/>
<data android:scheme="https" android:host="*"/>
</intent-filter>
</activity>
It is working when we click on any other site but in case of youtube is not working.
I have also try to add the sharing intent in my code but there is no luck to solve this.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
Please suggest what can i do to solve this.
Thanks in advance.
YouTube sends a text/plain intent with ACTION_SHARE, unless you are talking about sharing a video. So it is obvious that it won't show up any ACTION_VIEW intent.
Let's say in my app, users can make posts & send messages to other users, & I want to register my app as a component among those appears in the Share-via picker when sharing either text or an image, I'm defining my 2 activities in my AndroidManifest.xml as follows (like this official example):
<activity
android:name=".SharePostActivity"
android:label="MyApp (Post)">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity
android:name=".ShareMessageActivity"
android:label="MyApp (Message)">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
When sharing text, this works perfectly fine, where I see 2 icons of my app among available apps for sharing text, named MyApp (Post) & MyApp (Message),
Problem happens when sharing an image, because only one icon appears with the second defined label in the manifest (which is MyApp (Message)), and actually it opens the first defined activity in the manifest (which is SharePostActivity),
So, how to show the 2 options when sharing an image (just like what happens when sharing text)?
(I've tried on an emulator running Nougat & a real device running Oreo)
----- Update -----
I've found that this weird behavior happens only when sharing images from Google's Photos app, but everything works fine when sharing an image from other apps!
Some investigation leads to a solution: each of your intent-filter must contain an android:label which points to a resource, not a hardcoded string.
...
<intent-filter android:label="#string/first_value">
...
Different Activities must have different labels, so in your case the Manifest should look like
<activity
android:name=".SharePostActivity"
android:label="#string/my_app_post">
<intent-filter
android:label="#string/my_app_post">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter
android:label="#string/my_app_post">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity
android:name=".ShareMessageActivity"
android:label="#string/my_app_message">
<intent-filter
android:label="#string/my_app_message">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter
android:label="#string/my_app_message">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
i want to handle my website urls in my android app
for example :
when user in any app click on http://www.example.com/username
my app open and show username information
i use this code for open my app when click on http://www.example.com , but google chrome started :(
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="www.example.com" android:scheme="http"></data>
</intent-filter>
</activity>
You have to add android.intent.action.VIEW and android.intent.category.DEFAULT to the activity's 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:host="www.example.com" android:scheme="http"/>
</intent-filter>
For more information
https://developer.android.com/training/app-links/deep-linking.html#adding-filters
I want to launch an activity when a link is clicked on android browser.
I have followed the instructions provided by the link .
When I open the browser and click on the link, the play store is lauched.
This is my href code contained in the html page:
intent://scan/#Intent;scheme=test;package=com.exekon.appbrowser.MainActivity;end
this and this is the code in the manifest:
<activity
android:name=".MainActivity"
android:exported="true"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="test" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Can anyone proved me an example?
Thanks
Look at the zxing source code mentioned in the instructions you used:
<data android:scheme="test" android:host="scan" android:path="/"/>
check the scheme definition into the AndroidManifest.xml
<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="zxing" android:host="scan" android:path="/"/>
</intent-filter>
you must use something like:
<data android:scheme="test" android:host="scan" android:path="/"/>
I'm currently writing an Android App and it should open Files with the ending .meetme
Actually it should open them directly from Gmail, but I don't think that is possible.
This is the Code of my AndroidManifest.xml:
<activity android:name=".MeetingRequest" android:label="Meeting Request">
<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="file" />
<data android:mimeType="*/*" />
<data android:host="*" />
<data android:pathPattern=".*\\.meetme" />
</intent-filter>
</activity>
I've tried quite a few variations, if I open the file in Astro wit h a long click and open as text, my app shows up and can open it normally.
Would be grateful for any help.
Markus
After a lot of trial and error and reading nearly everything I could find, here's what finally worked for me:
<activity android:name=".DrawActivity"
android:screenOrientation="portrait"
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>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:pathPattern="*.snowdragon"/>
<data android:mimeType="text/snowdragon"/>
</intent-filter>
</activity>