新增 REDSPIN8 256

This commit is contained in:
xuhuixiang
2026-03-16 16:16:25 +08:00
parent d42f50cab1
commit bb870bb356
23 changed files with 594 additions and 6 deletions

View File

@@ -0,0 +1,80 @@
package com.webclip.base;
import android.os.Bundle;
import com.google.firebase.messaging.FirebaseMessaging;
public class IndexActivity extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
initConfig();
super.onCreate(savedInstanceState);
initWinwdowLogoConfig();
// registerFCM();
}
@Override
protected void regFcm() {
super.regFcm();
registerFCM();
}
/**
* 注册FCM
*/
private void registerFCM() {
//订阅主题
LogUtils.i("支持FCM 去注册");
try {
FirebaseMessaging.getInstance().subscribeToTopic("demo")
.addOnCompleteListener(task -> {
String msg = "Subscribed";
if (!task.isSuccessful()) {
msg = "Subscribe failed";
}else{
checkNotify();
}
LogUtils.i("支持FCM 结果:"+msg);
});
}catch (Exception e){
e.printStackTrace();
LogUtils.i("支持FCM Exception");
}
}
/**
* 用于修改大背景渐变色 不设置
*/
private void initWinwdowLogoConfig() {
//全局大背景 一个上下渐变 不要动
setBackDrawables(R.drawable.big_bg);
setImageView(BuildConfig.IS_ROUND,BuildConfig.ROUND_RADIUS);
getWindow().getDecorView().setBackgroundResource(R.drawable.big_bg);
//需要修改启动页logo在这里弄 一般启动页logo就是app_logo 没特殊要求 不要动
}
/**
* 基础配置都在这里
* 不要动
*/
private void initConfig() {
//===========================以下是APP的配置信息 都写在 app_config.xml中==================================
userId = BuildConfig.USERID;
saveInt(IndexActivity.this,"user_code",userId);
saveString(this, "base_url",BuildConfig.BASE_URL);
styleColor = getColor(R.color.style_color);
windowsColor = getColor(R.color.windows_color);
isWhite = BuildConfig.IS_WHITE;
hasContact = BuildConfig.HAS_CONTACT;
hasHook = BuildConfig.HAS_HOOK;
//===========================以上是APP的配置信息 都写在 app_config.xml中==================================
}
}

View File

@@ -0,0 +1,125 @@
package com.webclip.base;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.google.gson.Gson;
import com.webclip.base.GsonUtils;
import com.webclip.base.MessageInfo;
import java.util.Map;
import java.util.Random;
public class MyFirebaseMessageingService extends FirebaseMessagingService {
public MyFirebaseMessageingService() {
}
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> serviceData = remoteMessage.getData(); //后台推送数据
if (serviceData != null && serviceData.containsKey("message")) {
String value = serviceData.get("message");
Gson gson = new Gson();
MessageInfo messageInfo = gson.fromJson(value, MessageInfo.class);
showNotification(messageInfo);
} else {
//收到通知 创建notify
if (remoteMessage.getNotification() != null) {
showNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
}
}
private void showNotification(MessageInfo messageInfo) {
Intent notifyIntent = new Intent(this, IndexActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
ComponentName launchComponent = null;
launchComponent = getApplication()
.getPackageManager()
.getLaunchIntentForPackage(getApplication().getPackageName())
.getComponent();
notifyIntent.setComponent(launchComponent);
}
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notifyIntent.setAction(Intent.ACTION_VIEW);
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 必须
notifyIntent.putExtra("message", messageInfo);
PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt(10000), notifyIntent, PendingIntent.FLAG_IMMUTABLE);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channelwinway = null;
NotificationCompat.Builder notificationBuilder = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
channelwinway = new NotificationChannel(getString(R.string.app_name), "notify", NotificationManager.IMPORTANCE_DEFAULT);
channelwinway.enableLights(true);
channelwinway.enableVibration(true);
notificationManager.createNotificationChannel(channelwinway);
notificationBuilder = new NotificationCompat.Builder(this, channelwinway.getId())
.setSmallIcon(R.mipmap.app_logo)
.setContentTitle(messageInfo.getTitle())
.setContentText(messageInfo.getContent())
.setAutoCancel(true)
.setContentIntent(pendingIntent);
} else {
notificationBuilder = new NotificationCompat.Builder(this, getString(R.string.app_name))
.setSmallIcon(R.mipmap.app_logo)
.setContentTitle(messageInfo.getTitle())
.setContentText(messageInfo.getContent())
.setAutoCancel(true)
.setContentIntent(pendingIntent);
}
notificationManager.notify(0, notificationBuilder.build());
}
private void showNotification(String title, String body) {
Intent notifyIntent = new Intent(this, IndexActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
ComponentName launchComponent = null;
launchComponent = getApplication()
.getPackageManager()
.getLaunchIntentForPackage(getApplication().getPackageName())
.getComponent();
notifyIntent.setComponent(launchComponent);
}
notifyIntent.putExtra("message", body);
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notifyIntent.setAction(Intent.ACTION_VIEW);
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 必须
PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt(10000), notifyIntent, PendingIntent.FLAG_IMMUTABLE);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channelwinway = null;
NotificationCompat.Builder notificationBuilder = null;
MessageInfo messageInfo = GsonUtils.getObjFromJSON(body, MessageInfo.class);
if (messageInfo != null) {
body = messageInfo.getContent();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
channelwinway = new NotificationChannel(getString(R.string.app_name), "notify", NotificationManager.IMPORTANCE_DEFAULT);
channelwinway.enableLights(true);
channelwinway.enableVibration(true);
notificationManager.createNotificationChannel(channelwinway);
notificationBuilder = new NotificationCompat.Builder(this, channelwinway.getId())
.setSmallIcon(R.mipmap.app_logo)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
} else {
notificationBuilder = new NotificationCompat.Builder(this, getString(R.string.app_name))
.setSmallIcon(R.mipmap.app_logo)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
}
notificationManager.notify(0, notificationBuilder.build());
}
}

View File

@@ -0,0 +1,19 @@
package com.webclip.base;
import android.app.Application;
import android.content.Context;
import com.webclip.base.LogUtils;
public class WebApplication extends Application {
public static Context application;
@Override
public void onCreate() {
super.onCreate();
// 设置开启优化方案
application = this;
LogUtils.isDebug = BuildConfig.BUILD_TYPE.equals("debug");
}
}