Upgrade to Pro — share decks privately, control downloads, hide ads and more …

App Shortcuts

takuaraki
November 28, 2016

App Shortcuts

関モバ #20 の発表資料です。

takuaraki

November 28, 2016
Tweet

More Decks by takuaraki

Other Decks in Programming

Transcript

  1. 4UBUJD4IPSUDVU <activity
 android:name=".MainActivity"
 android:label="@string/app_name"
 android:theme="@style/AppTheme.NoActionBar">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />
 


    <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 <meta-data
 android:name="android.app.shortcuts"
 android:resource="@xml/shortcuts" />
 </activity> "OESPJE.BOJGFTUYNM
  2. 4UBUJD4IPSUDVU <?xml version="1.0" encoding="utf-8"?> <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
 <shortcut
 android:shortcutId="createEmail"
 android:enabled="true"
 android:icon="@mipmap/ic_create_email"


    android:shortcutShortLabel="@string/email_shortcut_short_label"
 android:shortcutLongLabel="@string/email_shortcut_long_label"
 android:shortcutDisabledMessage="@string/disabled_message">
 <intent
 android:action="android.intent.action.VIEW"
 android:targetPackage="com.example.arakitaku"
 android:targetClass="com.example.arakitaku.EmailActivity" />
 </shortcut>
 </shortcuts> YNMTIPSUDVUTYNM
  3. %ZOBNJD4IPSUDVU ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
 ShortcutInfo ara_tack = new ShortcutInfo.Builder(this,

    "ara_tack")
 .setShortLabel("ara_tack")
 .setLongLabel("mail to ara_tack")
 .setIcon(Icon.createWithResource(this, R.mipmap.ic_create_email_a))
 .setIntent(
 EmailActivity.createIntent(this, "ara_tack")
 .setAction(Intent.ACTION_VIEW)
 )
 .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(ara_tack)); .BJO"DUJWJUZKBWB
  4. %ZOBNJD4IPSUDVU ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); ShortcutInfo ara_tack = new ShortcutInfo.Builder(this,

    "ara_tack")
 .setShortLabel("ara_tack")
 .setLongLabel("mail to ara_tack")
 .setIcon(Icon.createWithResource(this, R.mipmap.ic_create_email_a))
 .setIntent(
 EmailActivity.createIntent(this, "ara_tack")
 .setAction(Intent.ACTION_VIEW)
 )
 .build(); ShortcutInfo hashido = new ShortcutInfo.Builder(this, “hashido”)…… ShortcutInfo n_morioka = new ShortcutInfo.Builder(this, “n_morioka”)…… shortcutManager.setDynamicShortcuts(Arrays.asList(
 ara_tack, 
 hashido, 
 n_morioka
 )); .BJO"DUJWJUZKBWB
  5. %ZOBNJD4IPSUDVU ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); ShortcutInfo kan = new ShortcutInfo.Builder(this,

    “kan”)…… ShortcutInfo sai = new ShortcutInfo.Builder(this, “sai”)…… ShortcutInfo mobairu = new ShortcutInfo.Builder(this, “mobairu”)…… ShortcutInfo apuri = new ShortcutInfo.Builder(this, “apuri”)…… ShortcutInfo kenkyu = new ShortcutInfo.Builder(this, “kenkyu”)…… ShortcutInfo kai = new ShortcutInfo.Builder(this, “kai”)…… // IllegalArgumentException will be thrown. // Max shortcut num is 5. (include static shortcuts)
 shortcutManager.setDynamicShortcuts(Arrays.asList(
 kan,
 sai,
 mobairu,
 apuri,
 kenkyu,
 kai
 )); .BJO"DUJWJUZKBWB
  6. %ZOBNJD4IPSUDVU // List<ShortcutInfo> shortcutInfos;
 // List<String> shortcutIds;
 // set
 shortcutManager.setDynamicShortcuts(shortcutInfos);

    
 // add
 shortcutManager.addDynamicShortcuts(shortcutInfos);
 
 // update
 shortcutManager.updateShortcuts(shortcutInfos);
 
 // remove specific
 shortcutManager.removeDynamicShortcuts(shortcutIds);
 
 // remove all
 shortcutManager.removeAllDynamicShortcuts();
 
 // disable
 shortcutManager.disableShortcuts(shortcutIds); .BJO"DUJWJUZKBWB
  7. %ZOBNJD4IPSUDVU ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
 ShortcutInfo n_morioka = new ShortcutInfo.Builder(this,

    "n_morioka")
 .setShortLabel("n_morioka")
 .setLongLabel("mail to n_morioka")
 .setIcon(Icon.createWithResource(this, R.mipmap.ic_create_email_n))
 // Multiple Intent can be set
 .setIntents(new Intent[]{
 MainActivity.createIntent(this)
 .setAction(Intent.ACTION_VIEW),
 EmailActivity.createIntent(this, "n_morioka")
 .setAction(Intent.ACTION_VIEW)
 })
 .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(n_morioka)); .BJO"DUJWJUZKBWB