我正在创建一个Android应用程序,我需要一个按钮将我的应用程序发送到另一部手机.
我试图把一个apk发送到其他但我不能这样做.
我正在使用此代码:
Intent sharei=new Intent(Intent.ACTION_SEND);
sharei.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.packa.ge/raw/hafez.apk"));
sharei.setType("application/vnd.android.package-archive");
startActivity(Intent.createChooser(sharei, "share"));
但它不起作用.
我看到一个波斯应用程序执行此操作:在上下文菜单中,其中一项是:“通过蓝牙发送”,当我触摸它时,它将apk文件发送到另一部手机.
我打包我的应用程序并将其放到Raw文件夹发送,但这对第二或第三部手机无法正常工作.
he said: “i create a application for android i need put button to send my application to other phone”, i think he is talking about sending the same application he is running….
Andrea Bellitto
是.我需要发送正在运行的应用程序.
解决方法:
解决 …
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(getPackageName(), 0);
File srcFile = new File(ai.publicSourceDir);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/vnd.android.package-archive");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(srcFile));
startActivity(Intent.createChooser(share, "PersianCoders"));
} catch (Exception e) {
Log.e("ShareApp", e.getMessage());
}