Commit eedf5b89 authored by wangxuewei's avatar wangxuewei

[提交人]:王雪伟

[提交简述] :幸运农场
[实现方案] :加入通知栏
parent eb3fd41f
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<meta-data <meta-data
android:name="notch.config" android:name="notch.config"
android:value="portrait|landscape" /> android:value="portrait|landscape" />
<service android:name="com.ym.game.notifservice.NotificationService"/>
<activity <activity
android:name="com.ym.game.activity.SplashActivity" android:name="com.ym.game.activity.SplashActivity"
android:noHistory="false" android:noHistory="false"
......
package com.ym.game package com.ym.game
import android.annotation.SuppressLint import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle import android.os.Bundle
import android.os.IBinder
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import com.bx.adsdk.AdSdk import com.bx.adsdk.AdSdk
import com.game.luckyfarm.UnityPlayerActivity import com.game.luckyfarm.UnityPlayerActivity
import com.umeng.analytics.MobclickAgent import com.umeng.analytics.MobclickAgent
import com.ym.admodule.rs.RSADUtils
import com.ym.game.activity.SplashActivity
import com.ym.game.activity.WxLoginActivity import com.ym.game.activity.WxLoginActivity
import com.ym.game.listener.IDialogViewCloseCallback import com.ym.game.listener.IDialogViewCloseCallback
import com.ym.game.module.* import com.ym.game.module.*
import com.ym.game.net.GameApiClient import com.ym.game.net.GameApiClient
import com.ym.game.notifservice.NotificationService
import com.ym.game.view.MainDialog import com.ym.game.view.MainDialog
import com.ym.game.view.SiginDropsPopupwindow import com.ym.game.view.SiginDropsPopupwindow
import com.ym.game.view.TurntableDialog import com.ym.game.view.TurntableDialog
import com.ym.library.AppliContext import com.ym.library.AppliContext
import com.ym.library.Constant import com.ym.library.Constant
import com.ym.library.config.AdManager import com.ym.library.config.AdManager
import com.ym.library.config.ZXADCallback
import com.ym.library.config.ZXADRewardVideo import com.ym.library.config.ZXADRewardVideo
import com.ym.library.down.UpdateVersionManager import com.ym.library.down.UpdateVersionManager
import com.ym.library.listener.ZXADVideoListener import com.ym.library.listener.ZXADVideoListener
...@@ -31,15 +31,11 @@ import com.ym.library.net.ApiClient ...@@ -31,15 +31,11 @@ import com.ym.library.net.ApiClient
import com.ym.library.net.BaseObserver import com.ym.library.net.BaseObserver
import com.ym.library.net.RxSchedulers import com.ym.library.net.RxSchedulers
import com.ym.library.net.UserInfoEntity import com.ym.library.net.UserInfoEntity
import com.ym.library.router.RounterApi
import com.ym.library.router.RounterBus
import com.ym.library.sm.SMADUtils
import com.ym.library.utils.* import com.ym.library.utils.*
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import org.jetbrains.anko.act import org.jetbrains.anko.act
import java.lang.reflect.Method import java.lang.reflect.Method
import java.text.DecimalFormat
/** /**
* @author (wangXuewei) * @author (wangXuewei)
...@@ -81,9 +77,11 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback { ...@@ -81,9 +77,11 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback {
AdSdk.exposure("2654", SettingPreference.getToken()) AdSdk.exposure("2654", SettingPreference.getToken())
Constant.isReportXiaoman = false Constant.isReportXiaoman = false
} }
openNotif()
} }
override fun onDestroy() { override fun onDestroy() {
scc?.let { unbindService(it) }
super.onDestroy() super.onDestroy()
if (mRefreshLoginObservable != null) { if (mRefreshLoginObservable != null) {
RxBus.get().unregister("refresh_login", mRefreshLoginObservable!!)//页面销毁的时候要执行 反注册 RxBus.get().unregister("refresh_login", mRefreshLoginObservable!!)//页面销毁的时候要执行 反注册
...@@ -893,13 +891,13 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback { ...@@ -893,13 +891,13 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback {
if (result != null) { if (result != null) {
callUnity("RedPackList", "redPackListDataUpdate", "") callUnity("RedPackList", "redPackListDataUpdate", "")
callUnity("TitleView", "getHomeInfo", "") callUnity("TitleView", "getHomeInfo", "")
GameEvent("show_receive_redPack_dialog_success","展示红包领取弹窗成功") GameEvent("show_receive_redPack_dialog_success", "展示红包领取弹窗成功")
//签到双倍领取弹窗显示 //签到双倍领取弹窗显示
CenterDialog.getTaskRewardDialog( CenterDialog.getTaskRewardDialog(
act, act,
"+${moneyNum}元", "+${moneyNum}元",
View.OnClickListener { View.OnClickListener {
GameEvent("click_receive_redPack_double","点击六倍领取") GameEvent("click_receive_redPack_double", "点击六倍领取")
Log.d("wxw", "签到翻倍广告点击") Log.d("wxw", "签到翻倍广告点击")
AdManager.loadRewardVideoAd( AdManager.loadRewardVideoAd(
ADConfig.AD_REWARD_VIDIO, ADConfig.AD_REWARD_VIDIO,
...@@ -965,7 +963,7 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback { ...@@ -965,7 +963,7 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback {
} }
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) { override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
GameEvent("show_receive_redPack_dialog_fail","展示红包领取弹窗失败") GameEvent("show_receive_redPack_dialog_fail", "展示红包领取弹窗失败")
} }
}) })
} }
...@@ -977,7 +975,7 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback { ...@@ -977,7 +975,7 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback {
.subscribe(object : BaseObserver<RedPackDoubleReceiveEntity>() { .subscribe(object : BaseObserver<RedPackDoubleReceiveEntity>() {
override fun onSuccess(result: RedPackDoubleReceiveEntity?) { override fun onSuccess(result: RedPackDoubleReceiveEntity?) {
if (result != null) { if (result != null) {
GameEvent("show_receive_redPack_double_success","六倍领取成功") GameEvent("show_receive_redPack_double_success", "六倍领取成功")
var allMoneyNum = var allMoneyNum =
"总共获得奖励+${result.rewardContentList[0].totalRewardNum / 100.toDouble()}元"; "总共获得奖励+${result.rewardContentList[0].totalRewardNum / 100.toDouble()}元";
ToastUtil.showImageToas(act, allMoneyNum) ToastUtil.showImageToas(act, allMoneyNum)
...@@ -986,7 +984,7 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback { ...@@ -986,7 +984,7 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback {
} }
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) { override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
GameEvent("show_receive_redPack_double_fail","六倍领取失败") GameEvent("show_receive_redPack_double_fail", "六倍领取失败")
} }
}) })
} }
...@@ -1023,4 +1021,21 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback { ...@@ -1023,4 +1021,21 @@ class GameActivity : UnityPlayerActivity(), IDialogViewCloseCallback {
} }
}) })
} }
private var myNotifService: NotificationService? = null
private var scc: ServiceConnection? = null
//打开通知栏
private fun openNotif() {
val intent = Intent(this, NotificationService::class.java)
scc = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
val myBinder: NotificationService.MyBinder = service as NotificationService.MyBinder
myNotifService = myBinder.getService()
}
override fun onServiceDisconnected(name: ComponentName) {}
}
bindService(intent, scc as ServiceConnection, BIND_AUTO_CREATE)
}
} }
\ No newline at end of file
...@@ -32,7 +32,7 @@ class BaseApplication : MultiDexApplication() { ...@@ -32,7 +32,7 @@ class BaseApplication : MultiDexApplication() {
//第一步初始化 application //第一步初始化 application
AppliContext.init(this) AppliContext.init(this)
// Config.init(this) // Config.init(this)
NetConfig.setBase_Url(NetConfig.Environment.PRODUCT)// TODO 上线之后提成成 NetConfig.Environment.PRODUCT NetConfig.setBase_Url(NetConfig.Environment.DEV)// TODO 上线之后提成成 NetConfig.Environment.PRODUCT
Constant.appLs = "a03d5320d905cf3b"//applsq Constant.appLs = "a03d5320d905cf3b"//applsq
AdManager.init(this) AdManager.init(this)
...@@ -129,4 +129,6 @@ class BaseApplication : MultiDexApplication() { ...@@ -129,4 +129,6 @@ class BaseApplication : MultiDexApplication() {
Log.i("Application", "Channel = $string") Log.i("Application", "Channel = $string")
return string ?: "" return string ?: ""
} }
} }
\ No newline at end of file
package com.ym.game.notifservice;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.Build;
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;
import java.lang.reflect.Method;
public class NotificationService extends Service {
private Context context;
private RemoteViews NormalView;
private Notification notification;
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";
private static String TAG = "NotificationService";
private NotificationManager mNotificationManager;
public class MyBinder extends Binder {
public NotificationService getService() {
return NotificationService.this;
}
}
//通过binder实现调用者client与Service之间的通信
private MyBinder binder = new MyBinder();
@Override
public IBinder onBind(Intent intent) {
return binder;
}
@Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
public static void startNotificationService(Context ctx) {
try {
// Boolean isOpen = (Boolean) SPUtils.get(ctx, SPUtils.SP_LONG_NOTICATION, true);
// if (!isOpen) {
// return;
// }
//开启常驻通知栏
Intent intent3 = new Intent(ctx, NotificationService.class);
ctx.startService(intent3);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onCreate() {
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);
}
return Service.START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
if (receiver != null)
unregisterReceiver(receiver);
}
private void initNotification() {
if (mNotificationManager == null) {
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
PendingIntent getFruitIntent = PendingIntent.getBroadcast(context, (int) System.currentTimeMillis(), new Intent(NOTIFICATION_GET_FRUIT), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, createNotificationChannel(this));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
builder.setSmallIcon(R.mipmap.icon_launch)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.app_name))
.setTicker(context.getString(R.string.app_name))
.setPriority(Notification.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setGroupSummary(true)
.setGroup("group")
.setOngoing(true);
} else {
builder.setSmallIcon(R.mipmap.icon_launch)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.app_name))
.setTicker(context.getString(R.string.app_name))
.setPriority(Notification.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setOngoing(true);
}
//Couldn't expand RemoteViews
try {
updateNotivView();
builder.setCustomContentView(NormalView);
NormalView.setOnClickPendingIntent(R.id.id_notification_click, getFruitIntent);
notification = builder.build();
} catch (Exception e) {
e.printStackTrace();
}
// startForeground(ID_FOR_CUSTOM_VIEW, notification);
// Boolean isOpen = (Boolean) SPUtils.get(context, SPUtils.SP_LONG_NOTICATION, true);
Boolean isOpen = true;
try {
if (isOpen) {
if (notification != null) {
startForeground(ID_FOR_CUSTOM_VIEW, notification);
}
}
} catch (Exception e) {
LogUtils.e(TAG, "set service for push exception: ", e);
}
}
private void updateNotivView() {
//Couldn't expand RemoteViews
try {
if (NormalView == null) {
NormalView = new RemoteViews(context.getPackageName(), R.layout.notification_view);
}
} catch (Exception e) {
e.printStackTrace();
}
}
class ActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent data) {
if (data == null || data.getAction() == null) {
return;
}
collapseStatusBar(context);
switch (data.getAction()) {
case NOTIFICATION_GET_FRUIT:
Intent intent2 = new Intent(context, GameActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent2);
break;
default:
break;
}
}
}
//9.0通知栏 适配
public static String createNotificationChannel(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "luck_farm";
CharSequence channelName = "幸运农场";
String channelDescription = "快速收获";
int channelImportance = NotificationManager.IMPORTANCE_MIN;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, channelImportance);
// 设置描述 最长30字符
notificationChannel.setDescription(channelDescription);
// 该渠道的通知是否使用震动
notificationChannel.enableVibration(false);
// 设置显示模式
notificationChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
return channelId;
} else {
return null;
}
}
public void collapseStatusBar(Context context) {
try {
@SuppressLint("WrongConstant") Object statusBarManager = context.getSystemService("statusbar");
Method collapse;
if (Build.VERSION.SDK_INT <= 16) {
collapse = statusBarManager.getClass().getMethod("collapse");
} else {
collapse = statusBarManager.getClass().getMethod("collapsePanels");
}
collapse.invoke(statusBarManager);
} catch (Exception localException) {
localException.printStackTrace();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/id_notification_click"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="这是一个通知栏" />
</LinearLayout>
\ No newline at end of file
...@@ -92,7 +92,7 @@ dependencies { ...@@ -92,7 +92,7 @@ dependencies {
api 'com.tencent.bugly:crashreport:latest.release' api 'com.tencent.bugly:crashreport:latest.release'
api 'com.tencent.bugly:nativecrashreport:latest.release' api 'com.tencent.bugly:nativecrashreport:latest.release'
api('cn.vlion.inland:inlandmix:9.8.2') { api('cn.vlion.inland:inlandmix:9.8.5') {
exclude group: 'cn.vlion.inland', module: 'inlandb' exclude group: 'cn.vlion.inland', module: 'inlandb'
exclude group: 'cn.vlion.inland', module: 'inlandg' exclude group: 'cn.vlion.inland', module: 'inlandg'
exclude group: 'cn.vlion.inland', module: 'inlands' exclude group: 'cn.vlion.inland', module: 'inlands'
......
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