packing my app and share to other + android

前端 未结 2 1741
谎友^
谎友^ 2021-01-14 19:02

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\'

相关标签:
2条回答
  • 2021-01-14 19:36

    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());
    }
    
    0 讨论(0)
  • 2021-01-14 19:45

    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());
            }
    
    0 讨论(0)
提交回复
热议问题