简体   繁体   中英

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:

  1. I confirmed through Package names application the Termux package name is "com.termux" and its activity class name is also "com.termux.app.termuxActivity"
  2. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM