【问题标题】:Intent.ACTION_SEND to share text worked well before, but failed nowIntent.ACTION_SEND 分享文本之前效果很好,但现在失败了
【发布时间】:2017-10-31 23:48:49
【问题描述】:

我使用下面相同的代码将文本分享到 Line、Wechat、... 它以前运行良好,但现在它不会向其他应用程序传输任何内容。尽管我追踪到 sendIntent(下)中的所有内容都相同且正确。有没有人有类似的经历? 提前感谢您的任何建议!


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)  .setAction("Action", null).show();
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, editText.getText()); //EditText..getText() is Editable, still can get string
            sendIntent.setType("text/plain");
            startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
        }
    });

【问题讨论】:

    标签: android action share send


    【解决方案1】:
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
     fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
              Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
              sharingIntent.setType("text/plain");              
              sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject here");
              sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, voiceTextView.getText());
              startActivity(Intent.createChooser(sharingIntent, "Sharing Option"));
    
         }
    });
    

    【讨论】:

    • 太棒了!它确实有效,虽然我现在不知道为什么。我会研究细节。你为我节省了很多时间。谢谢!
    猜你喜欢
    • 2014-04-29
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2016-01-28
    • 1970-01-01
    相关资源
    最近更新 更多