hamedh.1990 hamedh.1990 - 1 month ago 12
Android Question

packing my app and share to other + android

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 an persian app do this ...

in context menu 1 item was :"Send via Bluetooth" and when touch this , send the apk file to other phone ...!

i pack My app and put it to Raw folder to send , but this is not work correctly for 2nd or 3rd phone !!

please write correct code ...


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 send my running application

Answer

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