I want to make an application that could send itself (apk file) by bluetooth. but i have trouble with finding the apk file path. i tried this code:
final PackageManager pm = this.getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
String st = null;
for (PackageInfo packageInfo : packages) {
if(packageInfo.packageName.contains("testbutton"))
st=packageInfo.packageName;
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
String uri = "/data/app/";
uri+=st;
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
startActivity(intent);
but st returns null value. please help me with this. thanks in advance
There is no need to iteration. Getting the application itself APK file uri is as easy as this:
Also note that doc says this about
publicSourceDir
:And also note that to send an APK file, you need to set the type to
application/vnd.android.package-archive
instead ofimage/*
So the complete snippet would be:
Outputs something like this:
So, this way you will find path of all apps apk.
finally i'd found the right answer that works in this purpose, thanks to @Kanak for her help :)