【问题标题】:Send multiple text items in ShareIntent?在 ShareIntent 中发送多个文本项?
【发布时间】:2019-06-10 09:40:58
【问题描述】:

我的问题与这些问题非常相似:

Is it possible to share multiple text by using share intent?

Passing Multiple text/plain values in share intent

我已经尝试了建议的解决方案,但没有奏效。我正在尝试发送两个项目:共享意图中的“名称”和“到达时间”。通过 AsyncTask 和 RecyclerView 将两个文本(字符串)下载到活动中的数据在下面的方法中。

//正在初始化

  Schedule stationArrival;
            private String stationShareStationName;
            private String stationShareArrivalTime;


 @Override
    public void returnScheduleData(ArrayList<Schedule> simpleJsonScheduleData)
    {
        if (simpleJsonScheduleData.size() > 0) {
            scheduleAdapter = new ScheduleAdapter(simpleJsonScheduleData, StationScheduleActivity.this);
            scheduleArrayList = simpleJsonScheduleData;
            mScheduleRecyclerView.setAdapter(scheduleAdapter);
            scheduleAdapter.setScheduleList(scheduleArrayList);

            stationArrival = scheduleArrayList.get(0);

            stationShareStationName = stationArrival.getStationScheduleName();
            stationShareArrivalTime = stationArrival.getExpectedArrival();     
        }
       else
        {
            Toast.makeText(StationScheduleActivity.this, "Data currently unavailable", Toast.LENGTH_SHORT).show();
        }
        if (mShareActionProvider != null)
        {
            mShareActionProvider.setShareIntent(createShareIntent());
        }
    }

ShareIntent 代码。目前这是错误的,因为共享屏幕中仅显示一项。我试图将这两个项目放入一个 ArrayList 中,但它不起作用,因为我有一个单独的 ShareIntent 方法。有没有办法在不重组当前代码的情况下做到这一点?先感谢您。

public Intent createShareIntent()
    {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT,stationShareStationName);
        shareIntent.putExtra(Intent.EXTRA_TEXT,stationShareArrivalTime);
        return shareIntent;
    }

【问题讨论】:

    标签: android android-intent send parcelable share-intent


    【解决方案1】:

    您可以连接两个 stationShareStationNamestationShareArrivalTime 并制作单个字符串。您还可以在这些变量(“\n”)之间使用换行符,如下所示:

    public Intent createShareIntent()
    {
        String stationShareStationName ="xxx";
        String stationShareArrivalTime = "xxx";
        String data =stationShareStationName + "\n" + stationShareArrivalTime
    
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT,data);
        return shareIntent;
    }
    

    【讨论】:

    • 解决了!感谢您的超级快速回复。实际上,我认为您必须在其他方法中连接字符串。
    • @LeadBox4 很高兴它对您有所帮助。您可以通过单击正确的符号来接受答案,这样可以帮助其他人识别正确的答案。
    猜你喜欢
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 2020-06-20
    • 2014-03-30
    • 2015-03-15
    相关资源
    最近更新 更多