打包我的应用程序并分享给其他 + android [英] packing my app and share to other + android
问题描述
我正在为 Android 创建一个应用程序,我需要一个按钮来将我的应用程序发送到另一部手机.
I'm creating an application for Android and I need a button to send my application to another phone.
我尝试放置一个 apk 并发送给其他人,但我无法做到.我正在使用此代码:
I tried to put an apk and send to other but I can't do it. I'm using this code :
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 文件发送到另一部手机.
I saw a Persian app do this: in a context menu one of the items was :"Send via Bluetooth" and when I touched this, it sent the apk file to the other phone.
我打包了我的应用程序并将其放入 Raw 文件夹中进行发送,但这不适用于第二部或第三部手机.
I packed My app and put it to Raw folder to send, but this is not work correctly for 2nd or 3rd phone.
他说:我为 android 创建了一个应用程序,我需要放置按钮才能将我的应用程序发送到其他手机",我认为他正在谈论发送他正在运行的相同应用程序....
安德里亚·贝利托
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
是的.我需要发送我正在运行的应用程序.
Yes. I need to send my running application.
推荐答案
我找到了将 base.apk 更改为特殊文件名的代码...
i find the code for changing base.apk to special file name ...
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(getPackageName(), 0);
File srcFile = new File(ai.publicSourceDir);
File outputFile = new File(Environment.getExternalStorageDirectory(),
"hamed-heydari_Com" + ".apk");
Tools.copy(srcFile, outputFile);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_TEXT, Tools.getStringByName("installApp") + " " + Tools.getStringByName("app_name"));
share.setType("application/vnd.android.package-archive");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
startActivity(Intent.createChooser(share, "Share App ..."));
} catch (Exception e) {
Log.e("ShareApp", e.getMessage());
}
这篇关于打包我的应用程序并分享给其他 + android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!