packing my app and share to other + android

旧时模样 提交于 2019-12-01 05:43:32

问题


I'm creating an application for Android and I need a button to send my application to another phone.

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"));

but it isn't working.


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.

I packed My app and put it to Raw folder to send, but this is not work correctly for 2nd or 3rd phone.

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.


回答1:


resolved ...

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());
}



回答2:


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());
        }


来源:https://stackoverflow.com/questions/21816382/packing-my-app-and-share-to-other-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!