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

Androidの歩数取得とバックグラウンド制限

 Androidの歩数取得とバックグラウンド制限

Androidで歩数アプリを使う時に気をつけるべき事

1b47f58a15c90f3b212dbfc476595632?s=128

izmeal2000

August 23, 2018
Tweet

Transcript

  1. Androidʹ͓͚Δา਺औಘͱ όοΫάϥ΢ϯυ੍ݶ

  2. Kensuke Izumi AndroidEngineer@FiNC Kotlin/Ruby/Javascript

  3. FiNCʹ͍ͭͯ

  4. Lifelog ɾา਺΍ਭ຾ɺମॏ͕ه࿥Մೳ ɾา͍ͨา਺ʹԠͯ͡ϙΠϯτ͕෇༩͞ ΕͨΓɺϥϯΩϯά͕։࠵͞ΕͨΓ͢Δ

  5. ɾา਺औಘͷ࢓૊Έ
 ɾOS͔Β͔͔Δ੍ݶ ɾ੍ݶʹର͢Δ֨ಆ

  6. า਺औಘͷ࢓૊Έ

  7. า਺Λऔಘ͢Δखஈ ɾGoogleFit ɾηϯαʔ͔Βऔಘ

  8. Google Fit API ɾGooglePlayServicesͱͯ͠ఏڙ ɾSensors API, Recording API, 
 ɹHistory

    API, etc…
  9. ηϯαʔ͔Βऔಘ 1. AndroidFrameworkͷSensorListenerΛར༻ ɹTYPE_STEP_COUNTER
 ɹɹ=> ҰఆͷظؒͷूܭΛऔΓ͍ͨ࣌ ɹTYPE_STEP_DETECTOR ɹɹ=> ଌҐͳͲҰา͝ͱͷσʔλ͕ཉ͍࣌͠ 2.

    Ճ଎౓ηϯαʔͱ஍࣓ؾηϯαʔͰؤுΔ
  10. Googleʹ৐͔ͬΕ͹Α͘ͳ ͍ʁ

  11. None
  12. Ϗδωεཁ݅ʹຬͨͳ͍… GoogleFitΞϓϦ͔ΒϢʔβ͕า਺ΛฤूՄೳ ↓ า਺ʹԠͨ͡ϙΠϯτ෇༩͕೉͍͠ (ෆਖ਼ϙΠϯτ໰୊)

  13. Ϗδωεཁ݅ʹຬͨͳ͍… FitAPI͔ΒऔಘͰ͖Δา਺ͱ GoogleFitΞϓϦͰදࣔ͞ΕΔา਺͕ҟͳΔ ↓ ͍΍ɺࠔΔɻ

  14. Ϗδωεཁ݅ʹຬͨͳ͍… FitAPI͔ΒऔಘͰ͖Δา਺ͱ GoogleFitΞϓϦͰදࣔ͞ΕΔา਺͕ҟͳΔ > Sometimes the step calculation code for

    the Google Fit app is updated with bug fixes before we are able to release the fixes to developers (which requires a Google Play Services release). We are also working on making it possible for developers to access fixes at the same time. “͢·Μɺզʑ͸࠷৽ͷϩδοΫͰूܭ͢Δ͚ͲAPI΁ͷ൓ө͸஗ΕΔΘɻ”
  15. Α͠ɻา਺ηϯαʔͩɻ

  16. OS͔Β͔͔Δ੍ݶ

  17. OS͔Β͔͔ΔόοΫάϥ΢ϯ υ੍ݶ ɾAndroid 6.0=> DozeϞʔυ ɾAndroid 7.0 => DozeϞʔυڧԽ ɾAndroid

    8.0 => broadcast΁ͷ੍ݶ ɾAndroid 9.0 => backgroundͰͷηϯαʔ΁ͷΞΫηεېࢭ
  18. ੍ݶʹର͢Δ֨ಆ

  19. DozeϞʔυ লిྗϞʔυ: ը໘Λ͠͹Β͘Φϑʹͨ͠Γ୺຤Λిݯ͔Βൈ͍ͨΓ͢ΔͱɺDoze ʹΑ Γɺ௨ৗͷ CPU ͓ΑͼωοτϫʔΫ੍ݶͷҰ෦͕ΞϓϦʹద༻͞Ε·͢ɻ ରࡦɿαʔϏεऴྃ࣌ʹ"MBSN.BOBHFSͰ࠶ىಈͤ͞Δ ˞ݱࡏόοΫάϥ΢ϯυͷTDIFEVMJOHʹ͸+PC4DIFEVMFS8PSL.BOBHFS౳͕ਪ঑ 

    @Override
 public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); // restart service ((AlarmManager) getSystemService(Context.ALARM_SERVICE)) .setExactAndAllowWhileIdle(AlarmManager.RTC, System.currentTimeMillis() + 500, PendingIntent .getService(this, 3, createIntent(this), 0)); }
  20. DozeϞʔυ লిྗϞʔυ: ը໘Λ͠͹Β͘Φϑʹͨ͠Γ୺຤Λిݯ͔Βൈ͍ͨΓ͢ΔͱɺDoze ʹΑ Γɺ௨ৗͷ CPU ͓ΑͼωοτϫʔΫ੍ݶͷҰ෦͕ΞϓϦʹద༻͞Ε·͢ɻ ରࡦɿαʔϏεऴྃ࣌ʹ"MBSN.BOBHFSͰ࠶ىಈͤ͞Δ ˞ݱࡏόοΫάϥ΢ϯυͷTDIFEVMJOHʹ͸+PC4DIFEVMFS8PSL.BOBHFS౳͕ਪ঑ 

    @Override
 public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); // restart service ((AlarmManager) getSystemService(Context.ALARM_SERVICE)) .setExactAndAllowWhileIdle(AlarmManager.RTC, System.currentTimeMillis() + 500, PendingIntent .getService(this, 3, createIntent(this), 0)); }
  21. background͔Βͷηϯαʔ ΞΫηεېࢭ َɺGoogleFit΁ͷू໿.. ରࡦɿ'PSFHSPVOE4FSWJDFͰىಈ͢Δ class ForegroundService: Service() { override fun

    onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val notificationBuilder = NotificationCompat.Builder(this) .setAutoCancel(false) .setOngoing(true) .build() startForeground(100, notificationBuilder) return START_STICKY } override fun onBind(p0: Intent?): IBinder { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } }
  22. ·ͱΊ ɾFitAPIͰཁ݅Λຬͨͤ͹ͦΕ͕Ұ൪() ɹɾhttps://japan.googleblog.com/2018/08/google-fit.html ɾFitAPIͰ࣮ݱͰ͖ͳ͚Ε͹ɺForegroundService ͰSensorΛobserve͠·͠ΐ͏