最新一次版本提交
This commit is contained in:
58
koala88/src/main/java/com/xyz/alako21/MainActivity.java
Normal file
58
koala88/src/main/java/com/xyz/alako21/MainActivity.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.xyz.alako21;
|
||||
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.web.base.LogUtils;
|
||||
import com.web.base.MainActivity2;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
|
||||
public class MainActivity extends MainActivity2 {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
userId = 47;
|
||||
saveInt(MainActivity.this,"user_code",userId);
|
||||
saveInt(MainActivity.this,"version_code",getVersion());
|
||||
com.web.base.MainActivity.saveString(this, "base_url","https://koala88.co/");
|
||||
//网页的底部NavigationBar颜色
|
||||
com.web.base.MainActivity.saveString(this, "style_color", "#ffd1d2");
|
||||
//页面的大背景颜色
|
||||
com.web.base.MainActivity.saveString(this, "windows_color", "#614e97");
|
||||
//任务栏的文字颜色 0 黑 1白 默认黑
|
||||
saveInt(MainActivity.this,"is_white",1);
|
||||
super.onCreate(savedInstanceState);
|
||||
//用于修改大背景渐变色 不设置 大背景就是 windows_color 的颜色
|
||||
setBackDrawables(R.drawable.big_bg);
|
||||
setImageView(true);
|
||||
//订阅主题
|
||||
FirebaseMessaging.getInstance().subscribeToTopic("demo")
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
String msg = "Subscribed";
|
||||
if (!task.isSuccessful()) {
|
||||
msg = "Subscribe failed";
|
||||
}
|
||||
LogUtils.i("结果:"+msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getVersion(){
|
||||
try {
|
||||
PackageManager packageManager = getPackageManager();
|
||||
PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
|
||||
int versionCode = packageInfo.versionCode; // 版本码
|
||||
return versionCode;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.xyz.alako21;
|
||||
|
||||
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.web.base.GsonUtils;
|
||||
import com.web.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, MainActivity.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(com.web.base.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(com.web.base.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, MainActivity.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(com.web.base.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(com.web.base.R.string.app_name))
|
||||
.setSmallIcon(R.mipmap.app_logo)
|
||||
.setContentTitle(title)
|
||||
.setContentText(body)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent);
|
||||
}
|
||||
notificationManager.notify(0, notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
35
koala88/src/main/java/com/xyz/alako21/WebApplication.java
Normal file
35
koala88/src/main/java/com/xyz/alako21/WebApplication.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.xyz.alako21;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import com.tencent.smtt.export.external.TbsCoreSettings;
|
||||
import com.tencent.smtt.sdk.QbSdk;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class WebApplication extends Application {
|
||||
|
||||
|
||||
public static Context application;
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
// 设置开启优化方案
|
||||
application = this;
|
||||
HashMap map = new HashMap();
|
||||
map.put(TbsCoreSettings.TBS_SETTINGS_USE_SPEEDY_CLASSLOADER, true);
|
||||
map.put(TbsCoreSettings.TBS_SETTINGS_USE_DEXLOADER_SERVICE, true);
|
||||
QbSdk.initTbsSettings(map);
|
||||
QbSdk.initX5Environment(this, new QbSdk.PreInitCallback() {
|
||||
@Override
|
||||
public void onCoreInitFinished() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewInitFinished(boolean b) {
|
||||
|
||||
}
|
||||
});
|
||||
QbSdk.setDownloadWithoutWifi(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user