前台服务(在通知栏显示服务)
生活随笔
收集整理的這篇文章主要介紹了
前台服务(在通知栏显示服务)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
關鍵代碼:
public class MyService extends Service {@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}@Overridepublic void onCreate() {Intent notifyIntent = new Intent(this, MainActivity.class);PendingIntent pendingIntent = PendingIntent.getActivity(this,0, notifyIntent,0);Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher).setContentTitle("通知").setContentText("我是服務的通知").setContentIntent(pendingIntent).setDefaults(Notification.DEFAULT_ALL). // 設置用手機默認的震動或聲音來提示 build();// 設置為前臺服務,在系統狀態欄顯示startForeground(1, notification);super.onCreate();} }?
轉載于:https://www.cnblogs.com/itfenqing/p/6753176.html
總結
以上是生活随笔為你收集整理的前台服务(在通知栏显示服务)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网页开发——从接触到编写输出一个DIV
- 下一篇: 百度地图api location 211