Question

i'm trying to call share method from the app's i want, not just call list of all app that allow sharing. I'm using this code to call twitter share:

String tweetUrl = 
            String.format("https://twitter.com/intent/tweet?text=%s&url=%s",
            "Tweet text", "https://www.google.fi/");
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl));

        // Narrow down to official Twitter app, if available:
        List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
        for (ResolveInfo info : matches) {
            if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) {
                intent.setPackage(info.activityInfo.packageName);
            }
        }

        startActivity(intent);

This for facebook:

String fullUrl = "https://m.facebook.com/sharer.php?u=..";
    try {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setClassName("com.facebook.katana",
                "com.facebook.katana.ShareLinkActivity");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text");
        startActivity(sharingIntent);

    } catch (Exception e) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(fullUrl));
        startActivity(i);

    }

But it calls just to open browser, not facebook app that's installed on phone

And don't know how to do it for Vk

Was it helpful?

Solution

For Facebook i know only sharing with this facebook feed dialog

https://developers.facebook.com/docs/android/share

or

with this code for the browser

Session.openActiveSession(this, true, new Session.StatusCallback()
    {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

                share(session);
            }
        }
    });

}

private void share(Session mySession) {

    String message = "bla";

Bundle bundle = new Bundle();
bundle.putString("caption", "caption");
bundle.putString("description", message);
bundle.putString("link", "link");
bundle.putString("name", "title");
bundle.putString("picture", "");
new WebDialog.FeedDialogBuilder(this, mySession, bundle).build().show();
}

Hope it will help you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top