We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
使用前台服务相当于会在用户手机上显示一条常驻通知,所以要特别处理,在Android26以下利用谷歌漏洞处理
/**
Created by lang.chen on 2019/9/5 */ public class LForegroundService extends Service {
@OverRide public IBinder onBind(Intent intent) { return null; } @OverRide public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { startMyOwnForeground(); }else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){ //API Version 18以上 Notification.Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.mipmap.ic_launcher); startForeground(2, builder.build()); startService(new Intent(this, InnerService.class)); } }
public static class InnerService extends Service{ @OverRide public IBinder onBind(Intent intent) { return null; } @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @OverRide public void onCreate() { super.onCreate(); //发送与上面服务中ID相同的Notification,然后将其取消并取消自己的前台显示 Notification.Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.mipmap.ic_launcher); startForeground(2, builder.build()); new Handler().postDelayed(new Runnable() { @OverRide public void run() { stopForeground(true); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.cancel(2); stopSelf(); } },100);
}
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: