@@ -110,7 +110,7 @@ public static void installApp(final Activity activity,
110110 * @return {@code true}: success<br>{@code false}: fail
111111 */
112112 public static boolean installAppSilent (final String filePath ) {
113- return installAppSilent (getFileByPath (filePath ));
113+ return installAppSilent (getFileByPath (filePath ), null );
114114 }
115115
116116 /**
@@ -122,19 +122,47 @@ public static boolean installAppSilent(final String filePath) {
122122 * @return {@code true}: success<br>{@code false}: fail
123123 */
124124 public static boolean installAppSilent (final File file ) {
125+ return installAppSilent (file , null );
126+ }
127+
128+
129+ /**
130+ * Install the app silently.
131+ * <p>Without root permission must hold
132+ * {@code <uses-permission android:name="android.permission.INSTALL_PACKAGES" />}</p>
133+ *
134+ * @param filePath The path of file.
135+ * @param params The params of installation.
136+ * @return {@code true}: success<br>{@code false}: fail
137+ */
138+ public static boolean installAppSilent (final String filePath , final String params ) {
139+ return installAppSilent (getFileByPath (filePath ), null );
140+ }
141+
142+ /**
143+ * Install the app silently.
144+ * <p>Without root permission must hold
145+ * {@code <uses-permission android:name="android.permission.INSTALL_PACKAGES" />}</p>
146+ *
147+ * @param file The file.
148+ * @param params The params of installation.
149+ * @return {@code true}: success<br>{@code false}: fail
150+ */
151+ public static boolean installAppSilent (final File file , final String params ) {
125152 if (!isFileExists (file )) return false ;
126153 boolean isRoot = isDeviceRooted ();
127154 String filePath = file .getAbsolutePath ();
128- String command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install " + filePath ;
155+ String command = "LD_LIBRARY_PATH=/vendor/lib*:/system/lib* pm install " +
156+ (params == null ? "" : params + " " )
157+ + filePath ;
129158 ShellUtils .CommandResult commandResult = ShellUtils .execCmd (command , isRoot );
130159 if (commandResult .successMsg != null
131160 && commandResult .successMsg .toLowerCase ().contains ("success" )) {
132161 return true ;
133162 } else {
134- command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib64 pm install " + filePath ;
135- commandResult = ShellUtils .execCmd (command , isRoot , true );
136- return commandResult .successMsg != null
137- && commandResult .successMsg .toLowerCase ().contains ("success" );
163+ Log .e ("AppUtils" , "installAppSilent successMsg: " + commandResult .successMsg +
164+ ", errorMsg: " + commandResult .errorMsg );
165+ return false ;
138166 }
139167 }
140168
@@ -160,7 +188,10 @@ public static void uninstallApp(final Activity activity,
160188 final String packageName ,
161189 final int requestCode ) {
162190 if (isSpace (packageName )) return ;
163- activity .startActivityForResult (IntentUtils .getUninstallAppIntent (packageName ), requestCode );
191+ activity .startActivityForResult (
192+ IntentUtils .getUninstallAppIntent (packageName ),
193+ requestCode
194+ );
164195 }
165196
166197 /**
@@ -187,20 +218,17 @@ public static boolean uninstallAppSilent(final String packageName) {
187218 public static boolean uninstallAppSilent (final String packageName , final boolean isKeepData ) {
188219 if (isSpace (packageName )) return false ;
189220 boolean isRoot = isDeviceRooted ();
190- String command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm uninstall "
221+ String command = "LD_LIBRARY_PATH=/vendor/lib* :/system/lib* pm uninstall "
191222 + (isKeepData ? "-k " : "" )
192223 + packageName ;
193224 ShellUtils .CommandResult commandResult = ShellUtils .execCmd (command , isRoot , true );
194225 if (commandResult .successMsg != null
195226 && commandResult .successMsg .toLowerCase ().contains ("success" )) {
196227 return true ;
197228 } else {
198- command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib64 pm uninstall "
199- + (isKeepData ? "-k " : "" )
200- + packageName ;
201- commandResult = ShellUtils .execCmd (command , isRoot , true );
202- return commandResult .successMsg != null
203- && commandResult .successMsg .toLowerCase ().contains ("success" );
229+ Log .e ("AppUtils" , "uninstallAppSilent successMsg: " + commandResult .successMsg +
230+ ", errorMsg: " + commandResult .errorMsg );
231+ return false ;
204232 }
205233 }
206234
0 commit comments