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

AppLaunchChecker

 AppLaunchChecker

AppLaunchChecker

magiepooh

April 21, 2016
Tweet

More Decks by magiepooh

Other Decks in Technology

Transcript

  1. AppLaunchChecker
    @magiepooh

    View Slide

  2. About me
    @magiepooh
    @magie_pooh
    Takuma Fujita

    View Slide

  3. Company
    AbemaTV, Inc.
    (Cyber Agent, Inc.)

    View Slide

  4. AppLaunchChecker

    View Slide

  5. ?

    View Slide

  6. @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppLaunchChecker.hasStartedFromLauncher(this); // => false
    }

    View Slide

  7. @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppLaunchChecker.onActivityCreate(this);
    AppLaunchChecker.hasStartedFromLauncher(this); // => true
    }

    View Slide

  8. public static boolean hasStartedFromLauncher(Context context) {
    return context.getSharedPreferences(SHARED_PREFS_NAME, 0)
    .getBoolean(KEY_STARTED_FROM_LAUNCHER, false);
    }
    public static void onActivityCreate(Activity activity) {
    final SharedPreferences sp = activity.getSharedPreferences(SHARED_PREFS_NAME,
    0);
    if (sp.getBoolean(KEY_STARTED_FROM_LAUNCHER, false)) {
    return;
    }
    final Intent launchIntent = activity.getIntent();
    if (launchIntent == null) {
    return;
    }
    if (Intent.ACTION_MAIN.equals(launchIntent.getAction())
    && (launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
    || launchIntent.hasCategory(IntentCompat.CATEGORY_LEANBACK_LAUNCHER))) {
    SharedPreferencesCompat.EditorCompat.getInstance().apply(
    sp.edit().putBoolean(KEY_STARTED_FROM_LAUNCHER, true));
    }
    }
    AppLaunchChecker.java

    View Slide

  9. public static boolean hasStartedFromLauncher(Context context) {
    return context.getSharedPreferences(SHARED_PREFS_NAME, 0)
    .getBoolean(KEY_STARTED_FROM_LAUNCHER, false);
    }
    public static void onActivityCreate(Activity activity) {
    final SharedPreferences sp = activity.getSharedPreferences(SHARED_PREFS_NAME,
    0);
    if (sp.getBoolean(KEY_STARTED_FROM_LAUNCHER, false)) {
    return;
    }
    final Intent launchIntent = activity.getIntent();
    if (launchIntent == null) {
    return;
    }
    if (Intent.ACTION_MAIN.equals(launchIntent.getAction())
    && (launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
    || launchIntent.hasCategory(IntentCompat.CATEGORY_LEANBACK_LAUNCHER))) {
    SharedPreferencesCompat.EditorCompat.getInstance().apply(
    sp.edit().putBoolean(KEY_STARTED_FROM_LAUNCHER, true));
    }
    }
    AppLaunchChecker.java

    View Slide

  10. • SharedPreferencesʹΠϯςϯτͷΞΫγϣϯ
    ͱ͔ΧςΰϦͱ͔ݟͯϥϯνϟʔ͔Βىಈ͠
    ͔ͨΛॻ͖ࠐΜͰΔ͚ͩ
    • SharedPreferencesͷ஋ΛϦηοτ͢Δ΋ͷ͸
    ༻ҙ͞Ε͍ͯͳ͍

    View Slide

  11. • Πϯετʔϧ > Launcherىಈ // true
    • Πϯετʔϧ > DeepLink // false
    • Πϯετʔϧ > Launcherىಈ > DeepLink // true
    ݁࿦ɿ

    View Slide

  12. ݁࿦ɿ
    • Πϯετʔϧ > Launcherىಈ // true
    • Πϯετʔϧ > DeepLink // false
    • Πϯετʔϧ > Launcherىಈ > DeepLink // true
    աڈʹϢʔβ͕Ұ౓Ͱ΋Launcher͔Βىಈ͔ͨ͠Ͳ͏͔

    View Slide

  13. ݁࿦ɿ
    Ͳ͜Ͱ࢖͑Δ͔શ͘
    Θ͔ΒΜɻ

    View Slide