How do I get values from a deep link in android? - android

I'm implementing deep-linking in android, what I'm trying to do is when a user clicks on the link, he gets redirected on the application, and this already works, but I also want that the user can see some values I pass inside the link.
Example:
My link is: https://examplelink.com/123456789. The application needs to get 123456789 code.
How do I do this?
NB: I've alredy put this on the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sendsharedlink">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="#string/app_name">
<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="https"
android:host="examplelink.com" />
</intent-filter>
</activity>
</application>
I HAVE RESOLVED BY PUTTING:
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
String[] link = data.toString().split("/");
txt.setText(link[3]);
Thanks for the help.

The first copy this code in manifest
<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 name"
android:pathPrefix="your path"
android:scheme="https" />
</intent-filter>
This is our app link: https://myapp.page.link/path?email=your#gmail.com&token=12345
and in my splash activity i get data with kotlin code:
Firebase.dynamicLinks
.getDynamicLink(intent)
.addOnSuccessListener(this) { pendingDynamicLinkData ->
// Get deep link from result (may be null if no link is found)
val data: Uri? = intent?.data
// get path
val path = data?.path
// get param
val email = data?.getQueryParameter("email").toString()
}.addOnFailureListener(this) { e -> MLog.e(TAG, "getDynamicLink:onFailure $e") }

Related

How to make a google search string appear when you click a button?

I need the following logic: when I click a button, google search string opens up, like this
I have the following in MainActivity:
val mainBtn = findViewById<Button>(R.id.main_btn)
mainBtn.setOnClickListener {
val intent = Intent(Intent.ACTION_WEB_SEARCH)
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
} else {
Toast.makeText(this, "Sorry, no such app", Toast.LENGTH_SHORT).show()
}
}
and the following in Manifest file:
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.WEB_SEARCH"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
Thank you in advance for any help
You should add some search query to the intent, it won't work without it.
intent.putExtra(SearchManager.QUERY, "some query")
If the intent.resolveActivity(packageManager) returns null try to add the queries block to your AndroidManifest before or after the application (look here):
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>

What type of Intent object required Query tag for package visibility in API 30 in Android?

I have a question regarding package visibility in Android 11. I read the oficial docs and also checked stack overflow question-answer. But I've few doubts. Please check the code below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.test">
<application
.....>
<activity
android:name=".TestActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<data
android:host="open"
android:scheme=“xxx” />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter
android:autoVerify="true"
tools:targetApi="m">
<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.xxx.com"
android:pathPrefix="/"
android:scheme="https" />
</intent-filter>
</activity>
<activity
android:name=".ABCActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
</application>
</manifest>
Doubt:
I tried and understood that <query> tag suggestion is coming only outside of <application> tag. Am I right?
If you see my code like this android.intent.category.BROWSABLE written inside particular TestActivity. Now If I'll move intent filter code outside of application tag, then how Android will understand that for which activity browsable is required?
There are multiple intent filter with BROWSABLE, so I need to declare query tag multiple times?
I saw that people uses intent tag inside query tag, and no one is using intent-filter. So is that fine?
Can I do one last request? Can someone please correct my code and post it in answer? I already reduced and added only required code according to my questions. Thanks in advance!
EDIT:
Usage 1:
upiIntent = Intent(Intent.ACTION_VIEW)
val pm: PackageManager = packageManager
val app: MutableList<ResolveInfo>? = pm.queryIntentActivities(upiIntent!!, 0)
Usage 2:
Intent intent = new Intent(Intent.ACTION_SEND, null);
intent.setType("text/plain");
private List<ResolveInfo> sharingAppList = new ArrayList<>();
PackageManager pManager = context.getPackageManager();
sharingAppList = pManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Usage 3:
mVersionName.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
The latest code in your question seems wrong, insofar as upiIntent needs more than an action string.
But, ignoring that, you would need a <queries> element like:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
</intent>
</queries>
The first <intent> matches an ACTION_VIEW with no content; the second matches an ACTION_SEND with a MIME type of text/plain.

I have Integrate deep linking in my app but its not work

I have integrate deep linking in android app .I get result like below image and already app install in my phone but When i click on link from message Application after app icon not show in launcher list. I don't know what is wrong in my code implementation .Thanks in advance.
Here is my menifests file code
<activity
android:name=".activity.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Splash"
android:windowSoftInputMode="stateHidden"
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" />
<!-- handle website links -->
<data
android:host="www.abc.in"
android:pathPattern="/event"
android:scheme="https" />
<data
android:host="abc.in"
android:pathPattern="/event"
android:scheme="https" />
</intent-filter>
</activity>
Here is my activity code
private void handleIntent() {
// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null){
String recipeId = appLinkData.getLastPathSegment();
Log.e(TAG,"recipeId ="+ recipeId);
}
}
The host you clicked does not match to your deeplink.
If you clicked: https://abc.in/event. it will work.
If you want to support deeplink from like the sample above, you should this on your current intent-filter
<data
android:host="maps.google.com"
android:pathPrefix="/maps"
android:scheme="http" />
Edit:
To support this link: https://abc.in/event/-chakravyuh-featuring-nitish-bharadwaj/1073. You need to add the following.
<data
android:host="abc.in"
android:pathPrefix="/event"
android:scheme="https" />

Allow other app to start my Activity

