Commit 0bb05f53 authored by wangxuewei's avatar wangxuewei

[提交人]:王雪伟

[提交简述] :幸运农场1.0.6
[实现方案] :加入常驻通知栏
parent 2da405a8
......@@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
......
package com.ym.game.notifservice;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
......@@ -16,7 +17,6 @@ import android.os.IBinder;
import android.widget.RemoteViews;
import androidx.core.app.NotificationCompat;
import com.ym.game.GameActivity;
import com.ym.library.utils.LogUtils;
import com.ym.xync.R;
......@@ -31,7 +31,7 @@ public class NotificationService extends Service {
public final static int ID_FOR_CUSTOM_VIEW = 7;
private ActionReceiver receiver = new ActionReceiver();
public final static String NOTIFICATION_GET_FRUIT = "com.smile.notification.getfruit";
public final static String NOTIFICATION_GET_FRUIT = "com.cync.notification.getfruit";
private static String TAG = "NotificationService";
private NotificationManager mNotificationManager;
......@@ -73,33 +73,14 @@ public class NotificationService extends Service {
super.onCreate();
context = getApplicationContext();
// setAction("show");
initNotification();
//register action broadcast
IntentFilter filter = new IntentFilter();
filter.addAction(NOTIFICATION_GET_FRUIT);
// filter.addAction(IntentAction.NOTIFICATION_PHONE_CLEAN);
// filter.addAction(IntentAction.NOTIFICATION_PHONE_SCAN);
// filter.addAction(IntentAction.NOTIFICATION_SHENGDIAN);
// filter.addAction(IntentAction.NOTIFICATION_WX_CLEAN);
registerReceiver(receiver, filter);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
// isNewMin = intent.getBooleanExtra("isNewMin", false);
// if (isNewMin) {
// memNum = getMemCleanTv(true, true, 0);
// }
// if (intent.getStringExtra("notifCleanNum") != null) {
// notifCleanNum = intent.getStringExtra("notifCleanNum");
// if (notifCleanNum != null && !notifCleanNum.equals("0")) {
// notifCleanUnit = intent.getStringExtra("notifCleanUnit");
// }
// }
}
updateNotivView();
if (notification != null) {
mNotificationManager.notify(ID_FOR_CUSTOM_VIEW, notification);
......@@ -180,7 +161,8 @@ public class NotificationService extends Service {
if (data == null || data.getAction() == null) {
return;
}
collapseStatusBar(context);
// collapseStatusBar(context);
collapseStatusBar();
switch (data.getAction()) {
case NOTIFICATION_GET_FRUIT:
Intent intent2 = new Intent(context, GameActivity.class);
......@@ -234,4 +216,24 @@ public class NotificationService extends Service {
localException.printStackTrace();
}
}
public void collapseStatusBar() {
@SuppressLint("WrongConstant") Object service =getSystemService("statusbar");
if (null == service)
return;
try {
Class<?> clazz = Class.forName("android.app.StatusBarManager");
int sdkVersion = Build.VERSION.SDK_INT;
Method collapse = null;
if (sdkVersion <= 16) {
collapse = clazz.getMethod("collapse");
} else {
collapse = clazz.getMethod("collapsePanels");
}
collapse.setAccessible(true);
collapse.invoke(service);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_notification_click"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/notif_lf_bg"
android:paddingLeft="@dimen/dp_14"
android:paddingRight="@dimen/dp_14">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@mipmap/notif_lf_title" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="这是一个通知栏" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@mipmap/notif_lf_btn" />
</LinearLayout>
\ No newline at end of file
</RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment