嗨,我正在尝试制作一个按钮,通过蓝牙和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")); }