Share via Google+..dialog complete action with shown - android

hi everybody i've a little problem..i'm trying to share a text using google plus app, but the lastest version give me a problem.
when i call with an intent "com.google.android.apps.plus", android display me this dialog
so if i choose the first one, text will be shared correctly, but the second one do nothing.
if the app is not intalled i redirect the user to the market, at g+ download page (this work fine)
if (v == plus) {
social(2);
targetedShareIntent.putExtra(
android.content.Intent.EXTRA_TEXT, user);
targetedShareIntent
.setPackage("com.google.android.apps.plus");
startActivity(targetedShareIntent);
}
"v" is a button and social check if app is installed
any sugestion?

both options open google+ application?
I suppose show two options because google+ app have two activities with category.LAUNCHER.... the app and the chat app
PSDT: sorry for my bad english!

I was able to get the G+ dialog to launch with the following code (after querying the package manager to make sure the app was actually installed and passing in the currentContext as a parameter):
Intent appIntent = new Intent(Intent.ACTION_SEND);
String shareText = "Share text goes here";
appIntent.setType("text/plain");
appIntent.putExtra(Intent.EXTRA_TEXT, shareText);
//Filters so only the G+ app will launch
appIntent.setPackage("com.google.android.apps.plus");
try {
currentContext.startActivity(appIntent);
} catch (android.content.ActivityNotFoundException e) {
Log.d(e.getMessage());
}
Drove me bananas figuring this out, so I figured I'd try to save someone else the hassle.

Related

How to open both WhatsApp and GB-Whatsapp using an Intent in your Android App

I want to open chooser for both whatsapp and gb-whatsapp so the user can choose any of one from them. This code is only opening whatsapp only.
Intent intentWhatsapp = new Intent(Intent.ACTION_VIEW);
String url = "https://chat.whatsapp.com/JPJSkaiqmDu5gLKqUPAfMM";
intentWhatsapp.setData(Uri.parse(url));
intentWhatsapp.setPackage("com.whatsapp");
startActivity(intentWhatsapp);
To handle business whatsapp, GB-Whatsapp and normal whatsapp, the url scheme intent needs to be used, since the normal method of using package "com.whatsapp" only works for normal whatsapp.
Here's the code sample to handle gb, normal and business whatsapp :
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("whatsapp://send?phone="+ "+92300xxxxxxx" +"&text=" + URLEncoder.encode("Message\n", "UTF-8")));
context.startActivity(i);
} catch (Exception e){
Toast.makeText(context, "Whatsapp not installed!", Toast.LENGTH_LONG).show();
}
Simple answer you can't.
More detailed answer: You can only create an Intent targeting one specific app. I would suggest building a dialogue inside your app, showing the app images of whatsapp and gb-whatsapp, and then putting specific intents behind those two images so that it "looks" like the Android chooser.

Android Apps' content sharing works perfectly on emulator, but crashes on real device

I'm a newbie to the android platform and I am developing an android app. Along with several features, there is a feature in the app and it is sharing contents like text, images etc. For initial testing I have used tablelayout, and inside this layout I have used rows and columns. More specifically there are only two columns. The first column contains some textual contents and the second column contains a button or label or text that represents "Share". And when any user taps the share option in the app, a popup will come out and user will get a list of goals (like Facebook, Twitter, Google+ etc.) where the user wants to share the content. So when I test this share option on the emulator it works fine, just perfect. But when I test the app on real device and taps the share option on real device, the app just crashes. I am not getting any idea why. Someone kindly suggest me the possible reasons for such problem. Thanks in advance. Below is my sample code I have used.
textContent = (TextView) findViewById(R.id.content);
shareContent = (TextView) findViewById(R.id.share_content);
shareContent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textContent.getText());
sendIntent.setType("text/plain");
getApplicationContext().startActivity(
Intent.createChooser(sendIntent, "Share..."));
}
});
A list of respective applications will open if they are already installed in the device. If not, then system will fire an exception. Guard your method with try-catch block. And check which application are installed to match with your intent's action.

Open Facebook native app from your android app

