App Shortcuts 에 해당하는 애플리케이션 일람표 작성

11684 단어 nougatAndroid

App Shortcuts란 무엇입니까?


Android 7.1부터 사용하면 홈 페이지에서 응용 프로그램의 특정 기능에 대한 단축키를 만들 수 있습니다.
https://developer.android.com/guide/topics/ui/shortcuts.html
이미 몇 개의 실시례가 있는데, 내가 알고 싶은 사람도 매우 많다.

이 보도는?


AppShortcuts의 설치 방법을 소개했기 때문에 AppShortcuts에 대응하는 응용 프로그램의 일람표와 구체적인 단축키를 소개하고자 합니다.

홈 어플리케이션 만들기


빠르지만 다른 앱의 단축키 정보를 얻으려면 홈페이지 앱으로 설정해야 한다.
https://developer.android.com/reference/android/content/pm/LauncherApps.html#hasShortcutHostPermission()
Only the default launcher can access the shortcut information.
Static Shortcuts라면 괜찮은데, 다이나믹 Shortcuts는 사용자의 앱 사용 현황 등을 반영해 프라이버시와 보안이라는 관점에서 이런 규격이 아닐까 싶다.
또 앱 스포츠에 대한 정보를 얻으려면 25minSdkVersion가 필요하다.
(평소 개발이 이렇게 비싸지 않아서 좀 흥분된다

가정 응용 프로그램으로 선언


먼저, Android Manifest.xml로 홈 프로그램 선언을 발표합니다.
AndroidManifest.xml
<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.HOME" />
    </intent-filter>
</activity>
추가android.intent.category.HOME하면 됩니다.
(없을 수 있음android.intent.category.LAUNCHER

홈 어플리케이션으로 설정


프로그램을 설치한 후 Settings Apps 오른쪽 상단의 톱니바퀴 아이콘 > Home app에서 이 프로그램을 홈 프로그램으로 설정합니다.
(홈 애플리케이션이 변경되었더라도 알림 표시줄에서 설정 화면이 열리므로 동일한 절차로 복원할 수 있습니다.)

단축키 정보 얻기


LauncherApps 가져오기

LauncherApps launcherApps = (LauncherApps) getSystemService(Context.LAUNCHER_APPS_SERVICE);
if (!launcherApps.hasShortcutHostPermission()) {
    // ホームアプリとして設定されていない
    return;
}
위에서 말한 바와 같이 홈페이지 프로그램을 설정하지 않으면 아무것도 할 수 없다.

응용 프로그램 가져오기

Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfoList) {
    if (resolveInfo.activityInfo == null) continue;
    ApplicationInfo applicationInfo = resolveInfo.activityInfo.applicationInfo;
    // ...
}
지금까지 나는 이전의 가정 응용 프로그램과 같다고 생각한다.

단축키 정보 얻기

int queryFlags = LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST;
List<ShortcutInfo> shortcutInfoList = launcherApps.getShortcuts(new LauncherApps.ShortcutQuery().setPackage(applicationInfo.packageName).setQueryFlags(queryFlags), UserHandle.getUserHandleForUid(applicationInfo.uid));
for (ShortcutInfo shortcutInfo : shortcutInfoList) {
    // ...
}
적절한 지정ShortcutQuery을 통해 모든 단축키를 얻을 수 있습니다.

아이콘 가져오기


getShortcutIconDrawable()를 사용하여 바로 가기 아이콘을 가져옵니다.
Drawable shortcutIcon = launcherApps.getShortcutIconDrawable(shortcutInfo, getResources().getDisplayMetrics().densityDpi);
두 번째 인자인 density는 0으로 설정하면 기본값이 될 수 있지만, 보통 붕괴되기 때문에 위와 같이 변경됩니다.
그리고 저는 getShortcutIconDrawable()getShortcutBadgedIconDrawable()의 차이를 잘 몰라요.
시뮬레이터로 해보면 이런 느낌이에요.

아이콘 크기가 명확하지 않음

단축키 시작


ShortcutInfo에는 getIntent()getIntents()가 있는데 이 start를 하면 될 것 같은데 아닌 것 같아
startActivity(shortcutInfo.getIntent()); // NG
startActivities(shortcutInfo.getIntents()); // NG
올바른 사용startShortcut().
launcherApps.startShortcut(shortcutInfo, null, null));
그런데 왜 설정된 Wifi 단축키만 ActivityNotFoundException일 때 시작할 수 없습니까

총결산


홈페이지 앱 차원에서 앱 스포츠를 조사해 봤다.
홈 앱을 만드는 사람은 드물지만 일반 앱으로 앱 Shortcuts에 대응하려는 사람들도 도울 수 있을 것 같다.
또한 이번 소스 코드는 아래 창고에 보관하세요.
https://github.com/oxsoft/AppShortcutsViewer
만약 무슨 잘못이나 의견이 있다면 저에게 메시지를 남겨주시면 감사하겠습니다

좋은 웹페이지 즐겨찾기