【问题标题】:I need to share a phrase that is randomly generated我需要分享一个随机生成的短语
【发布时间】:2016-05-02 23:19:19
【问题描述】:

我需要一个字符串来分享我的代码在下面随机生成一个句子,不能分享或复制粘贴所选的短语。对不起我的英语

public class MainActivity extends ActionBarActivity {


    private TextView textViewNewId;
    private Button buttonNewId;

    private String[] frases = {
        "First phrase", "second phrase", "third phrase"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        textViewNewId = (TextView) findViewById(R.id.textViewNewId);
        buttonNewId = (Button) findViewById(R.id.buttonNewId);

        buttonNewId.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Random randomico = new Random();
                int numeroAleatorio = randomico.nextInt( frases.length );

                textViewNewId.setText( frases[ numeroAleatorio ]);
            }
        });

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View vivew) {

                fab();
                // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                 //     .setAction("Action", null).show();
            }
        });
    }

    private void fab() { //sharing implementation here
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "AndroidSolved");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Now Learn Android with AndroidSolved clicke here to visit ");
        startActivity(Intent.createChooser(sharingIntent, "Share via"));


    }

result of my code

【问题讨论】:

    标签: java android android-studio mobile share


    【解决方案1】:

    您可以将所选文本传递给您的意图并分享。我做以下事情:

    public static void shareOnSocials(Context context , String shareThings) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, shareThings);
            context.startActivity(Intent.createChooser(intent, "HOOORA"));
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-05
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      相关资源
      最近更新 更多