version:1.0
fix: update:更换包名
This commit is contained in:
56
app/src/main/java/com/uiui/zyos/service/DownloadService.java
Normal file
56
app/src/main/java/com/uiui/zyos/service/DownloadService.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.uiui.zyos.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
|
||||
public class DownloadService extends Service {
|
||||
private static final String TAG = DownloadService.class.getSimpleName();
|
||||
|
||||
public DownloadService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Aria.init(this);
|
||||
Aria.download(this).register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
Log.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
Log.e(TAG, "taskComplete: " + task.getFilePath());
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.uiui.zyos.service;
|
||||
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author TT
|
||||
*/
|
||||
public class NotificationService extends NotificationListenerService {
|
||||
private static final String TAG = NotificationService.class.getSimpleName();
|
||||
|
||||
private static HashMap<String, List<StatusBarNotification>> notificationMap = new HashMap<String, List<StatusBarNotification>>();
|
||||
private static Set<NotificationListener> mListener = new HashSet<NotificationListener>();
|
||||
|
||||
private void updateNotification() {
|
||||
notificationMap.clear();
|
||||
StatusBarNotification[] statusBarNotifications = getActiveNotifications();
|
||||
for (StatusBarNotification sbn : statusBarNotifications) {
|
||||
String pkg = sbn.getPackageName();
|
||||
Log.e(TAG, "onListenerUpdate: " + pkg);
|
||||
if (notificationMap.get(pkg) == null) {
|
||||
notificationMap.put(pkg, new ArrayList<>());
|
||||
notificationMap.get(pkg).add(sbn);
|
||||
} else {
|
||||
notificationMap.get(pkg).add(sbn);
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "onListenerUpdate: " + notificationMap);
|
||||
}
|
||||
|
||||
public static int getNotificationLength(String pkg) {
|
||||
if (notificationMap.get(pkg) == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return notificationMap.get(pkg).size();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setListener(NotificationListener listener) {
|
||||
mListener.add(listener);
|
||||
}
|
||||
|
||||
public interface NotificationListener {
|
||||
void onListenerUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListenerConnected() {
|
||||
super.onListenerConnected();
|
||||
Log.e(TAG, "onListenerUpdate: " + getActiveNotifications().length);
|
||||
updateNotification();
|
||||
for (NotificationListener listener : mListener) {
|
||||
listener.onListenerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationPosted(StatusBarNotification sbn) {
|
||||
super.onNotificationPosted(sbn);
|
||||
Log.e(TAG, "onNotificationPosted: " + getActiveNotifications().length);
|
||||
updateNotification();
|
||||
for (NotificationListener listener : mListener) {
|
||||
listener.onListenerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||
super.onNotificationRemoved(sbn);
|
||||
Log.e(TAG, "onNotificationRemoved: " + getActiveNotifications().length);
|
||||
updateNotification();
|
||||
for (NotificationListener listener : mListener) {
|
||||
listener.onListenerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.uiui.zyos.service.main;
|
||||
|
||||
import com.uiui.zyos.base.BasePresenter;
|
||||
import com.uiui.zyos.base.BaseView;
|
||||
|
||||
public class MainSContact {
|
||||
public interface Presenter extends BasePresenter<MainSView> {
|
||||
}
|
||||
|
||||
public interface MainSView extends BaseView {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.uiui.zyos.service.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
|
||||
/**
|
||||
* MainActivity和MainService 的 Presenter
|
||||
*
|
||||
* @author jgy02
|
||||
*/
|
||||
public class MainSPresenter implements MainSContact.Presenter {
|
||||
private static final String TAG = MainSPresenter.class.getSimpleName();
|
||||
private static final int OK = 200;
|
||||
private MainSContact.MainSView mView;
|
||||
private Context mContext;
|
||||
MMKV mMMKV = MMKV.defaultMMKV();
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
public MainSPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "MainSPresenter: " + context.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@androidx.annotation.NonNull MainSContact.MainSView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.uiui.zyos.service.main;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.uiui.zyos.base.BaseService;
|
||||
|
||||
public class MainService extends BaseService implements MainSContact.MainSView, NetworkUtils.OnNetworkStatusChangedListener {
|
||||
private static final String TAG = MainService.class.getSimpleName();
|
||||
public MainSPresenter mPresenter;
|
||||
|
||||
public MainService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
Log.e(TAG, "onBind: ");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.e(TAG, "onCreate: ");
|
||||
mPresenter = new MainSPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e(TAG, "onStartCommand: ");
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPresenter.detachView();
|
||||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||||
}
|
||||
|
||||
public static final String ALARMWAKEUP = "ALARM_WAKEUP";
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user