package com.bigfat.servicetest;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
/**
* @author <a href="mailto:fbzhh007@gmail.com">bigfat</a>
* @since 2014/12/11
*/
public class MyService extends Service {
public static final String TAG = "MyService";
private DownloadBinder mBinder = new DownloadBinder();
class DownloadBinder extends Binder {
public void startDownload() {
Log.d(TAG, "startDownload executed");
}
public int getProgress() {
Log.d(TAG, "getProgress executed");
return 0;
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public void onCreate() {
super.onCreate();
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification notification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_launcher).setTicker("Notification comes").setContentTitle("This is title").setContentText("This is content").setContentIntent(pendingIntent).build();
startForeground(1, notification);
Log.d(TAG, "onCreate executed");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand executed");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy executed");
}
}