How to open my application when app link is clicked? - android

What I want is to share the link of specific page of my application. Suppose I am in a profile page of some user in my app and I want to share that user to some of my friends so I would like to share it via WhatsApp and other applications.
So basically I want to share a link to my app.
This is what I am doing right now
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
activity.startActivity(Intent.createChooser(shareIntent, "Share"));
I know this is not what I really want but it's partially done.
if user hasn't installed my app then this code redirect him to google play store page to download this app.
Main problem is when user have already this app this link just opens the app. I want to redirect user to that specific page when he clicks on a link.
How can I do this?
I heard something about intent-filter but not sure how to use them.
<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:mimeType="application/pdf" />
UPDATED
Now I am trying to share my app link like this
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra("PostID", postID);
shareIntent.putExtra("UserID", userID);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + activity.getPackageName());
activity.startActivity(Intent.createChooser(shareIntent, "Share"));
Inside my manifest I have declared an activity like this
<activity
android:name=".activities.ShareActivity"
android:screenOrientation="sensorPortrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="details"
android:scheme="market" />
<data
android:host="play.google.com"
android:pathPattern="/store/apps/details?id=my_package_name"
android:scheme="http" />
<data
android:host="play.google.com"
android:pathPattern="/store/apps/details?id=my_package_name"
android:scheme="https" />
</intent-filter>
</activity>
But I am still not able to see my app when I click on the link I shared using WhatsApp or any other means.
Please help me
Any help will be really appreciated.
Thanks in advance.

Add the following intent-filters to your activity declaration, in the AndroidManifest of your project :
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Now, in the onCreate(), onResume() or onNewIntent() method of your activity lifecycle, you can use the getData() of the intent that has fired your activity.

Related

A link generated from the web site does not open in my app but same link genrated from app its work properly

In my android app code Manifest file contains following Intent filter for handling a Link in the app but doesn't work
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="safimoney.com"
android:pathPrefix="/.*/transactions/request-money/confirm/.*" />
</intent-filter>
test it with link generated from web "https://safimoney.com/en/transactions/request-money/confirm/0CnpXE7u5hXRD1JVcZM2APHcYElKZvBZs8GeqimJ" but it doesn't ask for an open link in the app.
If you want your app to open a link, use below code.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
It will ask to select browser while opening this link.
You wanna do a Deep Link, right?
<intent-filter>
<data
android:host="open"
android:scheme="companyName" />
<data
android:host="companywebsite.com"
android:scheme="http" />
<data android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
I would suggest for you take a look in Branch.io for link-app solutions.
But if you wanna make a webView inside your app this tutorial can help you.
This is one of the cases where developer.android website has everything that you need, even code examples. Just need to ready with a lot of attention. Hope it helps
EDIT
About your data, looking on android developer website, this should be the better way to set:
<data
android:scheme="https"
android:host="safimoney.com"
android:pathPrefix="/en/transactions/request-money/confirm/" />
But even after this you should add a data like this
<data android:scheme="safimoney"
android:host="/en/transactions/request-money/confirm/" />

Make my app available as an option in the file picker dialog

How can i make my app available in the "Open From" dialog of the file picker? and how do i handle that request in the activity code?
Here is a screenshot of the dialog where i want my app to appear as an option(This dialog is from while uploading a file to google drive):
You can specify mimeType in intent-filter in your mainfest file.
your app will be added to share list.
For example you need to add your app for text share then use
mimeType="text/plain"
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
Handle share :
Write this code in onCreate method of your activity (Activity which is declared in mainfest with intent filter(above))
if (Intent.ACTION_SEND.equals(intent.getAction()))
{
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
//here you will get data which is shared.
}
I've faced same problem recently and solved it by handling this intent in my app:
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>

Add custom action to Android Share-Sheet

I have an app where the user should be able to share some text. Now I want to provide the default sharing options for plain text that Android provides. I do so with the following code:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");
Intent chooser = Intent.createChooser(sendIntent, "Share");
startActivity(chooser);
This will look a bit like that:
Source: http://developer.android.com/training/basics/intents/sending.html
But now I also would like to be able to have one more option in the Share-Service-Picker Dialog that triggers a custom action in my own code. Namely I want the user to be able to favourite an entry. So beside sharing via SMS, Email, FB, whatever, I'd like there to be one more item on the top of that list, saying "Add to favourites" (Including an icon if possible).
So my question is if that's possible?!? And if, how :)
Any tips are appreciated!
Intent filters inform the system what intents an application component is willing to accept. Similar to how you constructed an intent with action ACTION_SEND in the Sending Simple Data to Other Apps lesson, you create intent filters in order to be able to receive intents with this action. You define an intent filter in your manifest, using the element. For example, if your application handles receiving text content, a single image of any type, or multiple images of any type, your manifest would look like:
<activity android:name=".ui.MyActivity" >
<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>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
from Receiving Simple Data from Other Apps:Update Your Manifest

