-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Release 1.3,背景运行(BETA),调整CH34X缓冲区(BETA),通讯期间中文编码问题修复(BETA)
- Loading branch information
1 parent
71babff
commit 8479fe1
Showing
6 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ain/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatService/MyForegroundService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* 受Haohanyh Computer Software Products Open Source LICENSE保护 https://github.com/Hny0305Lin/LICENSE/blob/main/LICENSE */ | ||
package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatService; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Notification; | ||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.os.IBinder; | ||
import android.util.Log; | ||
|
||
import androidx.core.app.NotificationCompat; | ||
|
||
import com.haohanyh.linmengjia.nearlink.nlchat.fun.R; | ||
|
||
public class MyForegroundService extends Service { | ||
private static final String TAG = "MyForegroundService & NLChat"; | ||
private static final String CHANNEL_ID = "ForegroundServiceChannel"; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
Log.d(TAG, "服务已创建"); | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
Log.d(TAG, "服务已启动"); | ||
|
||
createNotificationChannel(); | ||
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) | ||
.setContentTitle("NLChat保活活动") | ||
.setContentText("保持软件后台运行,已启用,请注意电池消耗,消耗过快请关闭本程序。") | ||
.setSmallIcon(R.drawable.app_icon_new) | ||
.build(); | ||
startForeground(1, notification); | ||
|
||
// Your background task code here | ||
|
||
return START_STICKY; | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
Log.d(TAG, "服务已销毁"); | ||
} | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; // We don't provide binding, so return null | ||
} | ||
|
||
@SuppressLint("ObsoleteSdkInt") | ||
private void createNotificationChannel() { | ||
Log.d(TAG, "背景服务通知已创建,可查看Android通知栏"); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
NotificationChannel serviceChannel = new NotificationChannel( | ||
CHANNEL_ID, | ||
"背景服务通知", | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
); | ||
NotificationManager manager = getSystemService(NotificationManager.class); | ||
if (manager != null) { | ||
manager.createNotificationChannel(serviceChannel); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters