通过 android 中的共享选项共享 APK

Share APK via share option in android

您好,我正在尝试制作一个按钮,通过蓝牙和 ShareIt 等其他媒体共享我的应用程序。我试过这个

public void onClick(View view) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Share this application");
    sendIntent.setType("text/plain");
    startActivity(sendIntent);
}

这适用于共享一些文本。现在我如何通过它分享我的 apk 文件或应用程序???

private void shareApplication() {
        ApplicationInfo app = getApplicationContext().getApplicationInfo();
        String filePath = app.sourceDir;

        Intent intent = new Intent(Intent.ACTION_SEND);

        // MIME of .apk is "application/vnd.android.package-archive".
        // but Bluetooth does not accept this. Let's use "*/*" instead.
        intent.setType("*/*");


        // Append file and send Intent
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));
        startActivity(Intent.createChooser(intent, "Share app via"));
    }