通过android中的股票期权共享APK
嗨,我正在尝试制作一个按钮,通过蓝牙和ShareIt等其他媒体共享我的应用程序。我试过这个通过android中的股票期权共享APK,android,bluetooth,apk,share,media,Android,Bluetooth,Apk,Share,Media,嗨,我正在尝试制作一个按钮,通过蓝牙和ShareIt等其他媒体共享我的应用程序。我试过这个 public void onClick(View view) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Share this application"); sendIntent.se
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文件或应用程序???谢谢@AliEsmaeili这就是我要找的。
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"));
}