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.
Related
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).
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.
I'm trying to call a Python script from Tasker using SL4A on my Android (4.4) phone. I'm using the Run SL4A Script task for this. As a test exercise, I want to pass a string from Tasker and use it (for now just print it) in Python.
According to the link below, this can be done by setting the 'Pass Variables' field in the Run SL4A Script task and picking it up with the Android getIntent method in Python. (https://groups.google.com/forum/#!topic/taskerpro/mQIv1PBu3PU)
Here's my Python script:
import android
droid = android.Android
params = droid.getIntent().result[u'extras']
print params[0]
However when I run the task I get the following error in SL4A:
AttributeError: type object 'Android' has no attribute 'getIntent'
Anyone know why I get this and how to solve it? I can't find any reference to it elsewhere.
I don't know about calling from Tasker, but the Python script runs fine stand-alone on SL4A Release 6 and Python interpreter Py4A Release 5.
If you don't have everything installed yet, here are some some slides I recently presented at an Android developers meetup.
I think you are simply missing the parentheses in your Android imports.
I use:
import android
droid = android.Android()
you can also try:
from android import Android
droid = Android()
this makes Android an object in python properly and you should be able to call the getIntent and other functions properly.
and to save time testing if the android module is functional I also add:
def toast(x):
x = str(x)
droid.makeToast(x)
then you can pass variables to the newly defined toast(x) function.
Hope I've helped!
Python for Android supports lxml. But how can I import it? On the google site, there is a modul in a recipe.sh file. But i can not run it through the shell there. I get some errors:
app_122#android:/mnt/sdcard $ sh recipe.sh
: nor found]
recipe.sh[6]: get_directory: not found
: not found]
recipe.sh[9]: syntax error: '{^M' expected
1 app_122#android:/mnt/sdcard
Can't I just get some .py file and simply import it into my programms?
I used this code:
https://github.com/kivy/python-for-android/blob/master/recipes/lxml/recipe.sh
Can someone help?
I think you might be confusing py4a which is a sister project of SL4A (Scripting Layer For Android) with https://github.com/kivy/python-for-android which is a sister project of Kivy
Both are different projects with different targets. You should be clear about which project you want to use. Read the docs to get more familiar.
kivy/python-for-android docs
Discussion groups
py4a docs
Discussion groups
I added an app in packages/apps in android build system and my app use some internal api.But when I use mm or mmm to make the app,android build system shows error:package com.android.internal.policy.impl does not exist etc.But I saw Phone app also uses internal api like com.android.internal.xx and it builds with no errors.I want to know whether there are something i missed and how can i use internal api in internal apps.BTW,my app can import com.android.internal.telephony,but cannot import com.android.internal.policy.impl.Thanks.
Finally I add LOCAL_JAVA_LIBRARIES := android.policy framework in Android.mk, and it works.