Sharing button only in facebook and twitter apps in dialog

I want to add a sharing button to my application, and I did the following:

final Intent shareIntent = new Intent(Intent.ACTION_SEND); /* Fill it with Data */ shareIntent.setType("plain/text"); shareIntent.putExtra(Intent.EXTRA_TEXT, "www.somesite.com"); /* Send it off to the Activity-Chooser */ startActivity(Intent.createChooser(shareIntent, "Share...")); 

It shows a dialog, and I do not see facebook and twitter in this dialog. I have both of these applications installed on my phone. So the first question is - why doesn't he show them? And second , if later I somehow show them on the phone how to make this dialogue show only facebook and twitter, and if the user does not have them, ask the user to simply install it by indicating the link to the official application.

+4
source share
2 answers

You can check them using the code below,

How to set up sharing intent in Android?

Android intention for Twitter application

I saw a lot of questions about changing application choices, and they all seem to say no, you cannot change the built-in selection of applications, but you can create your own custom selection using queryIntentActivities () in the PackageManager class.

 try{ ApplicationInfo info = getPackageManager().getApplicationInfo("com.facebook.katana", 0 ); return true; } catch( PackageManager.NameNotFoundException e ){ return false; } try{ ApplicationInfo info = getPackageManager().getApplicationInfo("com.twitter.android", 0 ); return true; } catch( PackageManager.NameNotFoundException e ){ return false; } 
+5
source

After successful login.

 public class ShareOnTwitterTrophy extends AsyncTask<String, Integer, Long> { private Activity mActivity; private Bitmap bitmap; public ShareOnTwitterTrophy(Activity mActivity,Bitmap bitmap) { this.mActivity=mActivity; this.bitmap=bitmap; } protected void onPreExecute() { } @Override protected Long doInBackground(String... arg0) { long result = 0; // TwitterSession twitterSession = new TwitterSession(activity); // AccessToken accessToken = twitterSession.getAccessToken(); AccessToken accessToken = new UserSharedPreference(mActivity).getTwitterAccessToken(); if (accessToken != null) { Configuration conf = new ConfigurationBuilder() .setOAuthConsumerKey("your key") .setOAuthConsumerSecret( "your secret") .setOAuthAccessToken(accessToken.getToken()) .setOAuthAccessTokenSecret(accessToken.getTokenSecret()) .build(); ImageUploadFactory factory = new ImageUploadFactory(conf); ImageUpload upload = factory.getInstance(); Log.d("", "Start sending image..."); try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); // you can create a new file name "test.jpg" in sdcard // folder. String imagePath = Environment .getExternalStorageDirectory() + File.separator + "test.jpg"; File f = new File(imagePath); f.createNewFile(); // write the bytes in file FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray()); // remember close de FileOutput fo.close(); upload.upload(f, ""); Log.e("Image Uploaded", "yayeeeee"); result = 1; } catch (Exception e) { Log.e("image upload failed", "awwwww :("); e.printStackTrace(); } return result; } return result; } @Override protected void onPostExecute(Long result) { if (result == 1) Toast.makeText( mActivity, mActivity .getString(R.string.twitter_shared_successfully), Toast.LENGTH_LONG).show(); } 
+1
source

All Articles