Commit 0bb05f53 authored by wangxuewei's avatar wangxuewei

[提交人]:王雪伟

[提交简述] :幸运农场1.0.6
[实现方案] :加入常驻通知栏
parent 2da405a8
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_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.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_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
......
package com.ym.game.notifservice; package com.ym.game.notifservice;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
...@@ -16,7 +17,6 @@ import android.os.IBinder; ...@@ -16,7 +17,6 @@ import android.os.IBinder;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import com.ym.game.GameActivity; import com.ym.game.GameActivity;
import com.ym.library.utils.LogUtils; import com.ym.library.utils.LogUtils;
import com.ym.xync.R; import com.ym.xync.R;
...@@ -31,7 +31,7 @@ public class NotificationService extends Service { ...@@ -31,7 +31,7 @@ public class NotificationService extends Service {
public final static int ID_FOR_CUSTOM_VIEW = 7; public final static int ID_FOR_CUSTOM_VIEW = 7;
private ActionReceiver receiver = new ActionReceiver(); 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 static String TAG = "NotificationService";
private NotificationManager mNotificationManager; private NotificationManager mNotificationManager;
...@@ -73,33 +73,14 @@ public class NotificationService extends Service { ...@@ -73,33 +73,14 @@ public class NotificationService extends Service {
super.onCreate(); super.onCreate();
context = getApplicationContext(); context = getApplicationContext();
// setAction("show");
initNotification(); initNotification();
//register action broadcast
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(NOTIFICATION_GET_FRUIT); 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); registerReceiver(receiver, filter);
} }
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { 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(); updateNotivView();
if (notification != null) { if (notification != null) {
mNotificationManager.notify(ID_FOR_CUSTOM_VIEW, notification); mNotificationManager.notify(ID_FOR_CUSTOM_VIEW, notification);
...@@ -180,7 +161,8 @@ public class NotificationService extends Service { ...@@ -180,7 +161,8 @@ public class NotificationService extends Service {
if (data == null || data.getAction() == null) { if (data == null || data.getAction() == null) {
return; return;
} }
collapseStatusBar(context); // collapseStatusBar(context);
collapseStatusBar();
switch (data.getAction()) { switch (data.getAction()) {
case NOTIFICATION_GET_FRUIT: case NOTIFICATION_GET_FRUIT:
Intent intent2 = new Intent(context, GameActivity.class); Intent intent2 = new Intent(context, GameActivity.class);
...@@ -234,4 +216,24 @@ public class NotificationService extends Service { ...@@ -234,4 +216,24 @@ public class NotificationService extends Service {
localException.printStackTrace(); 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"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/id_notification_click" 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 <ImageView
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:layout_alignParentRight="true"
android:text="这是一个通知栏" /> android:layout_centerVertical="true"
android:src="@mipmap/notif_lf_btn" />
</LinearLayout> </RelativeLayout>
\ No newline at end of file \ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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