Android PackageManager: check if a library APK has been installed - android

The PackageManager.getPackageInfo(packageName, flags) method can be used to check whether a specific package has been installed. It either returns the PackageInfo or throws PackageManager.NameNotFoundException.
How to check if a library APK is installed? An example of the library APK is Trichrome Library: https://www.apkmirror.com/apk/google-inc/trichrome-library/trichrome-library-98-0-4758-101-release/trichrome-library-98-0-4758-101-3-android-apk-download/download/
After installation of this APK, calling PackageManager.getPackageInfo('com.google.android.trichromelibrary', 0) throws PackageManager.NameNotFoundException.
Looking via ADB, I see that once installed, it's not visible under pm list packages but it's visible under pm list libraries with the name "library:com.google.android.trichromelibrary".
Is there any way to determine programmatically whether the library has been installed?

As you can see in the source code of pm in this link, pm list libraries command uses PackageManager.getSystemSharedLibraryNames() which is documented here.
If this method is not working, there are also other methods in PackageManager to get info about shared libraries. As mentioned by #vmayorow, One of these methods is PackageManager.getSharedLibraries(0).

Related

How can you launch Termux through another android app?

I am working on automating the process of launching the dependencies for an android project.
One of the dependencies is launching Termux (Installed through F-Droid not Play store as recommended).
I am trying to launch the installed Termux application through another application and add some commands to its ~./bashrc file for the sake of automation.
I know that an installed app can be launched trough another android app (more details are here).
I wonder to know if this is possible for Termux as well? I wonder to know if we can use intent concept to launch Termux from an android app as well? If yes what is the Termux package name?
I tried using "com.termux" as its packagename in my sample code, but it did not work.
In other words, the following line returns null:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.termux");
Updated:
I can open another installed app (the app that I developed and installed its apk file on tablet) using Intent concept as shown above (by replacing the appropriate package name instead of termux package name).
Note:
I have installed the Termux through F-Drioid not google play store.
New observation:
I confirmed through Package names application the Termux package name is "com.termux" and its activity class name is also "com.termux.app.termuxActivity"
But seems like the "com.termux" is not accessible through package manager. When i try to pass "com.termux" to the following function it returns false.
Any idea or suggestion?
public boolean isPackageExisted(String targetPackage){
enter code here
PackageManager pm=getPackageManager();
try {
PackageInfo info=pm.getPackageInfo(targetPackage,PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return true;
}
Add com.termux to queries element or declare QUERY_ALL_PACKAGES permission in AndroidManifest.xml if targetSdkVersion is 30+. Check Package Visibility or this article for more info. Otherwise, you will will get PackageSetting{...... com.termux/......} BLOCKED errors in logcat.
<manifest
<queries>
<package android:name="com.termux" />
</queries>
</manifest>
Moreover, you can run commands in termux via RUN_COMMAND intent. The termux-shared lib is published on jitpack since v0.116, check Termux Libraries for import instructions.
Moreover, activity name is com.termux.app.TermuxActivity.

App Refuses to Install - INSTALL_FAILED_MISSING_SHARED_LIBRARY

I am new to programming generally please I need some help!
My app was installing successfully after every update until i decided to add the 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha' library to the app because i need the user to be able to view some data in form of statistical charts.
The library was synced successfully and have used packages and classes therein successful. But when i try to install the app in my android device it returned this error:
Installation failed with message Failed to commit install session 590492354 with command cmd package
install-commit 590492354. Error: INSTALL_FAILED_MISSING_SHARED_LIBRARY: Package couldn't be installed in
/data/app/com.cenitscitech.www.etimebook-jOP-jv2YuNu7_8qnkfqp-A==: Package com.cenitscitech.www.etimebook requires unavailable shared library com.google.android.things; failing!.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing." I have pasted a screenshot here:
I uninstalled the existing version of the apk, cleared some memory space but keep on getting the same message! What should I do next please?
You are most likely installing on a device that is not an Android Things device. I suspect the library you added either has some transitive dependency on com.google.android.things, or something else changed in your project.
To get around this, you must do the following 2 things:
1. Mark that Android Things is not required on the device in your AndroidManifest.xml file:
<uses-library
android:name="com.google.android.things"
android:required="false"
tools:replace="android:required" />
(tools:replace is not strictly required, but it just there in case something in the manifest merge process overrides your setting.)
2. In your app's code, before making any calls to the Things APIs, make sure that they are available on the current device. This can be tested with the following code snippet:
public boolean isThingsDevice(Context context) {
final PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_EMBEDDED);
}
Only doing 1 should fix the install problem, but your app will crash if you make any Things API calls on a device that isn't an Android Things device.
Had a look in the com.github.PhilJay:MPAndroidChart:v3.1.0-alpha repository and did not find any reference to com.google.android.things inside the source code.
You need to remove the below entry in case it's found in the AndroidManifest.xml of your app for it to work on your device again:
<uses-library android:name="com.google.android.things" />

Verify android library's (aar) signature on runtime

I am developing an Android library which I am going to distribute to my business partners. I have signed it with my key store and I want to verify the signature on runtime to see if my library is recompiled using a different signature. But the normal way to verify the signature
PackageManager pm = ctx.getPackageManager();
(PackageInfo packageInfo = pm.getPackageInfo(ctx.getPackageName(),
PackageManager.GET_SIGNATURES);)
in case of APK is not working as it returns only the application's signature and not the signature I signed my library with. Is there a way to do this?

The import com.android.packageinstaller cannot be resolved

How can I use packageinstaller to install apps programmatically in Android? If I try to use
import com.android.packageinstaller;
I get "The import com.android.packageinstaller cannot be resolved" error.
When I try directly use PackageManager I cannot use installPackage function:
The method installPackage() is undefined for the type PackageManager
How could I install 1.app obtained my web server by the other? Is it possible at all?
This is because it is not part of Android SDK. It is internal package. installPackage() also not open either.
You can use this packages, methods if you are OEM & compiling against android source code.

Android - how to get installed package in JNI C code

I have a requirement to implement an equivalent of following java code in JNI C on android:
PackageManager pm = context.getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(0);
for(PackageInfo packageInfo : packages) {
...
}
My question is how to get installed packages in JNI C. Is it even possible?
Thanks
Your best bet is to call PacakgeManager via JNI. There is no "C interface", you have to go through the system service. Installing a package does quite a few things, so just copying the APK to the right place is not enough.

Categories

Resources