11package org .qpython .qpy .main .activity ;
22
33import android .Manifest ;
4+ import android .app .ActivityManager ;
45import android .app .AlertDialog ;
56import android .app .LoaderManager ;
67import android .app .PendingIntent ;
910import android .content .IntentFilter ;
1011import android .content .Loader ;
1112import android .content .pm .PackageManager ;
13+ import android .content .pm .ResolveInfo ;
1214import android .content .pm .ShortcutInfo ;
1315import android .content .pm .ShortcutManager ;
1416import android .graphics .drawable .Icon ;
1517import android .os .Build ;
1618import android .os .Bundle ;
19+ import android .os .Handler ;
1720import android .support .annotation .NonNull ;
1821import android .support .annotation .Nullable ;
1922import android .support .v4 .app .ActivityCompat ;
3841import org .qpython .qpy .main .event .AppsLoader ;
3942import org .qpython .qpy .main .model .AppModel ;
4043import org .qpython .qpy .main .model .QPyScriptModel ;
44+ import org .qpython .qpy .utils .ShortcutUtil ;
4145import org .qpython .qpysdk .QPyConstants ;
4246import org .qpython .qpysdk .utils .Utils ;
4347import org .qpython .qsl4a .qsl4a .LogUtil ;
@@ -145,6 +149,7 @@ public void createShortcut(QPyScriptModel item) {
145149// return;
146150// }
147151 createShortcutOnThis ();
152+ // test();
148153 }
149154
150155 @ Override
@@ -191,6 +196,10 @@ public void exit() {
191196// }
192197// }
193198
199+ private void test (){
200+ judgeShortcutNameV2 ("org.qpython.qpy" );
201+ }
202+
194203 private void createShortcutOnThis (){
195204 if (mBean == null ){
196205 return ;
@@ -217,9 +226,17 @@ private void createShortcutOnThis(){
217226 mShortcutManager .createShortcutResultIntent (pinShortcutInfo );
218227 PendingIntent successCallback = PendingIntent .getBroadcast (this , 0 ,
219228 pinnedShortcutCallbackIntent , 0 );
220-
229+ LogUtil . e ( "createShortcut: " + "111111111111" );
221230 mShortcutManager .requestPinShortcut (pinShortcutInfo ,
222231 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 );
223240 }
224241 } else {
225242 //Adding shortcut for MainActivity
@@ -236,6 +253,24 @@ private void createShortcutOnThis(){
236253 }
237254 }
238255
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+
239274
240275 private void getScriptList () {
241276 try {
0 commit comments