I have created custom soft keyboard with images and my task is want to send selected image to the currently selected Application by the user like google hangout but i can get Installed application package name and icon using Package Manager like that if am using google hangout application means i have to get google hangout application package name and from my custom keyboard i have to share selected images directly to the hangout chat conversation as a message how can i solve this issue.
Asked
Active
Viewed 947 times
3 Answers
1
Try this:
String packageName = getApplicationContext().getPackageName();

blackgreen
- 34,072
- 23
- 111
- 129

Krunal Patel
- 61
- 3
- 12
1
From activity String appPackage = currentContext.getPackageName();
or
String appPackage = getApplicationContext().getPackageName();

Sreehari
- 5,621
- 2
- 25
- 59
-
thanks i found solution for that using this code ComponentName componentInfo = runningTaskInfos.get(0).topActivity; String currentpackagename = componentInfo.getPackageName(); Log.d("currentpackagename : ","#############"+currentpackagename); – MahaJeyaraj Jan 08 '16 at 07:31
-
@MahaJeyaraj i too had the same requirement as of yours, but the above you have mentioned always return android.app.launcher package – jagadesh Jul 29 '16 at 14:55
1
You can get all the installed package details.
public ArrayList<PackageInfoStruct> getInstalledApps(Activity mActivity) {
ArrayList<PackageInfoStruct> res = new ArrayList<PackageInfoStruct>();
List<PackageInfo> packs = mActivity.getPackageManager()
.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
PackageInfoStruct newInfo = new PackageInfoStruct();
newInfo.appname = p.applicationInfo.loadLabel(
mActivity.getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.datadir = p.applicationInfo.dataDir;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(mActivity
.getPackageManager());
res.add(newInfo);
}
return res;
}
public class PackageInfoStruct {
String appname = "";
String pname = "";
String versionName = "";
int versionCode = 0;
Drawable icon;
String datadir = "";
}
Call getInstalledApps
ArrayList<PackageInfoStruct> installedPackageDetails = getInstalledApps(getActivity());
You can use above method to display list of installed app and on selected you can details from as per selected item. PackageInfoStruct
class contains details for package

user1140237
- 5,015
- 1
- 28
- 56