Pack my app and share with another + android

I am creating an Android application and I need a button to send my application to another phone.

I tried putting apk and sending to another, but I can not do this. I am 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 does not work.


I saw a Persian application: in the context menu, one of the elements was: “Send via Bluetooth”, and when I touched this, he sent the apk file to another phone.

I packed my application and put it in the Raw folder for sending, but this does not work correctly for the second or third phone.

he said: "I am creating an Android application, I have to put a button to send my application to another phone," I think he is talking about sending the same application in which it works.

Andrea Bellitto

Yes. I need to send the current application.

+3
source share
2 answers

I find code to change base.apk to a 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
source

allowed ...

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

All Articles