How to provide content for Intent.ACTION_GET_CONTENT

The web and stackoverflow contain several examples how to get a file from another Android app (e.g., to use it as email attachment) using an ACTION_GET_CONTENT intent. But what kind of class do I have to implement to create an application providing content for the ACTION_GET_CONTENT event such as I can choose this app (e.g., for selecting an email attachment).
Is a ContentProvider the right solution? And what do I have to add to my AndroidManifest.xml?
After some hours of web search I found the following solution.
Implement an Activity handling intents. Within, use the following or more specific code:
Uri resultUri = // the thing to return
Intent result = new Intent();
result.setData(resultUri);
setResult(Activity.RESULT_OK, result);
finish();
Add the following to the Manifest:
<activity
android:name="ActivityName"
android:label="Some label" >
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
starting from api level 18 incoming intent can also have EXTRA_ALLOW_MULTIPLE set to true and in this case you can send back in result more than one file. To do so you need to set it as ClipData:
resultIntent.setClipData(clipData)

Launch Skype from an App Programmatically & Pass Number - Android

Trying to launch and pass tel. no. to skype by this code from my app:
PackageManager packageManager = getPackageManager();
Intent skype = packageManager.getLaunchIntentForPackage("com.skype.raider");
skype.setData(Uri.parse("tel:65465446"));
startActivity(skype);
Skype is launched but it can't catch the number.
This code works for me to start a call between two Skype users:
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + user_name));
startActivity(sky);
To find this (and others), use apktool to open up the Skype APK. Look at the AndroidManifest.xml and you'll see all the intent filters they know about. If you want to trigger one of those intent filters, you need to make an intent that will match one. Here's the intent filter that the code above is matching:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="skype" />
</intent-filter>
You get the category "android.intent.category.DEFAULT" for free from new Intent(), so all that remains is to set the action and the URI.
The intent filter for tel: URIs looks like this:
<intent-filter android:icon="#drawable/skype_blue" android:priority="0">
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
So you set to the action and give the Intent a tel: URI and "the right thing happens". What happens is that Android finds the correct provider for the tel: URI. It might get the user's input to choose between the Phone App and Skype. The priority for Skype to handle tel: URIs zero, which is lowest. So if the Phone App is installed, it will probably get the Intent.
In case you want to trigger a video call you will have to add "?call&video=true" to your Skype URI.
Intent skypeVideo = new Intent("android.intent.action.VIEW");
skypeVideo.setData(Uri.parse("skype:" + "<username>" + "?call&video=true"));
startActivity(skypeVideo);
More information about Skype URIs are documented at:
http://developer.skype.com/skype-uris-program/skype-uri-ref
EDIT :
Direct Skype call without any intent chooser :
If you want direct skype call without any intent chooser, add these lines in your manifest file...
<intent-filter
android:icon="#drawable/skype"
android:priority="0" >
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<intent-filter
android:icon="#drawable/skype"
android:priority="0" >
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="skype" />
</intent-filter>
</intent-filter>
Use this code for Skype version 2:
Intent skype_intent = new Intent("android.intent.action.VIEW");
skype_intent.setClassName("com.skype.raider", "com.skype.raider.Main");
skype_intent.setData(Uri.parse("skype:skypeusername"));
startActivity(skype_intent);
With this code you will get the intent of the Skype activity not the caller activity. So you have to find the intent for the activity which has the intent filter for action CALL. But more clearly Skype uses the action android.intent.action.CALL_PRIVILEGED, so find by this filter.
Just for information that caller activity is cmp=com.skype.raider.contactsync.ContactSkypeOutCallStartActivity.
Skype 2.X has significantly different manifest then Skype 1.X. There is no ContactSkypeOutCallStartActivity there. New manifest contains code:
<activity android:name="com.skype.raider.Main" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="adjustResize">
...
<intent-filter android:icon="#drawable/skype_blue" android:priority="0">
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
...
</activity>
So you should write:
Intent skype_intent = new Intent("android.intent.action.CALL_PRIVILEGED");
skype_intent.setClassName("com.skype.raider", "com.skype.raider.Main");
skype_intent.setData(Uri.parse("tel:65465446"));
context.startActivity(skype_intent);
Please note, that this method doesn't allow you to start call/chat using Skype. It works with Skype Out only.
I found that the code above did not work...
Intent i = packageManager.getLaunchIntentForPackage("com.skype.raider");
// i.setAction("android.intent.cation.CALL_PRIVILEGED");
// i.setClassName("com.skype.raider", "com.skype.raider.contactsync.ContactSkypeOutCallStartActivity");
// i.setData(Uri.parse("tel:5551234"));
startActivity(i);
The commented out lines either stopped it functioning, or did nothing!
The code as presented will call Skype and arrive at a page where you can choose Skype contacts
More information will be most welcome
John

Categories

Resources