How can I create a custom protocol in Android?
I have tried this code:
<activity android:name=".MyActivity" android:label="#string/app_name">
<!-- open the app when a foo://www.example.com link is clicked -->
<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="foo" />
</intent-filter>
Register this in Manifest file and call in browser like this foo://hello but it not open my app .
I remember having similar problem a while back. Hope my solution will help you solve yours.
Add android:exported="true" and move <data android:scheme="foo" />
on top.
<activity android:name=".MyActivity" android:label="#string/app_name"
android:exported="true">
<!-- open the app when a foo://www.example.com link is clicked -->
<intent-filter>
<data android:scheme="foo" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Related
PLEASE HELP MEEEE
In my application i want use DeepLink and for this i write below code.
But when run application not suggest my application and just show in Chrome browser !
My Url : sosapp://sosapp/hashcode/ghfhgfhgf?
My codes :
<activity
android:name=".Activity.LandingActivity"
android:screenOrientation="sensorPortrait" />
<activity
android:name=".Activity.MainActivity"
android:screenOrientation="sensorPortrait">
<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="sosapp" android:host="sosapp"/>
</intent-filter>
</activity>
How can i fix it and when click on this Url from mobile, suggest my app ?
I have tried use your link in my Activity and works fine.
my Activity Manifest:
<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="sosapp"
android:scheme="sosapp" />
</intent-filter>
</activity>
and my intent used to call the activity
val action = Intent()
action.data = Uri.parse("sosapp://sosapp/hashcode/ghfhgfhgf?")
startActivity(action)
Add pathPattern to your data tag like below:
<data
android:host="sosapp"
android:pathPattern="/*"
android:scheme="sosapp" />
Try adding label, it's mandatory for higher versions of android. See example from the docs. They always include a label for intent-filter
<intent-filter android:label="#string/filter_view_example_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmosā -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
After implementing Firebase Dynamic Links, my app icon is missing.
I had combined the suggested intent filter on my main activity, which prevented the app icon from appearing.
Fix this by separating them like so:
<activity
android:name=".activities.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<!--Main activity intent filter-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--Firebase dynamic links-->
<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="#string/deep_link_uri"
android:scheme="http" />
<data
android:host="#string/deep_link_uri"
android:scheme="https" />
</intent-filter>
</activity>
I'm following the App Indexing API doc .
My app URI is android-app://com.mypackagename.app/intro/intro/, so I add this to the manifest file, under <activity>
<activity
android:name=".MainActivity"
android:label="#string/config_app_name"
android:screenOrientation="portrait"
android:enabled="true"
android:exported="true"
>
<intent-filter android:label="test">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="android-app"
android:host="com.mypackagename.app" />
</intent-filter>
</activity>
But when go and test my deep link as said in Test your deep link on my phone, the link android-app://com.mypackagename.app/intro/intro/ can't be opened, there's a toast saying "there are no apps installed that can handle it"
What am I missing? Thanks
Update: in the documentation pointed out by Mattia, there's definitely an option to put whatever scheme, like 'example', but it doesn't work for me. I'm on Lollipop, if it makes a difference.
<intent-filter android:label="#string/filter_title_viewgizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos" -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
Update 2: anything after the package is the scheme, in my case, android-app://com.mypackagename.app/intro/intro/, it is intro. Marked answer below
You should use your domain, not android-app and your package as you can see in the documentation.
Try this example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateVisible">
<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="yourdomain"
android:scheme="example" />
</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.yourdomain.com"
android:scheme="http" />
</intent-filter>
</activity>
</application>
</manifest>
Than test here with these values (change com.example.test with the package name of your app):
android-app://com.example.test/http/www.yourdomain.com/page
android-app://com.example.test/example/yourdomain/page
When you scan the bar code and press the link, your app will open automatically.
Here is what I am trying to set up: My Android app requires email confirmation. They register using my app, and then an email is sent to them with a link. I want to have that link open the app directly, but I've been told it's better to have the link open page on my web site that in turn opens the app using a redirect. The link also sends the user's email address and a verification code.
Okay, so, do that, my understanding is that I need to add this code to my AndroidManifest.xml (where MYAPP is the name of my web site):
<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="MYAPP.com" android:path="/confirmation.html" />
</intent-filter>
And then my web site has a page with this in the <head> (where MYAPP is the name of my app):
meta http-equiv="refresh" content="0;URL=MYAPP://?verification=' . $_GET["verification"] . '&email=' . $_GET["email"] . '"/>
It's not working, and I'm possibly making multiple mistakes.
First question is, where does my <intent-filter> go? I've only read that it goes within the <activity> tags, but in my AndroidManifest.xml, I have two <activity> tags:
<activity android:label="#string/app_name" android:name=".MYAPP" android:screenOrientation="unspecified" android:configChanges="locale|keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name="com.phonegap.DroidGap">
<intent-filter />
</activity>
I tried adding my <intent-filter> in one, but that doesn't seem to work:
<activity android:label="#string/app_name" android:name=".MYAPP" android:screenOrientation="unspecified" android:configChanges="locale|keyboard|keyboardHidden|orientation|screenSize">
<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" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="MYAPP.com" android:path="/confirmation.html" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name="com.phonegap.DroidGap">
<intent-filter />
</activity>
Where do I put my <intent-filter>?
Is the rest of my code, especially my redirect URL, okay?
Please note I am a beginner and I am using Phonegap to build this app, so please do not assume I know a great deal about Android app development. Thanks for your understanding.
Inside you activity tags like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".My_Activity_Name"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application
In this code of yours, where is the starting intent-filter tag for the last activity:
<activity android:label="#string/app_name" android:name=".MYAPP" android:screenOrientation="unspecified" android:configChanges="locale|keyboard|keyboardHidden|orientation|screenSize">
<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" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="MYAPP.com" android:path="/confirmation.html" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name="com.phonegap.DroidGap">
<intent-filter />
</activity>
Turns out that I had my intent filter in the right place.
The reason it wasn't working was simply because I needed an extra line to account for https links.
So my code now looks 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="http" android:host="MYAPP.com" android:path="/confirmation.html" />
<data android:scheme="https" android:host="MYAPP.com" android:path="/confirmation.html" />
</intent-filter>
If someone shares http://myappAdurl.com from facebook than if another one clicks link, if application exist on that device, my app should be open,
I added following line to my manifest but I could not get the result, not working.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".TinyUrlTest"
android:label="#string/title_activity_tiny_url_test"
android:launchMode="singleTask" >
<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" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.myappAdurl.com"
android:path="/images"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="www.myappAdurl.com" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
I also tried below project but it opens link such as com.commonsware.android.MY_ACTION
https://github.com/commonsguy/cw-advandroid/tree/master/Introspection/URLHandler
ok found that,
if i give
android:pathPattern="/*.*"
inside data element, then it opens everything