I want to share my app through every possible installed apps on user device.. I mean my apk file itself not just a link of my app .. how can I do this ?
-
Possible duplicate of [How to Share Entire Android App with Share Intent](http://stackoverflow.com/questions/13941093/how-to-share-entire-android-app-with-share-intent) – Arun Shankar Mar 19 '17 at 09:12
-
@ArunElectra I already saw, That is about sharing text not a file – DastakWall Mar 19 '17 at 09:15
-
Plese try my answer – Arun Shankar Mar 19 '17 at 09:26
1 Answers
First of all, SO is not a developer on hire service. You should try something, and then if you hit a roadblock, then ask here for help,describing your problem.
Edit 2
Found another piece of code here
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());
}
Edit
Try this code (From Here)
ArrayList<Uri> arrayListapkFilepath; // define global
//put this code when you wants to share apk
arrayListapkFilepath = new ArrayList<Uri>();
shareAPK(getPackageName());
// you can pass bundle id of installed app in your device instead of getPackageName()
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("application/vnd.android.package-archive");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
arrayListapkFilepath);
startActivity(Intent.createChooser(intent, "Share " +
arrayListapkFilepath.size() + " Files Via"));
//Method
public void shareAPK(String bundle_id) {
File f1;
File f2 = null;
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
int z = 0;
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
if (info.activityInfo.packageName.equals(bundle_id)) {
f1 = new File(info.activityInfo.applicationInfo.publicSourceDir);
Log.v("file--",
" " + f1.getName().toString() + "----" + info.loadLabel(getPackageManager()));
try {
String file_name = info.loadLabel(getPackageManager()).toString();
Log.d("file_name--", " " + file_name);
f2 = new File(Environment.getExternalStorageDirectory().toString() + "/Folder");
f2.mkdirs();
f2 = new File(f2.getPath() + "/" + file_name + ".apk");
f2.createNewFile();
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
// byte[] buf = new byte[1024];
byte[] buf = new byte[4096];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage() + " in the specified directory.");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
arrayListapkFilepath.add(Uri.fromFile(new File(f2.getAbsolutePath())));
}
Old Answer To answer your question, it is not possible to share your "apk" through "app through every possible installed apps" for obvious reasons. Of-course You can write code to share your apk through bluetooth or LAN Wifi, and, you could attach your apk to a mail/supported messaging services. But it is not possible to do as "you put that".
You can copy your apk to some place by using this code
File file = new File(getPackageManager().getPackageInfo(getPackageName(), 0).publicSourceDir);
// Copy the .apk file to wherever
And you can share it using Bluetooth/Wifi/Intent with ACTION_SEND by attaching the apk you saved/copied. But as far as I know, very few messagin apps permits sending apk files.
This Article will help you in sharing files :

- 1
- 1

- 2,603
- 2
- 26
- 36
-
Can I change ACTION_SEND_MULTIPLE to just ACTION_SEND in this method without losing valid content ? – DastakWall Mar 19 '17 at 09:35
-
Yes, you can as long as you are sending only one file. https://developer.android.com/training/sharing/send.html – Arun Shankar Mar 19 '17 at 09:45
-
Yes , It works .. actually I tried this answer before I ask my own question but I had problem with ACTION_SEND_MULTIPLE .. this will reduce apps that are capable of sharing my application.. – DastakWall Mar 19 '17 at 09:51
-
@DastakWall have you tried the latest update? NB : If my answer helped, please accept it and upvote :-) – Arun Shankar Mar 19 '17 at 09:53
-