I use this code to send the app's APK file to another device. It works on android 2.3.3, but is not working on android 4+.
Where is the problem?
I have logged the getpackageCodePath()
and it returns the APK file on android 4+, but the whole code is not working, and when Bluetooth starts, it sends nothing.
ArrayList<Uri> uris = new ArrayList<Uri>();
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("application/vnd.android.package-archive");
uris.add(Uri.parse(getApplication().getPackageCodePath()));
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, null));
To do this, open the folder where you downloaded the file. Right-click the APK file. Click Send to. Select your Android.
You cannot attach the file in your email directly, since APKs are treated as junk by most email providers. So upload the apk somewhere and send the link to your co-worker. If a link is not enough, with a simple trick, you can send the file anyway: Rename the file: attach .
You have to take backup of the desired Application you want to send. Then go to file manager on your smartphone and locate the apk file you want to send. Select the apk file and tap on share it using WhatsApp then select the contact you want to send that file.
Distributing your apps by email To do this, you prepare the app for release, attach it to an email, and send it to a user. When the user opens your email on their Android-powered device, the Android system recognizes the APK and displays an Install Now button in the email message.
I use below code for send apk. and it works
try{
ArrayList<Uri> uris = new ArrayList<Uri>();
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("application/*");
uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir)));
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, null));
}catch(Exception e){}
Change the line :
uris.add(Uri.parse(getApplication().getPackageCodePath()));
to
uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir)));
and it should work in all 4.x devices. Alternatively you can also do something like this:
ApplicationInfo app=getPackageManager().getApplicationInfo("packageName", 0);
uris.add(Uri.fromFile(new File(app.publicSourceDir)));
Both of the above ways work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With