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

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

izmeal2000
August 23, 2018

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

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

izmeal2000

August 23, 2018
Tweet

More Decks by izmeal2000

Other Decks in Technology

Transcript

  1. Ϗδωεཁ݅ʹຬͨͳ͍… 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΁ͷ൓ө͸஗ΕΔΘɻ”
  2. OS͔Β͔͔ΔόοΫάϥ΢ϯ υ੍ݶ ɾAndroid 6.0=> DozeϞʔυ ɾAndroid 7.0 => DozeϞʔυڧԽ ɾAndroid

    8.0 => broadcast΁ͷ੍ݶ ɾAndroid 9.0 => backgroundͰͷηϯαʔ΁ͷΞΫηεېࢭ
  3. 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)); }
  4. 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)); }
  5. 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. } }