您好,我正试图通过蓝牙和其他媒体制作一个共享我的应用程序的按钮。分享它。我试过这个
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文件或应用程序答案 0 :(得分:11)
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"));
}