I have used this example so that other applications can call my activity to receive data from them.
Specifically, I want when uploading an image from a browser my application can supply that image.
In the following image can see that case. A list of applications that provide images when the user clicks upload file:
I used this code that is copied from the link I added to the start.
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login">
<!-- filter for sending text or images; accepts SEND action and text or image data -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
I can not get my app to appear in the apps list shown in the photo.
Also I test this, as #Avi suggests:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.APP_BROWSER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="image/*" />
<data android:mimeType="text/plain" />
</intent-filter>
Getting the same results
Note: I am using the chrome browser in Android
Change below line
<action android:name="android.intent.action.SEND" />
to
<action android:name="android.intent.action.VIEW" />
I got my app to appear in the browser when uploading an image with the following code.
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Try this-
Manifest file:
<activity
android:name=".activities.HomeActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
Your MainActivity file:
val data: Uri? = intent?.data
// Figure out what to do based on the intent type
if (intent?.type?.startsWith("image/") == true) {
// This handles the intents with image data or of any other type based on your specified condition.
} else if (intent?.type == "text/plain") {
// This handle the intents with text or based on your conditions
//Use any popup like toast, snackbar, dialog, etc of your preference.
}
And also please do check whether you have mentioned your action as VIEW or SEND.
If its a VIEW it wont reflect in your result but if its SEND then it will work.
Check for this if in any of the file you have mentioned this-
val sendIntent = Intent(Intent.ACTION_SEND) //Replace to SEND if you have used ACTION_VIEW
sendIntent.type = "image/*"
val title = context?.resources?.getString(R.string.chooser_text)
if (context?.packageManager != null) {
context?.startActivity(Intent.createChooser(sendIntent, title))
}
And if you want to fetch the result of your action the insert this too...
Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri")).also { result ->
setResult(Activity.RESULT_OK, result)
}
finish()
For better understanding of this flow, refer this -> https://developer.android.com/training/basics/intents/filters

How to make my Android app appear in the share list of another specific app

<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
this is in my manifest file
this will make my app appear on the share list of all apps
but I want my app to appear in the share list of another specific app
and I don't own the other app
Add this code in the activity you want opened first when sharing a content from outside the app, call this method in onCreate()
private void onSharedIntent() {
Intent receiverdIntent = getIntent();
String receivedAction = receiverdIntent.getAction();
String receivedType = receiverdIntent.getType();
if (receivedAction.equals(Intent.ACTION_SEND)) {
// check mime type
if (receivedType.startsWith("text/")) {
String receivedText = receiverdIntent
.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
//do your stuff
}
}
else if (receivedType.startsWith("image/")) {
Uri receiveUri = (Uri) receiverdIntent
.getParcelableExtra(Intent.EXTRA_STREAM);
if (receiveUri != null) {
//do your stuff
fileUri = receiveUri;// save to your own Uri object
Log.e(TAG,receiveUri.toString());
}
}
} else if (receivedAction.equals(Intent.ACTION_MAIN)) {
Log.e(TAG, "onSharedIntent: nothing shared" );
}
}
Add this in Manifest,
<activity
android:name="your-package-name.YourActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
In order to do this, you need to know the Intent that the application is creating and create an IntentFilter that will add your application to the specific list.
Receiving an Implicit Intent on Intents and Filters (Android Developers)
The application probably uses a specific action name that you could hook to.
<intent-filter . . . >
<action android:name="com.example.project.SHOW_CURRENT" />
<action android:name="com.example.project.SHOW_RECENT" />
<action android:name="com.example.project.SHOW_PENDING" />
. . .
</intent-filter>
Or it could be looking for applications accepting a certain type of file.
<intent-filter . . . >
<data android:mimeType="video/mpeg" android:scheme="http" . . . />
<data android:mimeType="audio/mpeg" android:scheme="http" . . . />
. . .
</intent-filter>
The name of the application and what it is sharing would help me give a more specific response.
- Add below code into your Project AndroidManifest.xml file in Specific Activity.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
- Add the following line of code into your project specific Activity.
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if ("android.intent.action.SEND".equals(action) && type != null && "text/plain".equals(type)) {
Log.println(Log.ASSERT,"shareablTextExtra",intent.getStringExtra("android.intent.extra.TEXT"));
}
add this to your mainefist file
<activity android:name=".ShareActivity">
<intent-filter
android:label="Share with my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
this link may help you
this worked well for me for getting all web pages, for my app that scans for mp3 files on a web page, and sets alarms from them. It opens up my new url activity, when you share a web page:
Here is what this code results in:
<activity
android:name=".NewUrl"
android:label="#string/title_activity_new_url"
android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter>
</activity>
Then to receive the link in the app, I got awsome info from this tutorial:
http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878
I want to add something to the above answers. Keep in mind that you should put another intent filter to prevent overriding in case you are using multiple categories in an activity.
For example, the following will prevent your application to be shown on the application list in your device because it doesn't detect it as launcher activity.
Don't do this
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- DO NOT DO THIS-->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
Instead do following
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- USE SEPERATE INTENT FILTER -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
Note: Change mimeType according to your use.
Verdict: If you are using more than one category in intent filter use them separately.
I would check to see if there is any API for this app you want to work with.
If so, you can benefit by knowing
a more specific implicit action for your filter
or perhaps add a category other than DEFAULT
If you can find something like these, it would be unlikely to be seen by other apps.
Also make sure to have you Activity NOT labeled with android:exported="false", otherwise it won't show up in other applications' intent choosers (only your own)
E.g. AndroidManifest.xml
<activity
android:name=".ReceiveImageActivity"
android:exported="true"> <!-- here -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<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.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Categories

Resources