项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd

示例如下:

/ipc/ShareSourceDemo1.java

/**
 * 本例用于演示“分享源”
 *
 * 注:
 * 1、关于“分享目标”请参见 AndroidDemoIpc 项目中的 ShareTargetDemo1.java
 */

package com.webabcd.androiddemo.ipc;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import com.webabcd.androiddemo.R;

public class ShareSourceDemo1 extends AppCompatActivity {

    private Button mButton1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ipc_sharesourcedemo1);

        mButton1 = findViewById(R.id.button1);

        sample();
    }

    private void sample() {
        Intent intent = new Intent();
        // 设置 action 为发送分享
        intent.setAction(Intent.ACTION_SEND);
        // 设置 type 为发送纯文本内容
        intent.setType("text/plain");
        // 设置需要分享的数据
        intent.putExtra(Intent.EXTRA_TEXT, "我是分享内容");

        // 弹出系统分享
        startActivity(Intent.createChooser(intent, "系统分享框的 Title 上显示的信息"));
        // startActivity(Intent.createChooser(intent, getResources().getText(R.string.app_name)));
    }
}

/layout/activity_ipc_sharesourcedemo1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="分享文本数据" />

</LinearLayout>

项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd

相关文章:

  • 2022-01-07
  • 2021-09-13
  • 2021-11-26
  • 2022-01-11
  • 2021-07-26
  • 2021-06-21
  • 2021-04-11
猜你喜欢
  • 2021-08-24
  • 2021-08-23
  • 2022-02-17
  • 2022-02-24
  • 2021-11-30
  • 2021-11-15
  • 2022-01-11
相关资源
相似解决方案