How to use Deep-linking? - android

i am working on Deep-link from an Android application to connect my Android application. Now they are calling my app using below URI
kaip.deeplinkSandbox://payment?token=1p51ktwy2qK5sDwNBJy2kP11vK
So how to mention this on my app's Manifests file to open my app, when user trying this above from their app.
i want to seperate schema , host and path from the above deeplink data. Please help to finish this. Thanks!

Add this in your manifest file inside the tag. Activity should be your Launcher activity
<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="kaip.deeplinkSandbox" />
</intent-filter>
And in your Activity,you can get the link like this:-
Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
String uri = this.getIntent().getDataString();
Log.i("MyApp", "Deep link clicked " + uri);
}
If any query, you can ask!!

Related

Android Deep Link with a URI that contains no paths but data-only

I want to add support for a deep link of a URI with the following scheme:
xrb:xrb_3wm37qz19zhei7nzscjcopbrbnnachs4p1gnwo5oroi3qonw6inwgoeuufdp?amount=10000
The amount parameter is optional, the second part is a required address. So essentially the schema is xrb: the first part xrb_3wm37qz19zhei7nzscjcopbrbnnachs4p1gnwo5oroi3qonw6inwgoeuufdp is any string and amount is an optional parameter.
Looking at the Android documentation here, what I'm not clear about is how to retrieve the data from my activity, particularly for the part that doesn't come in as a parameter (xrb_3wm37qz19zhei7nzscjcopbrbnnachs4p1gnwo5oroi3qonw6inwgoeuufdp)
The URI is a standard that other applications and services use so I'd rather not change it or do anything proprietary, but is it possible to have a deep link with a URI of this format?
Basically all I'm looking for is when clicking a link containing the URI, the app will open and pre-load some data for them based on the URI.
Thanks!
Accomplished by creating an intent-filter in AndroidManifest
<!-- xrb uri scheme -->
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="xrb" />
</intent-filter>
And retrieving the URI in the activity's onCreate
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
if (data != null) {
Timber.d("inuri %s", data.toString());
} else {
Timber.d("inuri null");
}

Open url into android app

currently i'm building blog/news portal app based on web version in android, i want if someone search a query on google/bing or another search engine in android browser and found my web www.newsportal.com/this-is-article-slug then browser tell there are choices to open it, open in browser itself or open on my newsportal app instead, then my app catch my link www.newsportal.com/this-is-article-slug, extract this slug this-is-article-slug then open new activity, search the article via API and done. I tried read some reference like http://developer.android.com/training/sharing/receive.html but I confuse where do i start,,
Thanks for your help..
Open search result in application you need to add in your activity tag in Manifest.xml like below
<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="your host"
android:scheme="your scheme" />
</intent-filter>
And handle result in in your activity like
Intent intent = getIntent();
Uri data = intent.getData();
String action = intent.getAction();
if (Intent.ACTION_VIEW.equalsIgnoreCase(action) && data != null) {
if (data.getScheme().equals("your scheme")
&& data.getAuthority().equals("your host")) {
}
}

Android link to own applications from other Android applications

