@@ -110,7 +110,7 @@ public static void installApp(final Activity activity,
110
110
* @return {@code true}: success<br>{@code false}: fail
111
111
*/
112
112
public static boolean installAppSilent (final String filePath ) {
113
- return installAppSilent (getFileByPath (filePath ));
113
+ return installAppSilent (getFileByPath (filePath ), null );
114
114
}
115
115
116
116
/**
@@ -122,19 +122,47 @@ public static boolean installAppSilent(final String filePath) {
122
122
* @return {@code true}: success<br>{@code false}: fail
123
123
*/
124
124
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 ) {
125
152
if (!isFileExists (file )) return false ;
126
153
boolean isRoot = isDeviceRooted ();
127
154
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 ;
129
158
ShellUtils .CommandResult commandResult = ShellUtils .execCmd (command , isRoot );
130
159
if (commandResult .successMsg != null
131
160
&& commandResult .successMsg .toLowerCase ().contains ("success" )) {
132
161
return true ;
133
162
} 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 ;
138
166
}
139
167
}
140
168
@@ -160,7 +188,10 @@ public static void uninstallApp(final Activity activity,
160
188
final String packageName ,
161
189
final int requestCode ) {
162
190
if (isSpace (packageName )) return ;
163
- activity .startActivityForResult (IntentUtils .getUninstallAppIntent (packageName ), requestCode );
191
+ activity .startActivityForResult (
192
+ IntentUtils .getUninstallAppIntent (packageName ),
193
+ requestCode
194
+ );
164
195
}
165
196
166
197
/**
@@ -187,20 +218,17 @@ public static boolean uninstallAppSilent(final String packageName) {
187
218
public static boolean uninstallAppSilent (final String packageName , final boolean isKeepData ) {
188
219
if (isSpace (packageName )) return false ;
189
220
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 "
191
222
+ (isKeepData ? "-k " : "" )
192
223
+ packageName ;
193
224
ShellUtils .CommandResult commandResult = ShellUtils .execCmd (command , isRoot , true );
194
225
if (commandResult .successMsg != null
195
226
&& commandResult .successMsg .toLowerCase ().contains ("success" )) {
196
227
return true ;
197
228
} 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 ;
204
232
}
205
233
}
206
234
0 commit comments