2016-11-01 9 views
0

Android 7.1.1의 새로운 바로 가기에 몇 가지 문제가 있습니다.Android 동적 단축 아이콘

두 번째 드로어 블에는 리소스 ID가 없습니다. 여기에 이미지와 코드 스 니펫이 있습니다. 내가 잘못 뭐하는 거지

enter image description here

private void createShortcuts(String deviceValue, String tablequery, int pos, String devImage, int index) { 
    ShortcutManager shortcutManager = mActivity.getSystemService(ShortcutManager.class); 

    if (index == 0) { 

     List<ShortcutInfo> scInfo = shortcutManager.getDynamicShortcuts(); 

     Bundle b = new Bundle(); 
     b.putInt("position", pos); 
     b.putString("table", tablequery); 
     b.putString("device", devImage); 

     String add = deviceValue + "_" + tablequery; 
     ShortcutInfo shortcut = new ShortcutInfo.Builder(mActivity, add) 
        .setShortLabel(deviceValue) // Shortcut Icon tab 
        .setLongLabel(deviceValue) // Displayed When Long Pressing On App Icon 
        .setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone)) 
        .setIntents(new Intent[]{ 
          new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mActivity, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), 
          new Intent(Intent.ACTION_DEFAULT, Uri.EMPTY, mActivity, Device_Detail_Activity.class).putExtras(b) 
        }) 
        .build(); 

     scInfo.add(shortcut); 

     shortcutManager.setDynamicShortcuts(scInfo); 
    } else if (index == 1) { 
     String remove = deviceValue + "_" + tablequery; 
     shortcutManager.removeDynamicShortcuts(Arrays.asList(remove)); 
    } 
} 

?

+1

만 확인을 위해 API를 사용하거나 더 자세한 내용은 ShortcutManager

를 세부 사항을 검색하고 에 다시 설정하지 스크린 샷. 코드는 항상 동일한 리소스를 사용하기 위해 유선 연결됩니다. 따라서 첫 번째 및 세 번째 앱 바로 가기에는 동일한 아이콘이 있어야하지만 두 번째 앱의 문제는 제외하고는 없습니다. 앱을 변경 한 상태에서 뛰어난 동적 앱 바로 가기가있는 경우 앱을 제거했다가 다시 설치하거나 코드가 모든 동적 앱 바로 가기를 다시 작성하도록 강요하고 도움이되는지 확인하십시오. – CommonsWare

+0

Nope 이미 2 역학 및 하나의 정적 바로 가기를 시도 –

답변

2

은 지금은 해결 방법을 발견하지만 난 업데이트가 다음 API에 고정 희망 여기에

은 잘린 정말 좋지 않아 보이는이지만 일 :

private void createShortcuts(String deviceValue, String tablequery, int pos, String devImage, int index) { 
    ShortcutManager shortcutManager = mActivity.getSystemService(ShortcutManager.class); 
    List<ShortcutInfo> scInfo = shortcutManager.getDynamicShortcuts(); 

    if (index == 0) { 

     Bundle b = new Bundle(); 
     b.putInt("position", pos); 
     b.putString("table", tablequery); 
     b.putString("device", devImage); 

     String add = deviceValue + "_" + tablequery; 

     if (scInfo.size() == 1) { 
      ShortcutInfo webShortcut = null, webShortcut1 = null; 

      webShortcut = new ShortcutInfo.Builder(mActivity, scInfo.get(0).getId()) 
        .setShortLabel(scInfo.get(0).getShortLabel()) 
        .setLongLabel(scInfo.get(0).getLongLabel()) 
        .setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone)) 
        .setIntent(scInfo.get(0).getIntent()) 
        .build(); 

      webShortcut1 = new ShortcutInfo.Builder(mActivity, add) 
        .setShortLabel(deviceValue) // Shortcut Icon tab 
        .setLongLabel(deviceValue) // Displayed When Long Pressing On App Icon 
        .setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone_2)) 
        .setIntents(new Intent[]{ 
          new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mActivity, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), 
          new Intent(Intent.ACTION_DEFAULT, Uri.EMPTY, mActivity, Device_Detail_Activity.class).putExtras(b) 
        }) 
        .build(); 

      shortcutManager.setDynamicShortcuts(Arrays.asList(webShortcut, webShortcut1)); 
     } else { 
      ShortcutInfo webShortcut = new ShortcutInfo.Builder(mActivity, add) 
        .setShortLabel(deviceValue) // Shortcut Icon tab 
        .setLongLabel(deviceValue) // Displayed When Long Pressing On App Icon 
        .setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone)) 
        .setIntents(new Intent[]{ 
          new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mActivity, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), 
          new Intent(Intent.ACTION_DEFAULT, Uri.EMPTY, mActivity, Device_Detail_Activity.class).putExtras(b) 
        }) 
        .build(); 

      shortcutManager.setDynamicShortcuts(Arrays.asList(webShortcut)); 
     } 
    } else if (index == 1) { 
     String remove = deviceValue + "_" + tablequery; 
     shortcutManager.removeDynamicShortcuts(Arrays.asList(remove)); 
    } 
} 
0

getDynamicShortcuts

API 레벨에 추가됨 List getDynamicShortcuts() 호출자 앱에서 모든 동적 바로 가기를 반환합니다.

이 API는 현재 의 바로 가기를 검사하기위한 것입니다. API를 통해 반환 된 ShortcutInfos를 다시 게시하면 (setDynamicShortcuts (List) 등)은 정보가 손실 될 수 있습니다. 을 아이콘으로 사용할 수 있습니다.

상기 단편은 getDynamicShortcuts developer.android.com의 기능을 설명한다.

그래서, 그것의 더 나은 당신은 세 가지 응용 프로그램 바로 가기를 가지고 https://developer.android.com/reference/android/content/pm/ShortcutManager.html#getDynamicShortcuts()