i'm trying to have ability like with internal links such as Google market as :
market://details?id=de.schildbach.oeffi
for exampele
myApplication://detail?id=11
how to change manifest or create other ability for application to have that? i want to create link as myApplication://detail?id=11 and share that in other android application such as Telegram or Whatsapp, user can be going to my application after click on my created link.
Add an intent filter to your activity:
<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="myApplication"
android:host="detail"
/>
</intent-filter>
And then handle the link on your activity's onCreate(..) or onNewIntent(..)
Uri intentData = intent.getData();
if (intentData != null && "myApplication".equals(intentData.getHost()) && "detail".equals(intentData.getScheme()) {
//link was clicked, parse the rest of intent's data and do something useful
}
You have to set a "scheme" as one of the intent_filter of the activity you want to be started, in your Manifest, something like:
<data android:scheme="#string/deeplink_scheme" />
You can follow Android documentation about it here :
Allowing Other Apps to Start Your Activity

Intent filter for common file explorers

I'm trying to associate my app with extension. I have read documentation and some questions about the problem. But major file explorers (like es file explorer, astro, file manager by Rhythm software) can't open my files.
My manifest file:
<activity android:name="com.comapping.android.map.MapActivity" android:configChanges="orientation|keyboardHidden">
<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="file" android:host="*" android:pathPattern=".*\\.comap" android:mimeType="*/*" />
</intent-filter>
<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="*" android:pathPattern=".*\\.comap" android:mimeType="*/*" />
</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>
And If I try to open file from my application using next code everything works fine (chooser not shown):
String extension = "";
int dotIndex = downloadedFile.lastIndexOf('.');
if (dotIndex != -1) {
extension = downloadedFile.substring(dotIndex + 1, downloadedFile.length());
}
// create an intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.fromFile(new File(downloadedFile));
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (type == null || type.length() == 0) {
// if there is no acceptable mime type
type = "application/octet-stream";
}
intent.setDataAndType(data, type);
// get the list of the activities which can open the file
List resolvers = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolvers.isEmpty()) {
(new AlertDialog.Builder(context)
.setMessage(R.string.AttachmentUnknownFileType)
.setNeutralButton(R.string.NeutralButtonText, null)
.create()).show();
} else {
context.startActivity(intent);
}
If i try to open it using OpenIntents file manager everything is normal - showed long chooser with lots of apps and my app in the list.
But if I try to open it with es file explorer or Rhythm file explorer - showed their custom chooser (open as text/image/video/audio). It's bad.
And if I try to open it with Astro - it opens OpenIntent's file manager. It's also bad.
Is there any solution of the problem? Who is wrong in such behavior?
Thank you for any help.
Part of the problem here is all the different ways people wrap a shared intent for, say, a file that resolves to text/plain in Android mime identifier.
My approach has been to find out what mime types the files I want are. Then I set my manifest filters to those types. I use two filters. The first just filters the mimes I want. The second is a copy of the first plus schemes.
Then I test by sending shares from apps like you have done. When one does not work, I use a toast to see what I am getting for a STREAM and then alter it to fit. For example, if I get an OpenIntent STREAM, I have to remove
content://org.openintents.filemanager
which leaves me with the path. Mostly, I just have to remove:
file://
But it's always something because the whole content/Uri/Intent scheme is a free-for-all cluster whatsit.
LATER. I just stumbled on this:
Intent intent = getIntent();
String name = intent.getData().getPath();
Maybe that will do for you. I'm going to try it soon myself.

Taking uri data through intent in android

Hi i have to do connectivity between android app and browser. So while clicking a button on browser it should redirect to android app. in android activity i have written
Uri data = getIntent().getData();
if (data.equals(null)) {
System.out.println("Data is null");
} else {
String scheme = data.getScheme();
System.out.println(scheme);
String host = data.getHost();
int port = data.getPort();
List<String> params = data.getPathSegments();
String first = params.get(0); // "hello"
System.out.println(first);
and in manifest i have already given
<intent-filter>
<data android:scheme="Integration" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
in html on button click i have given <FORM METHOD="LINK" ACTION="Integration://1">
it is throwing a indexoutofboundexception.
Please tell me where is the mistake
Updated
*I was unnecessarily using intent in an activity. By removing that n parameter in html5 my app is running successfully now.*
Quoting answer from: How to listen for a custom URI
To register a protocol in your android app, add an extra block to the AndroidManifest.xml
I modified the code a little, but thought I'd quote the source too
<manifest>
<application>
<activity android:name=".activityToCall">
<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="scheme" android:host="path"/>
</intent-filter>
</activity>
</application>
</manifest>
Then when a url matching your schema is opened your app will be called to handle it I assume.
Taking into consideration that scheme and pathcorrespond to this:
scheme://host/path
After that, in the activity you've set in the manifest to handle this stuff:
Uri data = getIntent().getData();
if (!data.equals(null)){
String scheme = data.getScheme();
//Or whatever you needed
}

Categories

Resources