Android
8
Вклад в тег
implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-auth:16.0.2"
implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
implementation "com.android.support:appcompat-v7:${supportLibVer}"
implementation "com.android.support:support-v13:${supportLibVer}"
implementation "com.android.support:recyclerview-v7:${supportLibVer}"
implementation "com.android.support:design:${supportLibVer}"
implementation 'com.android.support:multidex:1.0.3'
implementation "com.google.android.gms:play-services-maps:${gmsVersion}"
implementation "com.google.android.gms:play-services-location:${gmsVersion}"
implementation "android.arch.lifecycle:extensions:${aacVer2}"
kapt "android.arch.lifecycle:compiler:${aacVer}"
implementation "android.arch.persistence.room:runtime:${aacVer2}"
kapt "android.arch.persistence.room:compiler:${aacVer}"
implementation "com.squareup.retrofit2:retrofit:${retrofitVer}"
implementation "com.squareup.retrofit2:converter-gson:${retrofitVer}"
implementation "com.squareup.okhttp3:okhttp:${okHttpVer}"
implementation "com.squareup.okhttp3:logging-interceptor:${okHttpVer}"
implementation 'com.karumi:dexter:4.2.0'
implementation 'com.google.code.gson:gson:2.8.4'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'ch.acra:acra-http:5.1.2'
implementation('com.afollestad.material-dialogs:core:0.9.6.0') {
exclude group: 'com.android.support', module: 'appcompat-v13'
}
implementation ('com.squareup.picasso:picasso:2.71828') {
exclude group: 'com.android.support', module: 'animated-vector-drawable'
exclude group: 'com.android.support', module: 'exifinterface'
}
...
<receiver android:name=".MyAlarmReceiver" />
<service android:name=".MyService" android:process=":my_app_alternate" android:enabled="true" />
...
public class MyAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, MyService.class));
setupAlarm(context);
}
final long intervalMs = 60000; // Интервал в миллисекундах
public static final void setupAlarm(Context context) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
if (am != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalMs, pi);
} else {
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalMs, pi);
}
}
}
}
public class MyService extends Service {
Thread workThread = null;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (workThread == null) {
workThread = new Thread(run);
workThread.start();
}
return Service.START_STICKY;
}
final Runnable run = new Runnable() {
@Override
public void run() {
try {
while (true) {
//todo Что там надо делать раз в секунду
Thread.sleep(1000);
}
} catch (InterruptedException iex) { }
workThread = null;
}
}
}