Android-How to open my app from the browser - android

I am developing a parental control app, the goal is, when certain websites are accessed, my app would pop up.
From my research, the way to accomplish this is by adding intent-filter to AndroidManifest.xml
For now my activity looks like this
<activity
android:name=".BlockActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
From my understanding, this should intercept any website access because I did not specify any host in data attributes. However, when I open, say, www.google.com, my activity does not start.
I also tried specifying the host like this, but it also did not work.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.google.com"/>
<data android:pathPrefix="/"/>
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Out of curiosity, I tried another intent-filter with android.intent.action.SEND, and it does trigger for sharing.
FYI, I am testing on a virtual device with API Level 30.
Any insights on my goal of intercepting web browsing are welcome, at this stage I am not even sure if intent-filter is the right way to do it.

I later figured out that the better way of implementing what I'm trying to accomplish is to use AccessibilityService.

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.

Google Chrome ARC intent-filter crash

I try to implement launch app from intent filter on ARC using that code :
<activity
android:name=".package.etc.MyActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|layoutDirection|fontScale"
android:screenOrientation="sensorLandscape"
android:launchMode="singleTask"
android:label="#string/myactivity_name" >
<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:pathPattern=".*\\.pdf" />
<data android:host="*" />
</intent-filter>
</activity>
On Android Tablet, it works. But on Chrome ARC app crashes.
Is Chrome ARC supports that ?
EDIT
I got that crash
Fatal Exception: java.lang.IllegalArgumentException There is no Activity which handles filePath = file:///data/data/org.chromium.arc/external/C1373AC2527597D1C0BC66486DCC787F/Gra‌​nizo.pdf mimeType=application/pdf
org.chromium.arc.helper.FileHandlerLaunchHelperActivity.buildLaunchIntent (FileHandlerLaunchHelperActivity.java:122)
org.chromium.arc.helper.FileHandlerLaunchHelperActivity.onMessage (FileHandlerLaunchHelperActivity.java:162)
org.chromium.arc.ArcMessageBridge$1.handleMessage (ArcMessageBridge.java:75)
org.chromium.arc.ArcMessageBridgeService$3.run (ArcMessageBridgeService.java:238)
EDIT 2
<activity
android:name="com.package.activities.MyActivity_"
android:configChanges="mcc|mnc|locale|touchscreen|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|layoutDirection|fontScale"
android:screenOrientation="sensorLandscape"
android:launchMode="singleTask"
android:label="#string/myactivity_name" >
<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:pathPattern=".*\\.pdf" />
<data android:host="*" />
</intent-filter>
</activity>
I am going to assume that whatever "ARC file explorer" is refers to some other Android app, packaged via ARC, that is running in your Chrome/ChromeOS environment.
In that case, that app has nothing to do with your app.
It is best to think of ARC as providing separate Android emulators per ARC. Apps in one ARC do not have access to apps in other ARCs, just as apps in one emulator image do not have access to apps in other emulator images (or apps on one device do not have access to apps on a separate device). Hence, your "ARC file explorer", in its own ARC, cannot open a PDF via your app in a separate ARC.
This makes many Android apps fairly useless in the ARC environment, and hopefully is something that will be addressed in the future.

application is not intercepting url

I am trying to intercept my own app's URL on android so that the user can open the URL in the app rather than on the browser. (I don't have browser support yet).
This is what I'm doing
<activity android:name=".ui.activity.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>
<action android:name="android.intent.action.PICK_ACTIVITY" />
<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:host="myapp.com" />
<data android:pathPattern=".*"/>
</intent-filter>
</activity>
For some reason anytime I open myapp.com it still keeps opening in the browser, without giving me the option to open the URL in my app. I am trying this on my emulator with API 16 running on it. I've closed the emulator several times and started it again but still its the same behavior.
To avoid any errors in the URL of my personal app. I even experimented with:
<data android:host="goo.gl" android:scheme="http" />
<data android:host="goo.gl" android:scheme="https" />
The app DOES intercept the above url but ONLY the first time. If I click 'JUST ONCE' in the options presented, I don't get the option ever again until I restart the emulator.
Has anyone gone through this? What might I be doing wrong?
this answer helped me : link to question
if you add the package name to the intent, it will open your app by default

http scheme intent filter for link to app from web

This seems to be a typical problem and there seems to be a lot of differing behaviour, the problem I'm having though is that my scheme will launch the picker and allow me to choose my app when I hit a link in an email or a note on the device, but if I hit a link on a web page I can't seem to launch the app, don't even get the picker (I'v checked the "defaults" for the two browsers and none are set).
<activity
android:name=".MyActivity"
android:exported="true"
android:enabled="true">
<intent-filter>
<data android:scheme="http" android:host="www.website.com"/>
<data android:scheme="http" android:host="website.com"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
If I use one of my links from an email as below it gives me the chooser, launches my app, all is great, however, hitting the same link in the web browser just launches the page with no chooser. Any suggestions on what the problem might be?
http://www.website.com/share.aspx?id=12345678
Testing on GS2 running ICS 4.0.3 with Chrome and stock browsers.
Add the android:pathPrefix attribute.
<data android:scheme="http" android:host="website.com" android:pathPrefix="/" />
This is how I solved it eventually:
<intent-filter>
<data
android:host="www.website.com"
android:pathPattern=".*\\share.aspx"
android:scheme="http" />
<data
android:host="website.com"
android:pathPattern=".*\\share.aspx"
android:scheme="http" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Also add the following to the Activity tag:
android:exported="true"
The reason there are two addresses is so that the app can pick up canonical domains (with/without www.).

Android Intent-filter mimetype and host/scheme

I've seen in some apps that when you click on a link it asks you if you want to open it in an app. I've seen in many posts that you can do
<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.ex-ample.com" android:scheme="http" />
</intent-filter>
I haven't tried it, but every post seems to say it works. What I tried was:
<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="vnd.android.cursor.item/vnd.example.crag" />
<data android:host="www.ex-ample.com" android:scheme="http" />
</intent-filter>
and it doesn't seem to work, I clicked on a link in a text that went to www.ex-ample.com/test/123 and it just opened in a browser.
I'm really wondering two things:
can you use a mineType and a host/scheme attribute together
can you see anything else wrong with this?
can you use a mineType and a host/scheme attribute together
Yes, at least according to the docs on <data>.
can you see anything else wrong with this?
If http://www.ex-ample.com/test/123 does not return a document of MIME type vnd.android.cursor.item/vnd.example.crag on an HTTP HEAD request, your <intent-filter> will not match.

Categories

Resources