不多说了,直接上代码:
Notification.Builder localBuilder = new Notification.Builder(this);
localBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, Test_Gson_AsyncTask.class), 0));
localBuilder.setAutoCancel(false);
localBuilder.setSmallIcon(R.drawable.a1);
localBuilder.setTicker("Foreground Service Start");
localBuilder.setContentTitle("Socket服务端");
localBuilder.setContentText("正在运行...");
// startForeground(1, localBuilder.getNotification());//过时版本
startForeground(1, localBuilder.build());//新版本
ok!最近脑子不大好使,查眼记录一下。。。