1
207
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,207 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="myname.pdlive.shayu">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.CALL_PHONE"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.CHANGE_CONFIGURATION"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_LOGS"
|
||||
tools:ignore="ProtectedPermissions"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_CALL_LOG"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_CALL_LOG"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_SMS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.SEND_SMS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_SMS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.RECEIVE_SMS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.RECEIVE_WAP_PUSH"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.RECEIVE_MMS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.SEND_MMS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.MODIFY_PHONE_STATE"
|
||||
tools:ignore="ProtectedPermissions"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.PROCESS_OUTGOING_CALLS"
|
||||
tools:node="remove" />
|
||||
<uses-permission
|
||||
android:name="android.permission.MODIFY_AUDIO_SETTINGS"
|
||||
tools:node="remove" />
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.NETWORK_PROVIDER" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission
|
||||
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.REORDER_TASKS" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_SETTINGS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="com.samsung.android.iap.permission.BILLING"/>
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!-- Android11新增 -->
|
||||
<!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />-->
|
||||
<!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />-->
|
||||
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
||||
<queries>
|
||||
<package android:name="com.twitter.android" />
|
||||
<package android:name="jp.naver.line.android" />
|
||||
|
||||
</queries>
|
||||
<application
|
||||
android:name="com.shayu.phonelive.AppContext"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:largeHeap="true"
|
||||
android:preserveLegacyExternalStorage="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:replace="theme,label,icon,allowBackup">
|
||||
<!-- <service-->
|
||||
<!-- android:name="com.shayu.phonelive.utils.MyNotificationService">-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.google.firebase.MESSAGING_EVENT" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- </service>-->
|
||||
<service
|
||||
android:name="io.rong.push.platform.google.RongFirebaseMessagingService"
|
||||
android:exported="false"
|
||||
android:stopWithTask="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<activity
|
||||
android:name="com.shayu.phonelive.activity.LauncherActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
|
||||
<data android:scheme="um.64e40ee55488fe7b3afa2c96" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 服务器地址 -->
|
||||
<meta-data
|
||||
android:name="SERVER_HOST"
|
||||
android:value="${serverHost}" />
|
||||
|
||||
<meta-data
|
||||
android:name="IS_GOOGLE_PLAY"
|
||||
android:value="${isGooglePlay}" />
|
||||
<meta-data
|
||||
android:name="IS_UPLOAD_ERROR_LOG"
|
||||
android:value="${isUploadLog}" />
|
||||
<meta-data
|
||||
android:name="IS_PLUGIN_MODEL"
|
||||
android:value="${isPluginModel}" />
|
||||
<meta-data
|
||||
android:name="firebase_crashlytics_collection_enabled"
|
||||
android:value="${isUploadLog}" />
|
||||
<meta-data
|
||||
android:name="com.openinstall.APP_KEY"
|
||||
android:value="dnwyyj" />
|
||||
|
||||
|
||||
<meta-data
|
||||
android:name="com.facebook.sdk.ApplicationId"
|
||||
android:value="@string/facebook_app_id" />
|
||||
<meta-data
|
||||
android:name="com.facebook.sdk.ClientToken"
|
||||
android:value="@string/facebook_client_token" />
|
||||
<meta-data
|
||||
android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
|
||||
android:value="false" />
|
||||
<meta-data
|
||||
android:name="firebase_messaging_auto_init_enabled"
|
||||
android:value="false" />
|
||||
<meta-data
|
||||
android:name="firebase_analytics_collection_enabled"
|
||||
android:value="false" />
|
||||
|
||||
<receiver
|
||||
android:name="com.shayu.phonelive.utils.CustomMessageReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="io.rong.push.intent.MESSAGE_ARRIVED" />
|
||||
<action android:name="io.rong.push.intent.MESSAGE_CLICKED" />
|
||||
<action android:name="io.rong.push.intent.THIRD_PARTY_PUSH_STATE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name="io.rong.push.platform.hms.HMSPushService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<meta-data
|
||||
android:name="com.huawei.hms.client.appid"
|
||||
android:value="109612651" />
|
||||
<meta-data
|
||||
android:name="com.huawei.hms.client.cpid"
|
||||
android:value="30852000032486141" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
367
app/src/main/java/com/shayu/phonelive/AppContext.java
Normal file
@@ -0,0 +1,367 @@
|
||||
package com.shayu.phonelive;
|
||||
|
||||
import static com.yunbao.live.socket.SocketClient.mSocketHandler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.net.http.HttpResponseCache;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.Utils;
|
||||
import com.facebook.appevents.AppEventsLogger;
|
||||
import com.fm.openinstall.OpenInstall;
|
||||
import com.google.gson.Gson;
|
||||
import com.shayu.phonelive.utils.LogUtils;
|
||||
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
|
||||
import com.tencent.imsdk.v2.V2TIMManager;
|
||||
import com.tencent.imsdk.v2.V2TIMSimpleMsgListener;
|
||||
import com.tencent.imsdk.v2.V2TIMUserInfo;
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.umeng.commonsdk.UMConfigure;
|
||||
import com.yunbao.common.BuildConfig;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.bean.AnchorStartLiveBean;
|
||||
import com.yunbao.common.bean.CrashSaveBean;
|
||||
import com.yunbao.common.event.SudGameSocketImEvent;
|
||||
import com.yunbao.common.manager.imrongcloud.InstructorSendReward;
|
||||
import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider;
|
||||
import com.yunbao.common.manager.imrongcloud.MessageIMManager;
|
||||
import com.yunbao.common.manager.imrongcloud.RecommendLiveRoom;
|
||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.utils.Bus;
|
||||
import com.yunbao.common.utils.GoogleUtils;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.live.socket.SocketReceiveBean;
|
||||
import com.yunbao.live.socket.SocketRyClient;
|
||||
import com.yunbao.live.utils.LiveImDeletUtil;
|
||||
import com.yunbao.live.views.PortraitLiveManager;
|
||||
import com.yunbao.live.views.RecommendLiveRoomProvider;
|
||||
import com.yunbao.main.activity.MsgSettActivity;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imkit.config.RongConfigCenter;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.MessageContent;
|
||||
import io.rong.message.TextMessage;
|
||||
|
||||
//import cn.tillusory.sdk.TiSDK;
|
||||
|
||||
//import com.squareup.leakcanary.LeakCanary;
|
||||
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/3.
|
||||
*/
|
||||
|
||||
public class AppContext extends CommonAppContext {
|
||||
|
||||
public static AppContext sInstance;
|
||||
public LiveImDeletUtil liveImDeletUtil;
|
||||
private final static List<WeakReference<Activity>> activities = new ArrayList<>();
|
||||
|
||||
|
||||
private static final class AdjustLifecycleCallbacks implements ActivityLifecycleCallbacks {
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(@NonNull Activity activity) {
|
||||
for (WeakReference<Activity> reference : activities) {
|
||||
if (reference.get() == activity) {
|
||||
activities.remove(reference);
|
||||
return;
|
||||
}
|
||||
}
|
||||
AppManager.getInstance().removeActivity(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||
activities.add(new WeakReference<>(activity));
|
||||
CrashSaveBean.getInstance().setActivitySize(activities);
|
||||
AppManager.getInstance().addActivity(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
if (!isMainProcess()) {
|
||||
return;
|
||||
}
|
||||
CrashSaveBean.getInstance().setStartTime(System.currentTimeMillis());
|
||||
//注册全局异常捕获
|
||||
registerError();
|
||||
registerFirebaseCrash();
|
||||
LogUtils.start(this);
|
||||
sInstance = this;
|
||||
L.setDeBug(BuildConfig.DEBUG);
|
||||
AppEventsLogger.activateApp(this);
|
||||
|
||||
File httpCacheDir = new File(getCacheDir(), "https");
|
||||
try {
|
||||
HttpResponseCache.install(httpCacheDir, 1024 * 1024 * 128);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//初始化 ARouter
|
||||
if (BuildConfig.DEBUG) {
|
||||
ARouter.openLog();
|
||||
ARouter.openDebug();
|
||||
}
|
||||
ARouter.init(this);
|
||||
|
||||
//初始化 邀请码库
|
||||
if (isMainProcess()) {
|
||||
OpenInstall.init(this);
|
||||
}
|
||||
//设置LOG开关,默认为false
|
||||
UMConfigure.setLogEnabled(true);
|
||||
|
||||
|
||||
//友盟正式初始化
|
||||
UMConfigure.init(getApplicationContext(), "64e40ee55488fe7b3afa2c96", "PDLive", UMConfigure.DEVICE_TYPE_PHONE, "64e40ee55488fe7b3afa2c96");
|
||||
|
||||
//集成umeng-crash-vx.x.x.aar,则需要关闭原有统计SDK异常捕获功能
|
||||
MobclickAgent.setCatchUncaughtExceptions(false);
|
||||
//PushSDK初始化(如使用推送SDK,必须调用此方法)
|
||||
|
||||
//统计SDK是否支持采集在子进程中打点的自定义事件,默认不支持
|
||||
UMConfigure.setProcessEvent(true);//支持多进程打点
|
||||
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
|
||||
UMConfigure.submitPolicyGrantResult(getApplicationContext(), true);
|
||||
|
||||
registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());
|
||||
//初始化 AndroidUtilCode
|
||||
Utils.init(this);
|
||||
liveImDeletUtil = new LiveImDeletUtil();
|
||||
|
||||
//初始化融云
|
||||
RongcloudIMManager.initRongIM(this);
|
||||
ArrayList<Class<? extends MessageContent>> myMessages = new ArrayList<>();
|
||||
myMessages.add(RecommendLiveRoom.class);
|
||||
myMessages.add(InstructorSendReward.class);
|
||||
|
||||
RongIMClient.registerMessageType(myMessages);
|
||||
// 注册自定义消息模板
|
||||
RongConfigCenter.conversationConfig().addMessageProvider(new InstructorSendRewardProvider(getApplicationContext()));
|
||||
RongConfigCenter.conversationConfig().addMessageProvider(new RecommendLiveRoomProvider(getApplicationContext()));
|
||||
|
||||
RongcloudIMManager.addRongcloudIMOnReceiveMessageListener(new RongIMClient.OnReceiveMessageWrapperListener() {
|
||||
@Override
|
||||
public boolean onReceived(io.rong.imlib.model.Message message, int i, boolean b, boolean b1) {
|
||||
Log.e("wewe", message.getConversationType() + "112121");
|
||||
MessageIMManager.get(sInstance).getSystemForRongcloud(message);
|
||||
//融云直播间聊天
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.SOCKET_WHAT_BROADCAST;
|
||||
try {
|
||||
if (!"".equals(message.getContent()) && message.getContent() != null) {
|
||||
TextMessage content = (TextMessage) message.getContent();
|
||||
if (content.getContent().contains("_method_")) {
|
||||
msg.obj = content.getContent();
|
||||
//观众页面
|
||||
if (SocketRyClient.mSocketHandler != null && (TextUtils.equals("__system__", message.getTargetId()) || ("g" + PortraitLiveManager.liveID).contains(message.getTargetId()))) {
|
||||
SocketRyClient.mSocketHandler.sendMessage(msg);
|
||||
} else if (content.getContent().contains("LivePK_anchorStartLiveNotify")) {//开播通知
|
||||
SocketReceiveBean received = JSON.parseObject(content.getContent(), SocketReceiveBean.class);
|
||||
JSONObject map = received.getMsg().getJSONObject(0);
|
||||
sendStartAnchorLive(map);
|
||||
} else if (message.getTargetId().contains("v")) {
|
||||
String contentJson = ((TextMessage) message.getContent()).getContent();
|
||||
Log.e("wewe", contentJson);
|
||||
SudGameSocketImEvent sudGameSocketImEvent = new Gson().fromJson(contentJson, SudGameSocketImEvent.class);
|
||||
Bus.get().post(sudGameSocketImEvent);
|
||||
}
|
||||
//主播页面
|
||||
if (TextUtils.isEmpty(PortraitLiveManager.liveID) && SocketRyClient.mSocketHandler != null) {
|
||||
SocketRyClient.mSocketHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
} else if (message.getConversationType() == Conversation.ConversationType.PRIVATE) {//私聊信息
|
||||
EventBus.getDefault().post(message);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendStartAnchorLive(JSONObject map) {
|
||||
AnchorStartLiveBean bean = new AnchorStartLiveBean();
|
||||
bean.setAnchorName(map.getString("anchorName"));
|
||||
bean.setRoomId(map.getString("roomid"));
|
||||
bean.setAvatar(map.getString("avatar"));
|
||||
EventBus.getDefault().post(bean);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//监听im消息
|
||||
V2TIMManager.getInstance().addSimpleMsgListener(new V2TIMSimpleMsgListener() {
|
||||
@Override
|
||||
public void onRecvGroupTextMessage(String msgID, String groupID, V2TIMGroupMemberInfo sender, String text) {
|
||||
super.onRecvGroupTextMessage(msgID, groupID, sender, text);
|
||||
Log.e("asasas", text);
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.SOCKET_WHAT_BROADCAST;
|
||||
msg.obj = text;
|
||||
if (mSocketHandler != null && Ingroup == 1) {
|
||||
mSocketHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecvC2CTextMessage(String msgID, V2TIMUserInfo sender, String text) {
|
||||
super.onRecvC2CTextMessage(msgID, sender, text);
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.SOCKET_WHAT_BROADCAST;
|
||||
msg.obj = text;
|
||||
if (mSocketHandler != null) {
|
||||
CommonAppContext.Ingroup = 1;
|
||||
mSocketHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
configSPApp();
|
||||
//初始化美颜SDK
|
||||
// FaceManager.initFaceUnity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置SharedPreferences默认值
|
||||
*/
|
||||
private void configSPApp() {
|
||||
if (!SpUtil.getInstance().isExists(MsgSettActivity.SWITCH_PRIVATE_CHAT_MSG)) {
|
||||
SpUtil.getInstance().setBooleanValue(MsgSettActivity.SWITCH_PRIVATE_CHAT_MSG, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isMainProcess() {
|
||||
int pid = android.os.Process.myPid();
|
||||
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (activityManager.getRunningAppProcesses() == null) {
|
||||
return true;
|
||||
}
|
||||
for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
|
||||
if (appProcess.pid == pid) {
|
||||
return getApplicationInfo().packageName.equals(appProcess.processName);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
RongcloudIMManager.removeRongcloudIMOnReceiveMessageListener();
|
||||
super.onTerminate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册全局异常捕获,有需要时可以在onCreate调用
|
||||
*/
|
||||
private void registerError() {
|
||||
NeverCrashUtils.getInstance().setDebugMode(BuildConfig.DEBUG).setMainCrashHandler((t, e) -> {
|
||||
Log.e("ApplicationError", "主线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息
|
||||
e.printStackTrace();
|
||||
AppManager.runDebugCode(() -> {
|
||||
//闪退后finish所有Activity并且杀死进程
|
||||
for (WeakReference<Activity> activity : activities) {
|
||||
if (activity != null && activity.get() != null) {
|
||||
activity.get().finish();
|
||||
}
|
||||
}
|
||||
Process.killProcess(Process.myPid());
|
||||
System.exit(0);
|
||||
setFirebaseCrashData();
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
throw new RuntimeException(e);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
}).setUncaughtCrashHandler((t, e) -> {
|
||||
Log.e("ApplicationError", "子线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息
|
||||
e.printStackTrace();
|
||||
}).register(this);
|
||||
}
|
||||
|
||||
public void registerFirebaseCrash() {
|
||||
if (!CommonAppConfig.IS_UPLOAD_ERROR_LOG) {
|
||||
return;
|
||||
}
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY != 2) {
|
||||
GoogleUtils.newInstance(this).initializeApp(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setFirebaseCrashData() {
|
||||
if (!CommonAppConfig.IS_UPLOAD_ERROR_LOG) {
|
||||
return;
|
||||
}
|
||||
String uid = CommonAppConfig.getInstance().getUid();
|
||||
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY != 2) {
|
||||
GoogleUtils.newInstance(sInstance).setFirebaseCrashData(
|
||||
uid,
|
||||
SpUtil.getInstance().getStringValue(SpUtil.USER_INFO),
|
||||
String.valueOf(CommonAppConfig.IS_GOOGLE_PLAY),
|
||||
Arrays.toString(Build.SUPPORTED_ABIS),
|
||||
String.valueOf(CrashSaveBean.getInstance().getStartTime()),
|
||||
String.valueOf(CrashSaveBean.getInstance().getEnterRoom()),
|
||||
String.valueOf(CrashSaveBean.getInstance().getSlidingRoom()),
|
||||
String.valueOf(CrashSaveBean.getInstance().getPlaySvga()), CrashSaveBean.getInstance().getActivitySize());
|
||||
}
|
||||
}
|
||||
}
|
||||
160
app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package com.shayu.phonelive;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.yunbao.common.BuildConfig;
|
||||
import com.yunbao.common.bean.CrashSaveBean;
|
||||
import com.yunbao.common.utils.AppManager;
|
||||
import com.yunbao.common.utils.FileUtil;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @ClassName NeverCrashUtils
|
||||
* @Description 全局捕获异常
|
||||
*/
|
||||
public class NeverCrashUtils {
|
||||
|
||||
private final static String TAG = NeverCrashUtils.class.getSimpleName();
|
||||
private final static NeverCrashUtils INSTANCE = new NeverCrashUtils();
|
||||
|
||||
private boolean debugMode;
|
||||
private MainCrashHandler mainCrashHandler;
|
||||
private UncaughtCrashHandler uncaughtCrashHandler;
|
||||
|
||||
private NeverCrashUtils() {
|
||||
}
|
||||
|
||||
public static NeverCrashUtils getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private synchronized MainCrashHandler getMainCrashHandler() {
|
||||
if (null == mainCrashHandler) {
|
||||
mainCrashHandler = (t, e) -> {
|
||||
};
|
||||
}
|
||||
return mainCrashHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主线程发生异常时的回调,可用于打印日志文件
|
||||
* <p>
|
||||
* 注意跨线程操作的可能
|
||||
*/
|
||||
public NeverCrashUtils setMainCrashHandler(MainCrashHandler mainCrashHandler) {
|
||||
this.mainCrashHandler = mainCrashHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
private synchronized UncaughtCrashHandler getUncaughtCrashHandler() {
|
||||
if (null == uncaughtCrashHandler) {
|
||||
uncaughtCrashHandler = (t, e) -> {
|
||||
};
|
||||
}
|
||||
return uncaughtCrashHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程发生异常时的回调,可用于打印日志文件
|
||||
* <p>
|
||||
* 注意跨线程操作的可能
|
||||
*/
|
||||
public NeverCrashUtils setUncaughtCrashHandler(UncaughtCrashHandler uncaughtCrashHandler) {
|
||||
this.uncaughtCrashHandler = uncaughtCrashHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isDebugMode() {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* debug模式,会打印log日志,且toast提醒发生异常,反之则都没有
|
||||
*/
|
||||
public NeverCrashUtils setDebugMode(boolean debugMode) {
|
||||
this.debugMode = debugMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成监听异常的注册
|
||||
*
|
||||
* @param application application
|
||||
*/
|
||||
private boolean errorWhile = true;
|
||||
|
||||
public void register(Application application) {
|
||||
//主线程异常拦截
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
while (errorWhile) {
|
||||
try {
|
||||
Looper.loop();
|
||||
} catch (Throwable e) {
|
||||
if (isDebugMode()) {
|
||||
Log.e(TAG, "未捕获的主线程异常行为", e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
AppContext.setFirebaseCrashData();
|
||||
AppManager.runDebugCode(() -> Toast.makeText(application, "发生闪退:" + e.getMessage(), Toast.LENGTH_SHORT).show());
|
||||
FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()), throwableToString(e), "error.log");
|
||||
getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e);
|
||||
AppManager.runDebugCode(() -> errorWhile = false);
|
||||
// return;
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
//子线程异常拦截
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||
if (isDebugMode()) {
|
||||
Log.e(TAG, "未捕获的子线程异常行为", e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
Toast.makeText(application, "发生闪退", Toast.LENGTH_SHORT).show();
|
||||
FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()),throwableToString(e),"error.log");
|
||||
getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e);
|
||||
getUncaughtCrashHandler().uncaughtException(t, e);
|
||||
|
||||
});*/
|
||||
}
|
||||
|
||||
public interface MainCrashHandler {
|
||||
void mainException(Thread t, Throwable e);
|
||||
}
|
||||
|
||||
public interface UncaughtCrashHandler {
|
||||
void uncaughtException(Thread t, Throwable e);
|
||||
}
|
||||
|
||||
private static String throwableToString(Throwable e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write("time=" + System.currentTimeMillis() + "\n");
|
||||
writer.write("AndroidVersion=" + Build.VERSION.SDK_INT + "\n");
|
||||
writer.write("AndroidName=" + Build.VERSION.RELEASE + "\n");
|
||||
writer.write("PhoneName=" + Build.BRAND + "\n");
|
||||
writer.write("Phone=" + Build.MODEL + "\n");
|
||||
writer.write("CPU=" + Arrays.toString(Build.SUPPORTED_ABIS) + "\n");
|
||||
writer.write("runTime=" + (System.currentTimeMillis() - CrashSaveBean.getInstance().getStartTime()) + "\n");
|
||||
writer.write("enterRoom=" + CrashSaveBean.getInstance().getEnterRoom() + "\n");
|
||||
writer.write("slidingRoom=" + CrashSaveBean.getInstance().getSlidingRoom() + "\n");
|
||||
writer.write("playSvga=" + CrashSaveBean.getInstance().getPlaySvga() + "\n");
|
||||
writer.write("ActivitySize=" + CrashSaveBean.getInstance().getActivitySize() + "\n");
|
||||
writer.write("UserData=" + SpUtil.getInstance().getStringValue(SpUtil.USER_INFO) + "\n");
|
||||
writer.write("[ERROR]");
|
||||
PrintWriter printWriter = new PrintWriter(writer);
|
||||
e.printStackTrace(printWriter);
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,589 @@
|
||||
package com.shayu.phonelive.activity;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.ActivityOptionsCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.shayu.phonelive.AppContext;
|
||||
import com.tencent.rtmp.ITXLivePlayListener;
|
||||
import com.tencent.rtmp.TXLiveBase;
|
||||
import com.tencent.rtmp.TXLiveConstants;
|
||||
import com.tencent.rtmp.TXLivePlayer;
|
||||
import com.tencent.rtmp.ui.TXCloudVideoView;
|
||||
import com.tencent.ugc.TXUGCBase;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.bean.AdBean;
|
||||
import com.yunbao.common.bean.ConfigBean;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.custom.CircleProgress;
|
||||
import com.yunbao.common.event.DataUserInfoEvent;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.http.CommonHttpConsts;
|
||||
import com.yunbao.common.http.CommonHttpUtil;
|
||||
import com.yunbao.common.interfaces.CommonCallback;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||
import com.yunbao.common.utils.DownloadUtil;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.LogUtil;
|
||||
import com.yunbao.common.utils.MD5Util;
|
||||
import com.yunbao.common.utils.RouteUtil;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.utils.WordUtil;
|
||||
import com.yunbao.live.views.LauncherAdViewHolder;
|
||||
import com.yunbao.main.activity.EntryActivity;
|
||||
import com.yunbao.main.activity.MainActivity;
|
||||
import com.yunbao.main.http.MainHttpConsts;
|
||||
import com.yunbao.main.http.MainHttpUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import myname.pdlive.shayu.R;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/9/17.
|
||||
*/
|
||||
@Route(path = RouteUtil.PATH_LAUNCHER)
|
||||
public class LauncherActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = "LauncherActivity";
|
||||
private static final int WHAT_GET_CONFIG = 0;
|
||||
private static final int WHAT_COUNT_DOWN = 1;
|
||||
protected Context mContext;
|
||||
private Handler mHandler;
|
||||
private ViewGroup mRoot;
|
||||
private ImageView mCover;
|
||||
private ViewGroup mContainer;
|
||||
private CircleProgress mCircleProgress;
|
||||
private List<AdBean> mAdList;
|
||||
private List<ImageView> mImageViewList;
|
||||
private int mMaxProgressVal;
|
||||
private int mCurProgressVal;
|
||||
private int mAdIndex;
|
||||
private int mInterval = 2000;
|
||||
private View mBtnSkipImage;
|
||||
private View mBtnSkipVideo;
|
||||
private TXCloudVideoView mTXCloudVideoView;
|
||||
private TXLivePlayer mPlayer;
|
||||
private LauncherAdViewHolder mLauncherAdViewHolder;
|
||||
private boolean mPaused;
|
||||
private int mVideoLastProgress;
|
||||
private boolean mForward;
|
||||
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
Resources res = super.getResources();
|
||||
Configuration config = new Configuration();
|
||||
config.setToDefaults();
|
||||
config.locale = IMLoginManager.get(this).getLocaleLanguage();
|
||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
return res;
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
|
||||
super.onCreate(savedInstanceState);
|
||||
EventBus.getDefault().register(this);
|
||||
setStatusBar();
|
||||
setContentView(R.layout.activity_launcher);
|
||||
mContext = this;
|
||||
mRoot = findViewById(R.id.root);
|
||||
mCover = findViewById(R.id.cover);
|
||||
mCircleProgress = findViewById(R.id.progress);
|
||||
mContainer = findViewById(R.id.container);
|
||||
mBtnSkipImage = findViewById(R.id.btn_skip_img);
|
||||
mBtnSkipVideo = findViewById(R.id.btn_skip_video);
|
||||
mBtnSkipImage.setOnClickListener(this);
|
||||
mBtnSkipVideo.setOnClickListener(this);
|
||||
ImgLoader.display(mContext, R.mipmap.screen, mCover);
|
||||
mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case WHAT_GET_CONFIG:
|
||||
getConfig();
|
||||
break;
|
||||
case WHAT_COUNT_DOWN:
|
||||
updateCountDown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000);
|
||||
LogUtil.uploadErrorLog(AppContext.sInstance);
|
||||
SpUtil.getInstance().setBooleanValue("NOTIFICATION", NotificationManagerCompat.from(this).areNotificationsEnabled());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 图片倒计时
|
||||
*/
|
||||
private void updateCountDown() {
|
||||
mCurProgressVal += 100;
|
||||
if (mCurProgressVal > mMaxProgressVal) {
|
||||
return;
|
||||
}
|
||||
if (mCircleProgress != null) {
|
||||
mCircleProgress.setCurProgress(mCurProgressVal);
|
||||
}
|
||||
int index = mCurProgressVal / mInterval;
|
||||
if (index < mAdList.size() && mAdIndex != index) {
|
||||
View v = mImageViewList.get(mAdIndex);
|
||||
if (v != null && v.getVisibility() == View.VISIBLE) {
|
||||
v.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
mAdIndex = mCurProgressVal / mInterval;
|
||||
}
|
||||
if (mCurProgressVal < mMaxProgressVal) {
|
||||
if (mHandler != null) {
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_COUNT_DOWN, 100);
|
||||
}
|
||||
} else if (mCurProgressVal == mMaxProgressVal) {
|
||||
checkUidAndToken();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Config信息
|
||||
*/
|
||||
private void getConfig() {
|
||||
CommonHttpUtil.getConfig(mContext, new CommonCallback<ConfigBean>() {
|
||||
@Override
|
||||
public void callback(ConfigBean bean) {
|
||||
if (bean != null) {
|
||||
L.e(TAG, "----------> getPaster360Url:" + bean.getBeautyKey() + " " + bean.getPaster360Url());
|
||||
CommonAppConfig.getInstance().setBeautySdkType(bean.getSproutType());
|
||||
//转盘开关
|
||||
CommonAppConfig.getInstance().setTurnTableEnable(bean.getTurntableEnable());
|
||||
CommonAppConfig.getInstance().setBeauty360TieZhiUrl(bean.getPaster360Url());
|
||||
CommonAppConfig.getInstance().setAnchorPkTime(bean.getPkTime());
|
||||
if (!TextUtils.isEmpty(bean.getTxVideoUgcLicenceUrl()) && !TextUtils.isEmpty(bean.getTxVideoUgcKey()))
|
||||
Log.i("tvv", bean.getTxVideoUgcLicenceUrl() + "是" + bean.getTxVideoUgcKey());
|
||||
TXLiveBase.getInstance().setLicence(LauncherActivity.this, bean.getTxVideoUgcLicenceUrl(), bean.getTxVideoUgcKey());
|
||||
TXUGCBase.getInstance().setLicence(LauncherActivity.this, bean.getTxPlayUgcLicenceUrl(), bean.getTxVideoUgcKey());
|
||||
|
||||
String adInfo = bean.getAdInfo();
|
||||
if (!TextUtils.isEmpty(adInfo)) {
|
||||
JSONObject obj = JSON.parseObject(adInfo);
|
||||
Log.i(TAG, "callback: " + adInfo);
|
||||
if (obj.getIntValue("switch") == 1) {
|
||||
List<AdBean> list = JSON.parseArray(obj.getString("list"), AdBean.class);
|
||||
if (list != null && list.size() > 0) {
|
||||
mAdList = list;
|
||||
mInterval = obj.getIntValue("time") * 1000;
|
||||
if (mContainer != null) {
|
||||
mContainer.setOnClickListener(LauncherActivity.this);
|
||||
}
|
||||
String[] uidAndToken = SpUtil.getInstance().getMultiStringValue(
|
||||
new String[]{SpUtil.UID, SpUtil.TOKEN});
|
||||
final String uid = uidAndToken[0];
|
||||
final String token = uidAndToken[1];
|
||||
if (!TextUtils.isEmpty(uid) && !TextUtils.isEmpty(token)) {
|
||||
playAD(obj.getIntValue("type") == 0);
|
||||
} else {
|
||||
releaseVideo();
|
||||
LauncherActivity.this.startActivity(new Intent(LauncherActivity.this, EntryActivity.class));
|
||||
LauncherActivity.this.finish();
|
||||
}
|
||||
} else {
|
||||
checkUidAndToken();
|
||||
}
|
||||
} else {
|
||||
checkUidAndToken();
|
||||
}
|
||||
} else {
|
||||
checkUidAndToken();
|
||||
}
|
||||
}else{
|
||||
ToastUtil.show(getString(R.string.net_error));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查uid和token是否存在
|
||||
*/
|
||||
private void checkUidAndToken() {
|
||||
if (mForward) {
|
||||
return;
|
||||
}
|
||||
mForward = true;
|
||||
if (mHandler != null) {
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
mHandler = null;
|
||||
}
|
||||
IMLoginModel model = IMLoginManager.get(this).getUserInfo();
|
||||
if (model != null) {
|
||||
IMLoginManager.get(this).upDataUserInfo();
|
||||
//融云连接服务器
|
||||
RongcloudIMManager.connectIM(this);
|
||||
forwardMainActivity();
|
||||
} else {
|
||||
//兼容老版本
|
||||
if (IMLoginManager.get(this).checkOLd()) {
|
||||
IMLoginManager.get(this).upDataUserInfo();
|
||||
} else {
|
||||
releaseVideo();
|
||||
this.startActivity(new Intent(this, EntryActivity.class));
|
||||
this.finish();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 跳转到首页
|
||||
*/
|
||||
private void forwardMainActivity() {
|
||||
releaseVideo();
|
||||
Intent intent = new Intent(
|
||||
LauncherActivity.this, MainActivity.class);
|
||||
intent.putExtra(Constants.SHOW_INVITE, false);
|
||||
|
||||
if (getIntent().getStringExtra("liveid") != null) {
|
||||
intent.putExtra("liveid", getIntent().getStringExtra("liveid"));
|
||||
}
|
||||
if (getIntent().getStringExtra("type") != null) {
|
||||
intent.putExtra("type", getIntent().getStringExtra("type"));
|
||||
}
|
||||
|
||||
if (getIntent().getStringExtra("activityUrl") != null) {
|
||||
intent.putExtra("activityUrl", getIntent().getStringExtra("activityUrl"));
|
||||
}
|
||||
if (mImageViewList != null && mImageViewList.size() > 0) {
|
||||
Log.i(TAG, "forwardMainActivity: " + mImageViewList.size());
|
||||
AdBean bean = mAdList.get(0);
|
||||
if (bean != null && bean.getAnimation() == 1) {
|
||||
intent.putExtra("ad_url", mAdList.get(0).getUrl());
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(LauncherActivity.this, mImageViewList.get(0), "ad_img_0").toBundle();
|
||||
LauncherActivity.this.startActivity(intent, bundle);
|
||||
} else {
|
||||
LauncherActivity.this.startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
LauncherActivity.this.startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
if (mHandler != null) {
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
mHandler = null;
|
||||
}
|
||||
MainHttpUtil.cancel(MainHttpConsts.GET_BASE_INFO);
|
||||
CommonHttpUtil.cancel(CommonHttpConsts.GET_CONFIG);
|
||||
releaseVideo();
|
||||
if (mLauncherAdViewHolder != null) {
|
||||
mLauncherAdViewHolder.release();
|
||||
}
|
||||
mLauncherAdViewHolder = null;
|
||||
super.onDestroy();
|
||||
L.e(TAG, "----------> onDestroy");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置透明状态栏
|
||||
*/
|
||||
private void setStatusBar() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window window = getWindow();
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int i = v.getId();
|
||||
if (i == R.id.btn_skip_img || i == R.id.btn_skip_video) {
|
||||
if (mBtnSkipImage != null) {
|
||||
mBtnSkipImage.setClickable(false);
|
||||
}
|
||||
if (mBtnSkipVideo != null) {
|
||||
mBtnSkipVideo.setClickable(false);
|
||||
}
|
||||
checkUidAndToken();
|
||||
} else if (i == R.id.container) {
|
||||
clickAD();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击广告
|
||||
*/
|
||||
private void clickAD() {
|
||||
if (mAdList != null && mAdList.size() > mAdIndex) {
|
||||
AdBean adBean = mAdList.get(mAdIndex);
|
||||
if (adBean != null) {
|
||||
String link = adBean.getLink();
|
||||
if (!TextUtils.isEmpty(link)) {
|
||||
if (mHandler != null) {
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
if (mContainer != null) {
|
||||
mContainer.setClickable(false);
|
||||
}
|
||||
releaseVideo();
|
||||
if (mLauncherAdViewHolder == null) {
|
||||
mLauncherAdViewHolder = new LauncherAdViewHolder(mContext, mRoot, link + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken());
|
||||
mLauncherAdViewHolder.addToParent();
|
||||
mLauncherAdViewHolder.loadData();
|
||||
mLauncherAdViewHolder.show();
|
||||
mLauncherAdViewHolder.setActionListener(new LauncherAdViewHolder.ActionListener() {
|
||||
@Override
|
||||
public void onHideClick() {
|
||||
checkUidAndToken();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseVideo() {
|
||||
if (mPlayer != null) {
|
||||
mPlayer.stopPlay(false);
|
||||
mPlayer.setPlayListener(null);
|
||||
}
|
||||
mPlayer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mLauncherAdViewHolder != null) {
|
||||
mLauncherAdViewHolder.release();
|
||||
checkUidAndToken();
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放广告
|
||||
*/
|
||||
private void playAD(boolean isImage) {
|
||||
if (mContainer == null) {
|
||||
return;
|
||||
}
|
||||
if (isImage) {
|
||||
int imgSize = mAdList.size();
|
||||
if (imgSize > 0) {
|
||||
mImageViewList = new ArrayList<>();
|
||||
for (int i = 0; i < imgSize; i++) {
|
||||
ImageView imageView = new ImageView(mContext);
|
||||
imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
imageView.setBackgroundColor(0xffffffff);
|
||||
imageView.setTransitionName("ad_img_" + i);
|
||||
mImageViewList.add(imageView);
|
||||
ImgLoader.display(mContext, mAdList.get(i).getUrl(), imageView);
|
||||
}
|
||||
for (int i = imgSize - 1; i >= 0; i--) {
|
||||
mContainer.addView(mImageViewList.get(i));
|
||||
}
|
||||
if (mBtnSkipImage != null && mBtnSkipImage.getVisibility() != View.VISIBLE) {
|
||||
mBtnSkipImage.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mMaxProgressVal = imgSize * mInterval;
|
||||
if (mCircleProgress != null) {
|
||||
mCircleProgress.setMaxProgress(mMaxProgressVal);
|
||||
}
|
||||
if (mHandler != null) {
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_COUNT_DOWN, 100);
|
||||
}
|
||||
if (mCover != null && mCover.getVisibility() == View.VISIBLE) {
|
||||
mCover.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
} else {
|
||||
checkUidAndToken();
|
||||
}
|
||||
} else {
|
||||
if (mAdList == null || mAdList.size() == 0) {
|
||||
checkUidAndToken();
|
||||
return;
|
||||
}
|
||||
String videoUrl = mAdList.get(0).getUrl();
|
||||
if (TextUtils.isEmpty(videoUrl)) {
|
||||
checkUidAndToken();
|
||||
return;
|
||||
}
|
||||
String videoFileName = MD5Util.getMD5(videoUrl);
|
||||
if (TextUtils.isEmpty(videoFileName)) {
|
||||
checkUidAndToken();
|
||||
return;
|
||||
}
|
||||
File file = new File(getCacheDir(), videoFileName);
|
||||
if (file.exists()) {
|
||||
playAdVideo(file);
|
||||
} else {
|
||||
downloadAdFile(videoUrl, videoFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
mPaused = true;
|
||||
if (mPlayer != null && mPlayer.isPlaying()) {
|
||||
mPlayer.setMute(true);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mPaused) {
|
||||
if (mPlayer != null && mPlayer.isPlaying()) {
|
||||
mPlayer.setMute(false);
|
||||
}
|
||||
}
|
||||
mPaused = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载视频
|
||||
*/
|
||||
private void downloadAdFile(String url, String fileName) {
|
||||
DownloadUtil downloadUtil = new DownloadUtil();
|
||||
downloadUtil.download("ad_video", getCacheDir(), fileName, url, new DownloadUtil.Callback() {
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
playAdVideo(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
checkUidAndToken();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 播放视频
|
||||
*/
|
||||
private void playAdVideo(File videoFile) {
|
||||
if (mBtnSkipVideo != null && mBtnSkipVideo.getVisibility() != View.VISIBLE) {
|
||||
mBtnSkipVideo.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mTXCloudVideoView = new TXCloudVideoView(mContext);
|
||||
mTXCloudVideoView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
mTXCloudVideoView.setRenderMode(TXLiveConstants.RENDER_MODE_FULL_FILL_SCREEN);
|
||||
mContainer.addView(mTXCloudVideoView);
|
||||
mPlayer = new TXLivePlayer(mContext);
|
||||
mPlayer.setPlayerView(mTXCloudVideoView);
|
||||
mPlayer.setAutoPlay(true);
|
||||
mPlayer.setPlayListener(new ITXLivePlayListener() {
|
||||
@Override
|
||||
public void onPlayEvent(int e, Bundle bundle) {
|
||||
if (e == TXLiveConstants.PLAY_EVT_PLAY_END) {//获取到视频播放完毕的回调
|
||||
checkUidAndToken();
|
||||
L.e(TAG, "视频播放结束------>");
|
||||
} else if (e == TXLiveConstants.PLAY_EVT_CHANGE_RESOLUTION) {////获取到视频宽高回调
|
||||
float videoWidth = bundle.getInt("EVT_PARAM1", 0);
|
||||
float videoHeight = bundle.getInt("EVT_PARAM2", 0);
|
||||
if (mTXCloudVideoView != null && videoWidth > 0 && videoHeight > 0) {
|
||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mTXCloudVideoView.getLayoutParams();
|
||||
int targetH = 0;
|
||||
if (videoWidth >= videoHeight) {//横屏
|
||||
params.gravity = Gravity.CENTER_VERTICAL;
|
||||
targetH = (int) (mTXCloudVideoView.getWidth() / videoWidth * videoHeight);
|
||||
} else {
|
||||
targetH = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
}
|
||||
if (targetH != params.height) {
|
||||
params.height = targetH;
|
||||
mTXCloudVideoView.requestLayout();
|
||||
}
|
||||
}
|
||||
} else if (e == TXLiveConstants.PLAY_EVT_RCV_FIRST_I_FRAME) {
|
||||
if (mCover != null && mCover.getVisibility() == View.VISIBLE) {
|
||||
mCover.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
} else if (e == TXLiveConstants.PLAY_ERR_NET_DISCONNECT ||
|
||||
e == TXLiveConstants.PLAY_ERR_FILE_NOT_FOUND) {
|
||||
ToastUtil.show(mContext.getString(R.string.live_play_error));
|
||||
checkUidAndToken();
|
||||
} else if (e == TXLiveConstants.PLAY_EVT_PLAY_PROGRESS) {
|
||||
int progress = bundle.getInt("EVT_PLAY_PROGRESS_MS");
|
||||
if (mVideoLastProgress == progress) {
|
||||
L.e(TAG, "视频播放结束------>");
|
||||
checkUidAndToken();
|
||||
} else {
|
||||
mVideoLastProgress = progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetStatus(Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
mPlayer.startPlay(videoFile.getAbsolutePath(), TXLivePlayer.PLAY_TYPE_LOCAL_VIDEO);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onDataUserInfoEvent(DataUserInfoEvent event) {
|
||||
if (event.isUpDataSuccess()) {
|
||||
//融云连接服务器
|
||||
RongcloudIMManager.connectIM(getApplication());
|
||||
forwardMainActivity();
|
||||
} else {
|
||||
releaseVideo();
|
||||
this.startActivity(new Intent(this, EntryActivity.class));
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
package com.shayu.phonelive.utils;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.makeramen.roundedimageview.RoundedImageView;
|
||||
import com.shayu.phonelive.AppContext;
|
||||
import com.shayu.phonelive.activity.LauncherActivity;
|
||||
import com.yunbao.common.bean.NotificationMsgBean;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.utils.DialogUitl;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.common.utils.WordUtil;
|
||||
import com.yunbao.main.activity.MainActivity;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import io.rong.imlib.ConnectChangeReceiver;
|
||||
import io.rong.push.PushType;
|
||||
import io.rong.push.notification.PushMessageReceiver;
|
||||
import io.rong.push.notification.PushNotificationMessage;
|
||||
import myname.pdlive.shayu.R;
|
||||
|
||||
public class CustomMessageReceiver extends PushMessageReceiver {
|
||||
|
||||
|
||||
private String createNotificationChannel(Context context, String channelID, String channelNAME, int level) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = new NotificationChannel(channelID, channelNAME, level);
|
||||
channel.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/raw/pdlive_sound"), null);
|
||||
manager.createNotificationChannel(channel);
|
||||
return channelID;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNotificationMessageClicked(
|
||||
Context context, PushType pushType, PushNotificationMessage message) {
|
||||
if (pushType.equals(PushType.GOOGLE_FCM)) {
|
||||
|
||||
Log.i("gmc", "gmc");
|
||||
|
||||
// TODO
|
||||
} else {
|
||||
Log.i("gmc", "gmc1111");
|
||||
}
|
||||
// 返回 true 表示拦截,false 为不拦截
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
NotificationMsgBean msg = new NotificationMsgBean();
|
||||
|
||||
@Override
|
||||
public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage notificationMessage) {
|
||||
Log.i("gmc", notificationMessage.getPushContent() + "VVV" + notificationMessage.getPushTitle() + "gmc11112222" + notificationMessage.getExtra());
|
||||
if (!SpUtil.getInstance().getBooleanValue("NOTIFICATION")) {
|
||||
if (AppContext.activityWeakReference != null) {
|
||||
Activity activity = AppContext.activityWeakReference.get();
|
||||
if (activity != null) {
|
||||
DialogUitl.showSimpleDialog(activity, WordUtil.isNewZh()?"应用需要通知权限":"Application requires notification permission", new DialogUitl.SimpleCallback() {
|
||||
@Override
|
||||
public void onConfirmClick(Dialog dialog, String content) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
|
||||
intent.putExtra("app_package", context.getPackageName());
|
||||
intent.putExtra("app_uid", context.getApplicationInfo().uid);
|
||||
// for Android 8 and above
|
||||
intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
|
||||
activity.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (notificationMessage.getExtra() == null) {
|
||||
msg.setImg("" + notificationMessage.getSenderPortrait());
|
||||
msg.setTitle(notificationMessage.getPushTitle());
|
||||
msg.setContent(notificationMessage.getPushContent());
|
||||
msg.setType("-1");
|
||||
sendNotification(context, msg);
|
||||
} else {
|
||||
try {
|
||||
JSONObject obj = new JSONObject(notificationMessage.getExtra());
|
||||
Log.i("gmc", "1111222");
|
||||
//开播
|
||||
if (obj.getString("type").equals("1") || obj.getString("type").equals("9")) {
|
||||
Log.i("gmc", "1111");
|
||||
msg.setImg("" + obj.getString("avatar"));
|
||||
msg.setTitle(notificationMessage.getPushTitle());
|
||||
msg.setContent(notificationMessage.getPushContent());
|
||||
msg.setLiveuid(obj.getString("liveuid"));
|
||||
msg.setType("1");
|
||||
liveNotification(context, msg);
|
||||
//发布动态 2
|
||||
//点赞 3
|
||||
//评论 4
|
||||
//鼓励 5
|
||||
} else if (obj.getString("type").equals("2") || obj.getString("type").equals("3") || obj.getString("type").equals("4") || obj.getString("type").equals("5")) {
|
||||
msg.setImg("" + obj.getString("avatar"));
|
||||
msg.setTitle(notificationMessage.getPushTitle());
|
||||
msg.setContent(notificationMessage.getPushContent());
|
||||
msg.setType("2");
|
||||
dynamicNotification(context, msg);
|
||||
} else if (obj.getString("type").equals("8") || obj.getString("type").equals("7")) {
|
||||
msg.setImg("" + obj.getString("avatar"));
|
||||
msg.setTitle(notificationMessage.getPushTitle());
|
||||
msg.setContent(notificationMessage.getPushContent());
|
||||
msg.setType(obj.getString("type"));
|
||||
msg.setActivityurl(obj.getString("activityUrl"));
|
||||
serviceNotification(context, msg);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.i("gmc", "1111" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Bitmap makeRoundCorner(Bitmap bitmap, float roundPx) {
|
||||
try {
|
||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
|
||||
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
final int color = 0xff424242;// 颜色值(0xff---alpha)
|
||||
final Paint paint = new Paint();
|
||||
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
final RectF rectF = new RectF(rect);// Rect是使用int类型作为数值,RectF是使用float类型作为数值
|
||||
// --------抗锯齿-------//
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
paint.setColor(color);
|
||||
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
final Rect src = new Rect(0, 0, bitmap.getWidth(),
|
||||
bitmap.getHeight());
|
||||
canvas.drawBitmap(bitmap, null, rect, paint);
|
||||
return output;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//私聊
|
||||
private void sendNotification(Context context, NotificationMsgBean message) {
|
||||
// 设置通知的点击行为:这里启动一个 Activity
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
} else {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
}
|
||||
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
|
||||
// 构建 remoteView
|
||||
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
|
||||
remoteView.setTextViewText(R.id.title, message.getTitle());
|
||||
remoteView.setTextViewText(R.id.content, message.getContent());
|
||||
Glide.with(context).asBitmap().load(message.getImg()).into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
remoteView.setImageViewBitmap(R.id.img, makeRoundCorner(resource, 50));
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
|
||||
// 设置自定义 RemoteViews
|
||||
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
|
||||
// 设置通知的优先级(悬浮通知)
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
builder.setAutoCancel(true);
|
||||
Notification notification = builder.build();
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
manager.notify(0, notification);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
int id = 1;
|
||||
|
||||
//动态
|
||||
private void dynamicNotification(Context context, NotificationMsgBean message) {
|
||||
// 设置通知的点击行为:这里启动一个 Activity
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.putExtra("type", "2");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
} else {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
|
||||
// 构建 remoteView
|
||||
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
|
||||
remoteView.setTextViewText(R.id.title, message.getTitle());
|
||||
remoteView.setTextViewText(R.id.content, message.getContent());
|
||||
remoteView.setImageViewResource(R.id.img, R.mipmap.ic_launcher);
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
|
||||
// 设置自定义 RemoteViews
|
||||
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
|
||||
// 设置通知的优先级(悬浮通知)
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
builder.setAutoCancel(true);
|
||||
Notification notification = builder.build();
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
id = (int) (id + System.currentTimeMillis());
|
||||
manager.notify(id, notification);
|
||||
|
||||
}
|
||||
|
||||
//开播
|
||||
private void liveNotification(Context context, NotificationMsgBean message) {
|
||||
// 设置通知的点击行为:这里启动一个 Activity
|
||||
Intent intent = new Intent(context, LauncherActivity.class);
|
||||
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.putExtra("liveid", message.getLiveuid());
|
||||
Log.e("gmc", message.getLiveuid() + "21121");
|
||||
PendingIntent pendingIntent;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
} else {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
|
||||
// 构建 remoteView
|
||||
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
|
||||
remoteView.setTextViewText(R.id.title, message.getTitle());
|
||||
remoteView.setTextViewText(R.id.content, message.getContent());
|
||||
Glide.with(context).asBitmap().load(message.getImg()).into(new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
remoteView.setImageViewBitmap(R.id.img, makeRoundCorner(resource, 50));
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
|
||||
// 设置自定义 RemoteViews
|
||||
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
|
||||
// 设置通知的优先级(悬浮通知)
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
builder.setAutoCancel(true);
|
||||
Notification notification = builder.build();
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
id = (int) (id + System.currentTimeMillis());
|
||||
manager.notify(id, notification);
|
||||
}
|
||||
});
|
||||
|
||||
Log.i("gmc", "11123231");
|
||||
|
||||
}
|
||||
|
||||
//后台
|
||||
private void serviceNotification(Context context, NotificationMsgBean message) {
|
||||
// 设置通知的点击行为:这里启动一个 Activity
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.putExtra("type", message.getType());
|
||||
if (message.getType().equals("8")) {
|
||||
intent.putExtra("activityUrl", message.getActivityurl());
|
||||
}
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
} else {
|
||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
|
||||
// 构建 remoteView
|
||||
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
|
||||
remoteView.setTextViewText(R.id.title, message.getTitle());
|
||||
remoteView.setTextViewText(R.id.content, message.getContent());
|
||||
remoteView.setImageViewResource(R.id.img, R.mipmap.ic_launcher);
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
|
||||
// 设置自定义 RemoteViews
|
||||
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
|
||||
// 设置通知的优先级(悬浮通知)
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
builder.setAutoCancel(true);
|
||||
Notification notification = builder.build();
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
id = (int) (id + System.currentTimeMillis());
|
||||
manager.notify(id, notification);
|
||||
|
||||
}
|
||||
}
|
||||
90
app/src/main/java/com/shayu/phonelive/utils/LogUtils.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package com.shayu.phonelive.utils;
|
||||
|
||||
import static java.text.DateFormat.DEFAULT;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LogUtils {
|
||||
/**
|
||||
* 采集所有日志
|
||||
*/
|
||||
public static void start(Context context) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
String[] exec = new String[]{"logcat", "-c"};
|
||||
Runtime.getRuntime().exec(exec).waitFor();
|
||||
|
||||
exec = new String[]{"logcat", "-v", "color", "UTC-8"};
|
||||
|
||||
Process process = Runtime.getRuntime().exec(exec);
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
PrintWriter writer = null;
|
||||
String title = "[PDLIVE]" + CommonAppConfig.getInstance().getUid() + "_";
|
||||
String today = title + SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
|
||||
File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator);
|
||||
if (dir.listFiles() != null) {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.getName().endsWith(".log") && !"error.log".equals(file.getName())) {
|
||||
String fileName = file.getName().replace(".log", "").split("_")[1];
|
||||
if (isDelLog(fileName)) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
|
||||
FileOutputStream os = new FileOutputStream(saveFile, true);
|
||||
writer = new PrintWriter(os);
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
writer.append(line).write("\n");
|
||||
writer.flush();
|
||||
}
|
||||
writer.flush();
|
||||
writer.close();
|
||||
exec = new String[]{"logcat", "-c"};
|
||||
Runtime.getRuntime().exec(exec).waitFor();
|
||||
bufferedReader.close();
|
||||
start(context);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是要删除的日志
|
||||
**/
|
||||
private static boolean isDelLog(String time) {
|
||||
try {
|
||||
Calendar timeCal = Calendar.getInstance(Locale.CHINA);
|
||||
timeCal.setTime(Objects.requireNonNull(SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).parse(time)));
|
||||
Calendar calendar = Calendar.getInstance(Locale.CHINA);
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.DATE, -3);
|
||||
return calendar.after(timeCal);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
package com.shayu.phonelive.utils;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.google.android.gms.common.internal.zzm;
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.main.activity.MainActivity;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import myname.pdlive.shayu.R;
|
||||
|
||||
public class MyNotificationService extends FirebaseMessagingService {
|
||||
|
||||
private String createNotificationChannel(String channelID, String channelNAME, int level) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = new NotificationChannel(channelID, channelNAME, level);
|
||||
manager.createNotificationChannel(channel);
|
||||
return channelID;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void onMessageReceived(RemoteMessage message) {
|
||||
// do nothing
|
||||
Map<String, String> params = message.getData();
|
||||
JSONObject object = new JSONObject(params);
|
||||
Log.e("JSON_OBJECT", object.toString());
|
||||
JSONObject remoteMessage = null;
|
||||
try {
|
||||
remoteMessage = new JSONObject(object.getString("message"));
|
||||
Log.e("gmc","remoteMessage1"+remoteMessage.toString());
|
||||
Log.e("gmc","remoteMessage"+remoteMessage.getString("fromUserName"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// if(remoteMessage!=null && remoteMessage.isNull("fcm_token")) {
|
||||
// String title = remoteMessage.getData().get("title");
|
||||
// String message = remoteMessage.getData().get("text");
|
||||
// String username = remoteMessage.getData().get("username");
|
||||
// String uid = remoteMessage.getData().get("uid");
|
||||
// String fcmToken = remoteMessage.getData().get("fcm_token");
|
||||
// Log.e("gmc","remoteMessage"+remoteMessage.getData().get("username"));
|
||||
//
|
||||
// //Muestro la notifiación
|
||||
//// sendNotification(title, message, username, uid, fcmToken);
|
||||
// }else {
|
||||
// /// Si es de tipo inserción la muestro sino no.
|
||||
// //Es una nueva notificación de que alguien ha creado algo
|
||||
// if(remoteMessage.getData().get("accion")!=null &&
|
||||
// remoteMessage.getData().get("accion").compareTo("insert")==0)
|
||||
//// displayNotification(remoteMessage.getNotification(), remoteMessage.getData());
|
||||
//// //Envío los datos al RecyclerView correspondiente para que se actualice
|
||||
//// addNotificacion(remoteMessage);
|
||||
// Log.e("gmc","remoteMessage"+remoteMessage.getData().get("username"));
|
||||
//
|
||||
// }
|
||||
|
||||
// sendNotification("remoteMessage");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// private void sendNotification(String messageBody) {
|
||||
//
|
||||
// // 设置通知的点击行为:这里启动一个 Activity
|
||||
// Intent intent = new Intent(this, MainActivity.class);
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
// String channelId = createNotificationChannel("my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
|
||||
// // 构建 remoteView
|
||||
//// RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.notification_message);
|
||||
//
|
||||
//// remoteView.setTextViewText(R.id.tvMsg, "RemoteViews");
|
||||
//// remoteView.setImageViewResource(R.id.ivIcon, R.mipmap.ic_launcher_round);
|
||||
// NotificationCompat.Builder builder = new NotificationCompat.Builder(this,channelId);
|
||||
// // 设置自定义 RemoteViews
|
||||
// builder.setContent(remoteView).setSmallIcon(R.mipmap.ic_launcher);
|
||||
// // 设置通知的优先级(悬浮通知)
|
||||
// builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||
// builder.setContentIntent(pendingIntent);
|
||||
// builder.setAutoCancel(true);
|
||||
// Notification notification = builder.build();
|
||||
// NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
// manager.notify(0, notification);
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
*/
|
||||
4
app/src/main/res/drawable/bg_launcher_skip.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#80000000"/>
|
||||
</shape>
|
||||
6
app/src/main/res/drawable/bg_launcher_skip_2.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="12sp"/>
|
||||
<stroke android:color="@color/white" android:width="1dp"/>
|
||||
<solid android:color="#80000000"/>
|
||||
</shape>
|
||||
BIN
app/src/main/res/drawable/no_banner.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
app/src/main/res/drawable/small_icons.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
64
app/src/main/res/layout/activity_launcher.xml
Normal file
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#000" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/btn_skip_img"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginTop="37dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:background="@drawable/bg_launcher_skip"
|
||||
android:visibility="invisible">
|
||||
|
||||
<com.yunbao.common.custom.CircleProgress
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:cp_bg_color="@color/white"
|
||||
app:cp_cur_progress="0"
|
||||
app:cp_fg_color="#ff7200"
|
||||
app:cp_stroke_width="2dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="@string/recommend_skip"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="11sp" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_skip_video"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="26dp"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginTop="37dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:background="@drawable/bg_launcher_skip_2"
|
||||
android:gravity="center"
|
||||
android:text="@string/recommend_skip"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="11sp"
|
||||
android:visibility="invisible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cover"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:scaleType="centerCrop" />
|
||||
</FrameLayout>
|
||||
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/screen.png
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
app/src/main/res/raw/pdlive_sound.mp3
Normal file
5
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">PandoraLive</string>
|
||||
<string name="leak_canary_test_class_name">assertk.Assert</string>
|
||||
</resources>
|
||||