My question is directly connected with this one Open Facebook page from Android app? Which answer (for the version at the moment) is not the marked one but this one
public static Intent newFacebookIntent(PackageManager pm, String url) {
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
// https://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(url);
}
return new Intent(Intent.ACTION_VIEW, uri);
}
Which is confirmed working last on 7th of February 2015.
My question is should you use the whole url (like www.facebook.com/mypage) or just add the url of the page so it'll be fb://facewebmodal/f?href=mypage. I tried both and it just opens the fb app without an actual page. It shows blank fb page on both tries.
Can someone give me an example with url for some public page that works?
You can try to write mypage as https://www.facebook.com/ID. The whole uri should then be
fb://facewebmodal/f?href=https://www.facebook.com/ID
and change ID to the page you want to visit.
That functionality is not documented or supported, so you may get unknown result. You may want to try passing the Page ID or Profile ID instead of names. You can get the ID by calling https://graph.facebook.com/<name> and parse the result.
I had the same issue. I searched for a while and tried all the answers on here Open facebook page from android app (in facebook version > v11) and there Open Facebook page from Android app?, finally I figured out what the real problem is. There is nothing wrong in the code, however the weird behavior is about facebook app itself. If the facebook app is on the background, it just switches back to the foreground without navigating to the requested page. You just swipe it out from the background (kill instances) and try your code again.
Considering most of the users leave facebook app on the background, this is some kind of an issue needs to be fixed. Although I think it is about the facebook app itself, somehow it can be related with the device. I'm using Nexus 6 with v 6.0.1 and had no chance to test it on another android versioned device.
i using this for my apps its working just fine, kotlin
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/100674618166286"));
startActivity(intent);
} catch(e: Exception) {
startActivity( Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/iqtousd")));
}
Remember have a similar issue.
Try the mobile url :
instead of
String facebookUrl = "https://facebook.com/...";
use
String facebookUrl = "https://m.facebook.com/...";

App force closes when google+ is not installed

My requirement is to share on Social networking sites. So, I have already done with Facebook and Twitter. But I am stuck with Google+. I have the following code to share on Google+, but the app forcecloses when I start activity. This occurs only when the Google+ app isn't installed on device already. I know this sharing intent requires the Google+ already installed to start the activity.
Now what I need to do is at least to inform the user that the google+ sharing requires already installed google+ app through dialog or toast instead of getting force closed (If possible by clicking on ok on the dialog should redirect to the google+ on google play). If the google+ app is installed already it goes as usual.
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Hello there! This is a pic of the lazy cat")
.setType("image/jpeg")
.setStream(Uri.parse(path))
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
Any help is appreciated. Thanks in advance.
UPDATE
The answer below is outdated. You can now check if the Google+ app is installed through the Google Play Services library (available through the Android SDK). See here for information how to add it to your project.
Example:
int errorCode = GooglePlusUtil.checkGooglePlusApp(mContext);
if (errorCode != GooglePlusUtil.SUCCESS) {
//Google+ is either not present or another error occured, show the error dialog
GooglePlusUtil.getErrorDialog(errorCode, this, 0).show();
}
else{
//Your Google+ related code here
}
OLD ANSWER
You can create some sort of check to see if the Google+ app is installed:
public void loadGooglePlus()
{
if(isGooglePlusInstalled())
{
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Hello there! This is a pic of the lazy cat")
.setType("image/jpeg")
.setStream(Uri.parse(path))
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
}
else{
//Notify user
}
}
public boolean isGooglePlusInstalled()
{
try
{
getPackageManager().getApplicationInfo("com.google.android.apps.plus", 0 );
return true;
}
catch(PackageManager.NameNotFoundException e)
{
return false;
}
}

Using facebook.katana aka facebook app from the code

i´m trying to achieve a solution where the app ask if facebook.katana aka facebook app is installed in your android phone, if it is installed, check if the user is logged, and if it's logged send a picture with a text (better if it is to a folder), if the user is not logged go to the facebook.katana.LoginActivity and log him, after that make the procedure.
I have this working with a Web View, but i'm interested on how to do it using the app if possible, what i got so far is the uncompiled facebook.katana in this URL where i'm testing the activities:
http://xt720.ru/miui-trans/apk-decompiled/Facebook/smali/com/facebook/katana/
I also know that an image can be attached to that app, since can start the facebook app using this:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM,imageUri);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Whatever");
startActivity(Intent.createChooser(emailIntent, "Send email using"));
This method would be great for an email, but as it says it creates a chooser, but i don't want to let that option open. So i tried something like:
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
Also you can use the ShareLinkActivity to add an extra to your intent like this:
intent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com/");
The problem is that i don't see how to attach the image to the katana, neither, how to add it to a folder, or how to add it through an application, of course this is much easier via facebook API for android, but like i said that's already done, i want to make it with the facebook App, i have tried, attaching the Bundle to the app as a parcelable, with the usual way it is done in the API, but not luck, this is the snippet:
Bundle params = new Bundle();
params.putByteArray("picture", bitmapdata);
params.putString("title", url);
params.putString("message","Wathever message");
and try to send the params, also tried sending only the image, but not luck, maybe i'm not using the right class (see the uncopiled facebook.katana URL) or i´m attaching in a bad way the info, it should work somehow, cause it works for ACTION_SEND, so, anybody knows how to solve any of this problems:
Attach an image to the facebook.katana
Attach an image to the facebook.katana in a folder
Attach an image to the facebook.katana as an external app
Request the log status of the user to the facebook.katana (i think this would be automatically)
Attach the picture, title, message params to the facebook.katana.
Publish as the app that opens the facebook.katana (i.e. publishin with the WebView will show "published from X app"

Categories

Resources