简体   繁体   English

如何从活动向Google+和Facebook添加共享应用程序按钮?

[英]How to add share application button from activity to google+ and facebook?

I am building android application now i already completed, but I want to add Share button in root activity that user can share my application(link to download from google market) to google+ , facebook, twitter and linkin. 我现在已经完成构建Android应用程序,但是我想在root活动中添加“共享”按钮,以便用户可以将我的应用程序(从Google市场下载的链接)共享到google +,facebook,twitter和linkin。

How can i do it? 我该怎么做?

my code: 我的代码:

ImageButton sharingButton = (ImageButton) findViewById(R.id.share);
    sharingButton.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    sharingButton.setImageResource(R.drawable.ic_share);

sharingButton.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            { 
                shareIt();
            }
        });


private void shareIt()
{
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    String shareBody = "Here is the share content body";
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, "Share via"));
}

I tried this but doesn't give me a result. 我尝试了这个,但没有给我结果。 Can you please help me? 你能帮我么?

regards, 问候,

These Couple of lines worked for me maybe you can try it : 这些几行对我有用,也许您可​​以尝试:

            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com/");

    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subjecttest");

    startActivity(Intent.createChooser(sharingIntent, "Choose option"));

I am also guessing that the button you have is getting clicked but the shareintent is'nt working, if there is an error before that part then maybe its not the shareintent but the button declaration and xml issue 我还猜测您的按钮正在被单击,但shareintent无法正常工作,如果在该部分之前出现错误,则可能不是共享意图,而是按钮声明和xml问题

如果您prefere由你自己做,一个图书馆,你应该使用前页: http://support.addthis.com/customer/portal/articles/381271-addthis-for-android-quickstart-guide

Try this in menu: 在菜单中尝试:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_share"
          android:title="@string/share"
          android:showAsAction="ifRoom"
          android:actionProviderClass="android.widget.ShareActionProvider" />
    ...
</menu>

Read: http://developer.android.com/reference/android/widget/ShareActionProvider.html 阅读: http : //developer.android.com/reference/android/widget/ShareActionProvider.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM