Android get install location with packagename - android

Hi i used the following code from this tutorial to list all of the installed applications in an app i'm working on.
http://impressive-artworx.de/2011/list-all-installed-apps-in-style/
I changed the onClick to my own dialog and what i now need to do is be able to get the location of the app. That is if it's in /system/app or /data/app i'd like to be able to toast the entire path to the pressed app but can't figure out how to do this. I can get the packagename by doing app.getPackageName() in the onClick but how can i get the apks path with this? Thank you for any suggestions or help it is much appreciated!

After a bit more googling i got what i was looking for
PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.sourceDir;
worked very well found it here
Get Application Directory
thanks for the help it helped with my googling as to what to look for

Take a look at this . In particular the snippet with publicSourceDir .

List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
// skip system apps if they shall not be included
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
continue;
}
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
CharSequence description = p.applicationInfo.loadDescription(packageManager);
app.setDescription(description != null ? description.toString() : "");
apps.add(app);
}
u can use this code to get the information of installed Applications.

Related

How to know an app's target sdk version

I'm doing some android analysis and need to find all the android app that have targetSdkversion over 23, right now I'm reverse engineering all the apk packages to see this...Wondering if there's more easy way to get this information given an app name?
Thanks :)
you can do that by this code:
int sdkVersion = 0;
IPackageManager packageManager = AppGlobals.getPackageManager();
try {
ApplicationInfo appInfo = packageManager.getApplicationInfo(yourAppName, 0);
if (applInfo != null) {
sdkVersion = applicationInfo.targetSdkVersion;
}
}

Unity app on Android is not shown as installed package

I have a project where use a custom Android launcher (android 4.2.2). The launcher shows games which are made in Adobe Air. Now we want to expand the list of games with Unity games.
To show the games we use the PackageManager and filter on name e.g.: air.Bimii. Namespace of both technologies are kept the same: air.BimiiMath, air.BimiiABC and so on.
The problem is that the games made in Unity are not listed when using:
private ArrayList<LocalAppDetail> initAppList(){
ArrayList<LocalAppDetail> res = new ArrayList<LocalAppDetail>();
PackageManager main_package_manager = main_activity.getPackageManager();
List<PackageInfo> packs = main_package_manager.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((p.versionName == null)) {
continue;
}
//Store Local Appdetail
LocalAppDetail newInfo = new LocalAppDetail();
newInfo.name = p.applicationInfo.loadLabel(main_package_manager).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(main_package_manager);
//Parse if the app meets requirements
if (newInfo.name.toLowerCase().contains(MiscData.apk_filter_text)) {
if(!newInfo.name.toLowerCase().contains("launcher")) {
if(!newInfo.name.toLowerCase().contains("rfid")){
res.add(newInfo);
}
}
}
}
//Store The Collection
return res;
}
but when i try using ADB: adb shell pm list packages -f air this is the result:
package:/data/app/air.BimiiFarm-1.apk=air.BimiiFarm
package:/data/app/air.BimiiFood-1.apk=air.BimiiFood
package:/data/app/air.nl.mediaheads.klassewinkel-1.apk=air.nl.mediaheads.klassewinkel
package:/system/app/Air.apk=com.adobe.air
package:/mnt/asec/nl.mediaheadsair.bimiiRekenen-1/pkg.apk=nl.mediaheadsair.bimiiRekenen
So the game is there (last in the list). The name is pkg.apk and the location is different. Do you guys have an idea about how to catch all the games in a list show we can launch them?
Help would be great! Thanks in advance
Update Sigh, it was an option in Unity Player settings. Install Location should be put on "Force Internal". What a world, what a world.

How can i prevent the user from running other applications programmatically in android?

I want to prevent the user from running some specific apps programmatically in Android? Kindly give some detailed answer if you know.
You can get a PID using a apps package name. with the pid you can close the app like android.os.Process.killProcess(pid);If you put this logic in a loop you can close specific apps whenever they are opened. Not the same as preventing them from opening but in many cases will yield the same result.
ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
int processid = 0;
for(int i = 0; i < pids.size(); i++)
{
ActivityManager.RunningAppProcessInfo info = pids.get(i);
if(info.processName.equalsIgnoreCase("here your package name")){
android.os.Process.killProcess(info.pid);
}
}

Hide App icon from its package Name

I am new to android. I want to hide other app icons from their package names. I get apps package name using this code
final PackageManager pm = getPackageManager();
List<ApplicationInfo> PackList = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (int i = 0; i < PackList.size(); i++) {
ApplicationInfo PackInfo = PackList.get(i);
// if (((PackInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) !=
// true) {
appsList.add(new AppPojo(PackInfo
.loadLabel(getPackageManager()).toString(),
PackInfo.packageName.toString(), "0"));
// }
}
Give package name of a particular app, is it possible to hide its icon??
Give package name of a particular app, is it possible to hide its icon?
No. You are welcome to write your own home screen which filters out apps, but you cannot force other home screens, or anything else, from showing whatever they want.

Android - Get List of Apps in Debug mode

I am trying to develop an android application where i have the following requirement. Is there any way through code, i can get the list of apps installed on devices in debug mode.
Thanks in advance.
EDIT - I tried the following code.
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (int i=0; i < packages.size(); i++)
{
if ((packages.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 1)
{
//This is for System applications
}
else
{
boolean isDebuggable = (0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) );
if((pm.getLaunchIntentForPackage(packages.get(i).packageName)!=null) && (isDebuggable = true) )
{
// Only For Apps with debug mode set true, this line should get executed
// But this does not happens
}
}
}
Here you go,
Intent main = new Intent(Intent.ACTION_MAIN, null);
main.addCategory(Intent.CATEGORY_LAUNCHER);
List pkgAppsList = context.getPackageManager().queryIntentActivities( main, 0);
This should give you enough information in order to kick off an application.
I tried various methods but as per my understanding, we cannot get the list of apps in debug mode seperately.
By using the flags, we can only get for the app which has this code and not other apps running on device.
Thanks anyways. If anybody has a different thought, please let me know.
From Justin's answer
Kotlin
val allIntent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
val allApps = packageManager.queryIntentActivities(allIntent, 0)
val debugApps = arrayListOf<ActivityInfo>()
allApps.forEach {
val appInfo = (packageManager.getApplicationInfo(
it.activityInfo.packageName,
0
))
if (0 != appInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) {
debugApps.add(it.activityInfo)
}
}
debugApps.forEach {
Log.d("debugApps", it.packageName)
}
It is possible to get all the apps that are in debug mode.
In my device, I get all the apps that I've installed using Android studio.

Categories

Resources