package com.pingyijinren.test; import android.annotation.TargetApi; import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.Build; import android.os.IBinder; import android.util.Log; public class MyService extends Service { private DownloadBinder downloadBinder=new DownloadBinder(); public MyService() { } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. //throw new UnsupportedOperationException("Not yet implemented"); return downloadBinder; } @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onCreate(){ super.onCreate(); Log.d("MainActivity","create"); Notification.Builder notificationBuilder=new Notification.Builder(this); notificationBuilder.setContentTitle("叶良辰") .setContentText("我有一百种方法让你呆不下去") .setTicker("收到叶良辰的消息") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher); Notification notification=notificationBuilder.build(); startForeground(1,notification); } @Override public int onStartCommand(Intent intent,int flags,int startId){ Log.d("MainActivity","startCommand"); return super.onStartCommand(intent,flags,startId); } @Override public void onDestroy(){ super.onDestroy(); Log.d("MainActivity","destroy"); } class DownloadBinder extends Binder { public void startDownload(){ Log.d("MainActivity","startDownload"); } public int getProgress(){ Log.d("MainActivity","getProgress"); return 0; } } }