Android share action. Trigger from navigation drawer rather than top bar. - android

My app has a navigation drawer and as one of its options on the left side I would like it to have "Share with friends". User can tap on Share with friends menu option and will trigger Android native Share action. Is it possible? Can you share with me a link on Tutorial or code sample on how to trigger Android Share action from other places like left side menu for example rather than top bar.
Thank you!

You can do this:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "message to share");
startActivity(Intent.createChooser(share, "title"));

Related

How to show sharing menus within activity?

I want to share a text using this:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
As you can see in the below picture, I know how to acheive a dialog which lets user picks his choice (My app). But recently I saw an app which is letting users pick their choice within its activity (Desired).
Any idea how to acheive desired one? Thank you all.
This is the code, I've been using for sharing 'Referral Code' from within my app:
ShareCompat.IntentBuilder
.from(this) // getActivity() or activity field if within Fragment
.setText("message") // This will be populated as user's message
.setType("text/plain") // most general text sharing MIME type
.setChooserTitle("Share code using:")
.startChooser();
It opens up a view similar to your right image.
Create Custom layout. (Right image)
Embed in BottomSheetLayout
Use setState() to show your "Share Screen"
................................................
or You can just do the same inside an AlertDialog. (Left Image)
You can query for the list of apps that are registered to handle the action and then display the result in the way that you like the most. When the user will choose something you can start the selected activity.

Show share menu like other apps on my android phone

I have added share action on my app's actionbar and followed these steps:
http://www.codewithasp.net/2016/11/share-action-provider-android-application-actionbar-appcompat-v7.html
This is showing a nice simple looking share menu on my actionbar. But problem is that all other application on my phone have different share menu and all of them are similar.
Here is how my share menu look:
Here is how other apps showing share menu on my device
Instead of creating a drop-down menu with share options, you should just call share intent once you've clicked on share button or menu option. That way the list of possible apps would be shown as on the example you've pasted.
Here is an example of how could you do it.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
sendIntent.setType("text/plain");
getContext().startActivity(sendIntent);
There was one more thing to add in SadClown's answer and I got what I wanted. Actually while calling startActivity instead of just pass your share intent we need to call intent chooser
getContext().startActivity(Intent.createChooser(sendIntent, "Share"));
It is explained here in detail

facebook and WhatsApp not appearing in "complete action using:" list when started from my app

I want to start the facebook app or the WhastApp app from my own app but they wont appear in the "Complete action using:" list
I have
Intent intentFB = new Intent(Intent.ACTION_MAIN);
intentFB.setComponent(ComponentName.unflattenFromString("com.facebook"));
intentFB.putExtra("ClassName","FB");
intentFB.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
intentFB.addCategory(Intent.CATEGORY_LAUNCHER);
intentFB.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentFB);
Basiclly I have a webview with a page with an article. This page has a facebook link to share the article. When I tap the link the list appear without the facebook option

What is the name of the new bottom menu in Lollipop

I'd like to use the new bottom menu of lollipop, but I don't know the name of the View. Does anyone know its name? This menu can be used to shows video?
This menu shows on long click on the home.
Bottom menu? It's a simple Share Intent view that the OS pop out.
You can get it via:
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Test text");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Test subject"));
shareIntent.setType("text/plain");
context.startActivity(shareIntent);
Or instead of starting the activity like this, you can do the following:
startActivity(Intent.createChooser(shareIntent, "Share is via..."));
That's the menu created by the Intent#createChooser(Intent, CharSequence) method. And I doubt you can show video via it.

In share option in dialog box, I want to add my custom intent option

I am using this code to share link in android app.
Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject test");
i.putExtra(android.content.Intent.EXTRA_TEXT, "extra text that you want to put");
startActivity(Intent.createChooser(i,"Share via"));
But i want to add cutom intent option in dialoag box.
If i have twitter and facebook app in my phone, then above code give me share option
1) Twitter
2) Facebook
3) Bluetooth(if phn supported)
Also with this I want to add
4) Commnets (on comments click user will go my Comment activity)
I want to make share like this.
Can anyone help. Thanks in advance.
You are creating a chooser. It contains all intents that reply to ACTION_SEND text/plain.
To have your comment activity in that list, you need make an intent-filter in your manifest matching that actions for your comment Activity.
Alternatively (and moreeasily, too), if you don't want your Comment activity to respond to external ACTION_SEND text/plain, you can use the response given to this question : Custom filtering of intent chooser based on installed Android package name : Add a Intent.EXTRA_INITIAL_INTENTS extra to the intent.

Categories

Resources