Background
In order to open Facebook app with a specific Facebook friend, you can use this intent:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("fb://profile/%s", friendId)));
A similar solution is found for LinkedIn:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("linkedin://profile/%s", friendId)));
I think the next one will work for Google Plus (didn't test it, but it seems promising) :
final Intent intent =new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("https://plus.google.com/%s/posts", friendId)));
The question
I've tried to find how to open VKontakte (VK) social network app using such intents, but couldn't find it.
Is there such an intent? If so, what is it?
The answer from developer is next:
Yes, it's done the same way:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("vkontakte://profile/%d", friendId)));
If you need to open a community, use the same URL but add the minus sign to the community ID.
Question answered here
Here is a list of url i found at VK app manifest
http ://vk.com/.*
http ://vkontakte.ru/.*
https ://vk.com/.*
https ://vkontakte.ru/.*
http ://m.vk.com/.*
Note: remove space after http/https. SO won't let me post more than 2 links
you can use any of that to launch vk from your app
here is how i do that
private void sendIntentToVkApp() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://vk.com/hmrussia"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
and here is a part of VK Manifest where all the schemes are defined
<intent-filter>
<category
android:name="android.intent.category.DEFAULT"/>
<action
android:name="android.intent.action.VIEW"/>
<data
android:scheme="vklink"/>
</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="vk.com"
android:pathPattern="/.*"/>
</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="vkontakte.ru"
android:pathPattern="/.*"/>
</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="https"
android:host="vk.com"
android:pathPattern="/.*"/>
</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="https"
android:host="vkontakte.ru"
android:pathPattern="/.*"/>
</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="vkontakte"
android:pathPattern="/.*"/>
</intent-filter>
In Kotlin. This will open the app if installed, otherwise the browser will open.
private fun openVk(profileId: String) {
val uri = Uri.parse("http://vk.com/$profileId")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
Related
I have a custom ROM and have no default browser except WebView Browser Tester. I have develop my own kind of web browser app(webviewclient activity) and install this in a phone. Now I want that whatever URLs when user click in a phone, my browser application will intercept and load this URL. Here is what I am using in 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"/>
</intent_filter>
But it is not working and still WebView browser Tester app launch and loading links. Can someone tell me how I can set my app as a default browser App OR use any special intent which can help to launch this activity while clicking on any URL?
Try adding both intent filters
<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="*"/>
</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="https"
android:host="*" />
</intent-filter>
For this you have to identify the launching Activity of Browser application, something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("/*Pass your browser package*/","com.google.android.browser.BrowserActivity /*And pass Browser Activity*/"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
Answer already available on this link
I have developed an android app locally on my device (app not yet on android play store). I have the following logic to get deep link in MainActivity.
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, null)
.addApi(AppInvite.API)
.build();
// Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
// would automatically launch the deep link if one is found.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// ...
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
I built some dynamic links using Firebase console and open in mobile browser. But it is not opening my app and reaching to line String deepLink = AppInviteReferral.getDeepLink(intent);
Instead it is opening the URL in mobile browser itself.
How to open the app and handle deep link in activity while using firebase dynamic link??
Edit:
I have intent filter in the manifest file.
<activity android:name="MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
</intent-filter>
</activity>
Action View and Action Main both are of different Intent category. So, you need to put them in different blocks like this:
<activity android:name=".DynamicLinkActivity">
<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="example.com"
android:scheme="http" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
</activity>
Alternatively, you could also provide the data in your intent-filter, like stated in the "regular" deep links doc (https://developer.android.com/training/app-indexing/deep-linking.html)
The intent filter would then look like the following :
<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="https://XXYYZZ42.app.goo.gl/" // <- Replace with your deep link from the console
android:scheme="https"/>
</intent-filter>
That said link can be obtained in your console, right here :
EDIT : Added the picture to show where to find this link
Update January 2019
Ensure that you have added the SHA256 certificate fingerprint for your app into your project in the Firebase console.
Add the below code in the AndroidManifest.xml under the activity which you want the dynamic link to lunch:
<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:host="mydomainname.page.link" android:scheme="http"/>
<data android:host="mydomainname.page.link" android:scheme="https"/>
</intent-filter>
Remove android:autoVerify="true" if you have Android 6.0 (API level 23) and below or the app will crash.
As explained in another answer, your intent filter seems to have some problems. Also your url may have some problems. When I was playing with those, I had created faulty URL to FireBase web site without noticing it. It is possible to test you code by opening the whole url in your app. I wrote all urls to be tested to an email and sent to myself, open in the device and started clicking. After that you can create the url you want in FireBase. Below are few examples (typos and other errors possible):
If you clicked this url on your device:
https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp
and had this in you 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:scheme="https"
android:host="mysite.fi"
android:pathPattern=".*" />
</intent-filter>
It should open https://mysite.fi/112972 in your app (com.mydomain.myapp) and if you opened the link on your PC, it would open https://mysite.fi/112972 in the browser.
If you opened this url in your device:
https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp&al=myscheme://mydeeplink/112972&afl=http://fallback.fi
and had this in you 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:scheme="myscheme"
android:host="mydeeplink"
android:pathPattern=".*" />
</intent-filter>
It would open myscheme://mydeeplink/112972 in your app (com.mydomain.myapp). You would need to have code for handling it. If the app is not installed, it would open http://fallback.fi in your browser. On the PC it would still open https://mysite.fi/112972.
(edit 19.3.2018) It seems that Firebase does not fully support 'al=' anymore. The code works, but it is missing from the documentation and Firebase console generated urls.
I had the same problem with deep links not working and the former answers wasn't helping. What did the trick was splitting the "data" tag like this:
Instead of:
<data android:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
Do this:
<data android:host="example.com"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
Hope that will help anyone else :)
Well, I was breaking the hell of my brain cells with this and no solution came up...
Usually, in Android, to open the Web Browser in a specified Website, we do this:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
So, I got a Data URI Scheme (dunno if it is written this way, i'm not an expert on this kind of stuff) like this:
data:text/html;charset=utf8;base64,<base64 html code>
If I copy and paste this in a web browser, it will handle it the way I want it.
But how can I do it programatically in Android?
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(dataHTMLBase64));
startActivity(browserIntent);
dataHTMLBase64 stores the Data URI Scheme I mentioned before.
The code above won't work. It won't even launch chrome.
What can I do?
PS: I'm not good with English. Please warn me if I didn't express myself the right way...
Actually, it appears that one can launch a Data URI in an Android browser quite easily.
String url = "data:text/html;charset=utf8,<b>Hee-haw!</b>";
startActivity(Intent.makeMainSelectorActivity(
Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)
.setData(Uri.parse(url.toString())));
Using apktool I reviewed the AndroidManifest.xml of the Google Chrome .apk file.
(apktool is quite easy to install, and then the command is simply apktool d example.apk)
I found the relevant intent filters (listed below) so there are many possible ways to launch the browser. Of course other browsers may have different intent filters, but it seems that APP_BROWSER is a good choice.
<activity-alias android:exported="true" android:name="com.google.android.apps.chrome.Main" android:targetActivity="org.chromium.chrome.browser.document.ChromeLauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.APP_BROWSER"/>
<category android:name="android.intent.category.NOTIFICATION_PREFERENCES"/>
</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="googlechrome"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:scheme="about"/>
<data android:scheme="javascript"/>
</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="googlechrome"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:scheme="about"/>
<data android:scheme="content"/>
<data android:scheme="javascript"/>
<data android:mimeType="text/html"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="multipart/related" android:scheme="file"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<intent-filter>
<action android:name="com.sec.android.airview.HOVER"/>
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable"/>
</activity-alias>
If you get these data URIs from somewhere you could do two things:
Parse the data content out of it and use it in some WebViewand call loadData(...) on it to display the contents
Save the data content of the URIs to some file, use FileProvider to make this file accessible outside of your app and use the URI returned by that to fire up a browser / view intent
I want to launch my app from a custom URL scheme. I checked the deep links section on dev android and here is a snippet of my code. This doesnt seem to fire though with a URL that looks like : myApp://?host=myhost.com
Manifest :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myApp" />
</intent-filter>
In the activity which is my main activity, i have :
Intent intent = getIntent();
Uri uri = intent.getData();
if (uri != null) {
String host = uri.getQueryParameter("host");
}
The app does not launch when i have email that has the url as a hyperlink.
Also, what would be a good way to test this ?
Try this, edit your IntentFilter
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.youtube.com" android:scheme="http"></data>
</intent-filter>
EDIT
<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"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.youtube.com" android:scheme="http"></data>
</intent-filter>
The browser converts the scheme to lowercase, so you need to change the data tag to
<data android:scheme="myapp"/>
k it looks like ACTION_VIEW is a must to support custom URI schemes. I can add VIEW and MAIN though which gets it to work.
I have a library project that displays pdfs. My main project has a few PDFs that I want to display. So I use it. Also, I have added intent filters for the activity that displays the pdf(so that other apps can also use it to display pdfs).
I want to detect if my PDFVIEWER was started by my own activity or not(I want to display the Title Bar if its started externally) how do I do that?
Here is my activity declaration:
<activity
android:name="com.artifex.mupdfdemo.MuPDFActivity"
android:theme="#android:style/Theme.Holo.Light"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/vnd.ms-xpsdocument"/>
<data android:mimeType="application/xps"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/pdf"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/x-cbz"/>
</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="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.xps"/>
<data android:host="*"/>
</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="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.pdf"/>
<data android:host="*"/>
</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="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.cbz"/>
<data android:host="*"/>
</intent-filter>
</activity>
I can't tell you, if it's possible to get the activity which started the intent, but as a workaround you can put a Boolean value in your Intent to make sure your PDFViewer was started by your app.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(fileUri);
intent.putExtra("myAppStarted", true);
And in your started activity:
boolean displayTitleBar = getIntent().getBooleanExtra("myAppStarted", false);
Please note it is recommended to use static final String variable with "myAppStarted" instead of hardcoding the String in different places.
You can use getCallingActivity, provided your activity was started using startActivityForResult. A better solution would be to add extra information into your intent that tells you if the calling activity is yours.
AppCompat.getReferrer() should return the package name of the Activity that started yours.