1
1
package org .qpython .qpy .main .activity ;
2
2
3
3
import android .Manifest ;
4
+ import android .app .ActivityManager ;
4
5
import android .app .AlertDialog ;
5
6
import android .app .LoaderManager ;
6
7
import android .app .PendingIntent ;
9
10
import android .content .IntentFilter ;
10
11
import android .content .Loader ;
11
12
import android .content .pm .PackageManager ;
13
+ import android .content .pm .ResolveInfo ;
12
14
import android .content .pm .ShortcutInfo ;
13
15
import android .content .pm .ShortcutManager ;
14
16
import android .graphics .drawable .Icon ;
15
17
import android .os .Build ;
16
18
import android .os .Bundle ;
19
+ import android .os .Handler ;
17
20
import android .support .annotation .NonNull ;
18
21
import android .support .annotation .Nullable ;
19
22
import android .support .v4 .app .ActivityCompat ;
38
41
import org .qpython .qpy .main .event .AppsLoader ;
39
42
import org .qpython .qpy .main .model .AppModel ;
40
43
import org .qpython .qpy .main .model .QPyScriptModel ;
44
+ import org .qpython .qpy .utils .ShortcutUtil ;
41
45
import org .qpython .qpysdk .QPyConstants ;
42
46
import org .qpython .qpysdk .utils .Utils ;
43
47
import org .qpython .qsl4a .qsl4a .LogUtil ;
@@ -145,6 +149,7 @@ public void createShortcut(QPyScriptModel item) {
145
149
// return;
146
150
// }
147
151
createShortcutOnThis ();
152
+ // test();
148
153
}
149
154
150
155
@ Override
@@ -191,6 +196,10 @@ public void exit() {
191
196
// }
192
197
// }
193
198
199
+ private void test (){
200
+ judgeShortcutNameV2 ("org.qpython.qpy" );
201
+ }
202
+
194
203
private void createShortcutOnThis (){
195
204
if (mBean == null ){
196
205
return ;
@@ -217,9 +226,17 @@ private void createShortcutOnThis(){
217
226
mShortcutManager .createShortcutResultIntent (pinShortcutInfo );
218
227
PendingIntent successCallback = PendingIntent .getBroadcast (this , 0 ,
219
228
pinnedShortcutCallbackIntent , 0 );
220
-
229
+ LogUtil . e ( "createShortcut: " + "111111111111" );
221
230
mShortcutManager .requestPinShortcut (pinShortcutInfo ,
222
231
successCallback .getIntentSender ());
232
+ LogUtil .e ("createShortcut: " + mBean .getLabel ());
233
+ new Handler ().postDelayed (new Runnable () {
234
+ @ Override
235
+ public void run () {
236
+ judgeShortcutNameV2 ("org.qpython.qpy" );
237
+ // judgeShortcutName(mBean.getLabel());
238
+ }
239
+ },200 );
223
240
}
224
241
} else {
225
242
//Adding shortcut for MainActivity
@@ -236,6 +253,24 @@ private void createShortcutOnThis(){
236
253
}
237
254
}
238
255
256
+ // private void judgeShortcutName(String name) {
257
+ // int shortcutNum = 0;
258
+ // for (String packageName : ShortcutUtil.getAllTheLauncher(getApplicationContext())) {
259
+ // LogUtil.e("packageName111111: " + packageName);
260
+ // if (name.equals(packageName)) {
261
+ // shortcutNum ++;
262
+ // }
263
+ // }
264
+ // LogUtil.e("packageName222222: " + shortcutNum);
265
+ // }
266
+
267
+ private void judgeShortcutNameV2 (String name ) {
268
+ if (!ShortcutUtil .getShortcutInfo (getApplicationContext ()).isEmpty ()){
269
+ return ;
270
+ }
271
+ Toast .makeText (this , getString (R .string .shortcut_create_fail ), Toast .LENGTH_SHORT ).show ();
272
+ }
273
+
239
274
240
275
private void getScriptList () {
241
276
try {
0 commit comments