Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending APK file android

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));
like image 735
Ata Avatar asked Jun 30 '13 14:06

Ata


People also ask

How do I send an APK file to my phone?

To do this, open the folder where you downloaded the file. Right-click the APK file. Click Send to. Select your Android.

Can you send an APK through email?

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 .

Can I send APK file via WhatsApp?

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.

How do I distribute APK files?

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.


2 Answers

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){}
like image 113
Mahdi-bagvand Avatar answered Oct 12 '22 14:10

Mahdi-bagvand


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.

like image 34
Jayesh Khasatiya Avatar answered Oct 12 '22 15:10

Jayesh Khasatiya