Update android application without starting an installation dialog - android

I'm currently looking for a way to update an android application without starting the installation intent.
Please note, the device is rooted
If it's possible I would just like to start the installation automated without notifying the user(automated APK installation).
If that is not an option I would like to unpack the APK, compile it myself and write it to the app's data directory.
Is there a way to achieve this?
Thanks in advance

you can try this
try {
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("pm install /mnt/sdcard/tr.apk");
} catch (IOException e) {
e.printStackTrace();
}
but this requires system permission and
android:name="android.permission.INSTALL_PACKAGES"

Related

How to set environment variable in Android Studio for the Dirs of my project?

I ported a C/C++ Project to Android.
Now, since it is working I want to build an APK for it.
All i need to do are 3 things.
copy the executables and the libraries on the device.
i already got this. The files are copied to:
getFilesDir()/bin and getFilesDir()/lib
I need to make the files executable. I did this with this command in the onCreate() Method:
try {Runtime.getRuntime().exec("chmod -R 777 " + getFilesDir());}
catch (IOException e)
{
e.printStackTrace();
}
It works but i guess there is a better way? Please help me out if there is a better way.
I need to set the environment variables to the dirs above:
getFilesDir()/bin and getFilesDir()/lib`
I can do it manually but i want to set them automatically when launching the app.
Whats the best way to do it?
I dont have a lot of experience with Android Studio so I really appreciate any input. Goal is, of course, that it works on any device without rooting the phone.
Thanks in advance.
i tried:
String[] cmd = {"/system/bin/sh", "-c", "export PATH=$PATH:./oorexx/bin"};
Runtime.getRuntime().exec(cmd);`
and i tried
System.setProperty("path.to.bin", getFilesDir().getAbsolutePath() + "/bin");
System.setProperty("path.to.lib", getFilesDir().getAbsolutePath() + "/lib");`
I also have this in the manifest but im on API LVL 33 so it will have no use:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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.

logcat not generating while device in sleep mode in android

when we run an application we can debug using logcat in eclipse/android studio but if we install apk in device we don't know what is happening for that we can generate log file programatically and save it in device.
This is the code i used for generating log :
String fileName = "logcat"+".doc";
File outputFile = new File(Environment.getExternalStorageDirectory(),"/"+fileName);
try {
#SuppressWarnings("unused")
Process process = Runtime.getRuntime().exec("logcat -f "+outputFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
This is all working fine but my question is :
when app is running in background(service is continuously running) if device goes to sleep after certain time log generating is stopped but app is running in the background.
I don't know how to fix the problem, could anyone help me?

Giving an Android app root permission

Using adb.exe that comes with the Android SDK, I can get root access to an Android device.
For testing purposes, I would like to give an Android app root permissions as well.
I know that app is running under a particular account called app_68.
Is there an adb shell command to add app_68 to the "root group"?
Thanks in advance for your comments/solutions.
You need the superuser (su) binary to run your app as root user.
For running as root implement this:
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("yourCommand\n");
os.writeBytes("exit\n");
os.flush();
os.close();
try { p.waitFor(); } catch (InterruptedException e) {}
If you get something like su: uid xxxx not allowed, then you need to update your su-binary using SuperSU.
Also see https://stackoverflow.com/a/26654728/4479004 if you want a fully detailed and working source.Just look at the code below:
Update: To get the result (the output to stdout), use:

Change file permission in application

I try to change file permission in application. Code is below:
Runtime.getRuntime().exec("chmod 777 /sdcard/test.txt");
This code NOT works in my application, but no error log.
I also checked the shell tools under /system/bin, find chmod is under /system/bin, but some other info shown that chmod > toolbox. I am not clear about this. My application has used android:sharedUserId="android.uid.system".
How to run this code or how to change permission of file? Thanks a lot.
Runtime rt = Runtime.getRuntime();
Process proc;
try {
proc = rt.exec(new String[] { "su", "-c", "chmod 777 " + Constants.filename });
proc.waitFor();
} catch (Exception e){ //DOSTUFFS }
This should do the trick
You've used the path /sdcard/ in your test -- is your SD Card formatted with a filesystem that supports standard Unix permissions? (FAT does not.)
You did not give an explicit path to chmod(1) in your string -- are you certain that chmod(1) is:
available on your device
available with your current PATH environment variable setting?
You can only change the permissions on files you own; are you certain that whatever your application's effective userid is owns the file on the SD card?
Lastly, Android may have additional security restrictions on changing file permissions. I don't know Android well, but perhaps changing file permission bits requires entries in the manifest declaring the operations, perhaps changing file permissions can only be done through provided APIs.

Categories

Resources