How to know an app's target sdk version - android

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;
}
}

Related

How to fix error get app version on Android 12?

I used this code and it can only get the version of other app above Android 11 and earlier. On Android 12 it doesn't work.
String uri = "com.uptodown.installer";
android.content.pm.PackageManager pm = getPackageManager(); try { android.content.pm.PackageInfo pInfo = pm.getPackageInfo(uri, android.content.pm.PackageManager.GET_ACTIVITIES); String version = pInfo.versionName;textview.setText(version); } catch (android.content.pm.PackageManager.NameNotFoundException e) { }
I tried to try but it only works on Android 11 or earlier.
From what I can tell, getPackageInfo() is deprecated as you've used it. From the ide:
Deprecated
Use getPackageInfo(String, PackageManager.PackageInfoFlags) instead.

Is it possible to get other application version?

Is it possible to findout version of another application?
I can find if it is installed
android.content.pm.PackageManager mPm = getPackageManager(); // 1
PackageInfo info = mPm.getPackageInfo(pName, 0); // 2,3
Boolean installed = info != null;
But i miss relative field in packageinfo or applicationinfo
versionCode and versionName are each fields in PackageInfo.

How to know a process of an app is 32-bit or 64-bit programmatically in Android lollipop?

As we all know from Android 5.0.64bit support is there. I have very simple question. Can we check programmatically in what mode any application is running i.e. 32bit or 64bit? For example: I have Facebook app running on my Nexus 9, so can I check using my android app if Facebook app's process is running in 32bit mode or 64bit mode?
In Nexus 5x
String arch = System.getProperty("os.arch");
returns
armv8l
it is not aarch64 and my code broke. However,
root#bullhead:/ # uname -m
aarch64
root#bullhead:/ # getprop ro.product.cpu.abilist
arm64-v8a,armeabi-v7a,armeabi
Wired. So I changed my code to
boolean is64 = (android.os.Build.VERSION.SDK_INT >= 21) && System.getProperty("ro.product.cpu.abilist").contains("64");
Updated on 2016-02-11
In Samsung Samsung Galaxy S5 Neo, Android 5.1.1
String arch = System.getProperty("os.arch");
returns aarch64 but it is not 64-bit device!!!
ro.product.cpu.abilist returns armeabi-v7a,armeabi
bool is64Bit = System.getProperty("ro.product.cpu.abilist").contains("64");
check is the only way to check.
Try System.getProperty("os.arch").
I haven't tried it on 64-bit android, but it must return something like 'aarch64' in case of 64 bit device.
http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)
public static boolean is64Bit() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Added in API level 23
return Process.is64Bit();
}
try {
Class cls = Class.forName("dalvik.system.VMRuntime");
Method getRuntimeMethod = cls.getDeclaredMethod("getRuntime");
Object vmRuntime = getRuntimeMethod.invoke(null);
Method is64BitMethod = cls.getDeclaredMethod("is64Bit");
Object is64Bit = is64BitMethod.invoke(vmRuntime);
if (is64Bit instanceof Boolean) {
return (boolean) is64Bit;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
IMO, you can use reflect to get the result of is64Bit. Android 6.0 began to provide this api to check your process.
android.os.Process.is64Bit()
In my experience (if your minSdkVersion is >= 21) the best way is to check the size of the array Build.SUPPORTED_64_BIT_ABIS.
(see https://developer.android.com/reference/android/os/Build#SUPPORTED_64_BIT_ABIS)
Something like this:
public static boolean is64Bit() {
return (Build.SUPPORTED_64_BIT_ABIS!= null && Build.SUPPORTED_64_BIT_ABIS.length >0);
}
What makes you think your device isn't 64-bit? The specs for the phone indicate it uses an Exynos 7 Octa 7580 which is arm8 and 64-bit.
boolean is64Arch = Build.CPU_ABI.equalsIgnoreCase("x86_64") || Build.CPU_ABI.equalsIgnoreCase("arm64-v8a");

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.

Android get install location with packagename

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.

Categories

Resources