Доля АПК с помощью опциона на акции в Android


Привет, я пытаюсь сделать кнопку, которая делится моим приложением через другие носители, такие как Bluetooth и 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 или приложением через это???

1 2

1 ответ:

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"));
    }