`ACTION_WEB_SEARCH` launching search action in Google app - android

I was trying to launch an Intent which will launch a browser and search query on Google. But the problem is that it is directly launching the search query on Google app instead of any browser. I have tested this on emulator and also in my Android device.
My Approach :
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,queryText);
startActivity(intent);

you can open browser using below intent
try{
String escapedQuery = URLEncoder.encode("Android developer", "UTF-8");
Uri uri = Uri.parse("http://www.google.com/#q=" + escapedQuery);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}catch (Exception e){
e.printStackTrace();
}

Related

Android intent open specific twitter in app

There is a way of knowing the id of the specific twitter that you want to open, to be able to open it in the official app.
I remember I found it long ago, but I can not remember.
I think it was a similar thing, but I'm not remembering.
Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://...?tweet_id=" + id));
appIntent.setPackage("com.twitter.android");
For launching a twitter user feed:
Intent intent = null;
try {
// get the Twitter app if possible
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERID_OR_PROFILENAME"));
}
this.startActivity(intent);

intent share facebook - Android

I want to share an image from android activity to facebook messenger app which is already opened in my device and reside in recent tasks of the android device.
I am using the below code to share the image but it is opening a new activity in messenger 'share seperately' but I want to share it to the already opened chat.
String mimeType = "image/*";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
activity.startActivityForResult(shareIntent, SHARE_TO_MESSENGER_REQUEST_CODE);
Facebook has restricted the text sharing over the post. It will either support a valid URL link sharing or Image Sharing. So I've posted the code which is referenced from https://stackoverflow.com/a/22994833/8331006
private void shareAppLinkViaFacebook(String urlToShare) {
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", urlToShare);
startActivity(intent1);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
}

Send package name to any market

i know there are some topics with this title. but all of them only works with GooglePlay.
i want to let users choose their favorite market. send package name to market and get results.
i also tested this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
but this is not supported by some markets.
You need a separate intent for Amazon Appstore and Google Play:
This bit of code figures out which store it was installed from, then tries Google Play and Amazon Appstore. If the intents fail, it falls back to the right web page
String installer = getPackageManager().getInstallerPackageName(getPackageName());
if ("com.amazon.venezia".equals(installer)) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("amzn://apps/android?p=com.monadpad...."));
startActivity(intent);
}
catch (Exception e) {
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com..."));
startActivity(browser);
}
}
else if ("com.android.vending".equals(installer)) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=com.monadpad..."));
startActivity(intent);
}
catch (Exception e) {
Intent browser = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=com.monadpad...."));
startActivity(browser);
}
}

Open Twitter application user profile from Android application

I'm able to start Twitter application (if it exists on the phone), yet I can't find how to automatically display a specific user profile.
Something like this works for Google+:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.apps.plus", "com.google.android.apps.plus.phone.UrlGatewayActivity");
intent.putExtra("customAppUri", "USER_ID");
Here is the Facebook way:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/USER_ID"));
startActivity(intent);
There should be the same kind of solution when I start Twitter app ?
Intent intent = getPackageManager().getLaunchIntentForPackage("com.twitter.android");
intent.putExtra("WHAT_TO_PUT_HERE?", "USER_ID");
startActivity(intent);
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + twitter_user_name)));
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + twitter_user_name)));
}
This is working fine with the new Twitter app. Solution provided by #Baptiste Costa didn't work for me.
try
{
// Check if the Twitter app is installed on the phone.
getPackageManager().getPackageInfo("com.twitter.android", 0);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.twitter.android", "com.twitter.android.ProfileActivity");
// Don't forget to put the "L" at the end of the id.
intent.putExtra("user_id", 01234567L);
startActivity(intent);
}
catch (NameNotFoundException e)
{
// If Twitter app is not installed, start browser.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/AndroTesteur")));
}
This is a very old question, I would like to shed some light into it. I have done it using either the user id or the username if that fails.
Intent intent;
try {
// Check if the Twitter app is installed on the phone.
context.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=813679215195410432"));
} catch (Exception e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/LynxMods"));
}
context.startActivity(intent);

Open page in Twitter app from other app - Android

I was looking for some way to launch Twitter app and open a specified page from my application, without webview.
I found the solution for Facebook here:
Opening facebook app on specified profile page
I need something similar.
[EDIT]
I've just found a solution:
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
Based on fg.radigales answer, this is what I used to launch the app if possible, but fall back to the browser otherwise:
Intent intent = null;
try {
// get the Twitter app if possible
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/PROFILENAME"));
}
this.startActivity(intent);
UPDATE
Added intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); to fix an issue where twitter was opening inside my app instead of as a new activity.
This worked for me: twitter://user?user_id=id_num
Open page on Twitter app from other app using Android in 2 Steps:
1.Just paste the below code (on button click or anywhere you need)
Intent intent = null;
try{
// Get Twitter app
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch () {
// If no Twitter app found, open on browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERNAME"));
}
2.intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
To get USER_ID just write username https://tweeterid.com/ and get Twitter User ID in there
Reference: https://solutionspirit.com/open-page-twitter-application-android/
My answer builds on top of the widely-accepted answers from fg.radigales and Harry.
If the user has Twitter installed but disabled (for example by using App Quarantine), this method will not work. The intent for the Twitter app will be selected but it will not be able to process it as it is disabled.
Instead of:
getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
You can use the following to decide what to do:
PackageInfo info = getPackageManager().getPackageInfo("com.twitter.android", 0);
if(info.applicationInfo.enabled)
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
else
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/wrkoutapp"));
Just try this code snippet. It will help you.
//Checking If the app is installed, according to the package name
Intent intent = new Intent();
intent.setType("text/plain");
intent.setAction(Intent.ACTION_SEND);
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : list)
{
String packageName = resolveInfo.activityInfo.packageName;
//In case that the app is installed, lunch it.
if (packageName != null && packageName.equals("com.twitter.android"))
{
try
{
String formattedTwitterAddress = "twitter://user/" ;
Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
long twitterId = <Here is the place for the twitter id>
browseTwitter.putExtra("user_id", twitterId);
startActivity(browseTwitter);
return;
}
catch (Exception e)
{
}
}
}
//If it gets here it means that the twitter app is not installed. Therefor, lunch the browser.
try
{
String twitterName = <Put the twitter name here>
String formattedTwitterAddress = "http://twitter.com/" + twitterName;
Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
startActivity(browseTwitter);
}
catch (Exception e)
{
}
For me this did the trick it opens Twitter app if you have it or goes to web browser:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+"USERID"));
startActivity(intent);
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
This answer was posted as an edit to the question Open page in Twitter app from other app - Android by the OP jbc25 under CC BY-SA 3.0.

Categories

Resources