Commit eae8f13f authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

files services added

parent 3fc3db19
package com.example.android.customnotifications.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import com.example.android.customnotifications.services.Helper;
/**
* Created by giacomo on 12/05/18.
*/
public class BootCompletedReceiver extends BroadcastReceiver {
private static final String TAG = "BootCompletedReceiver";
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Log.w("boot_broadcast_poc", "starting service...");
Helper.StartForegroundServiceNotification(context);
}
}
\ No newline at end of file
package com.example.android.customnotifications.services;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
/**
* Created by giacomo on 12/05/18.
*/
public class Helper {
public static void StartForegroundServiceNotification(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, NotificationService.class));
} else {
context.startService(new Intent(context, NotificationService.class));
}
}
}
package com.example.android.customnotifications.services;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
/**
* Created by giacomo on 12/05/18.
*/
public class NotificationService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment