接入Bugly在线更新SDK

This commit is contained in:
oujunhui
2020-08-04 20:39:21 +08:00
parent 4377b2c014
commit f75cb3739d
10 changed files with 325 additions and 24 deletions

View File

@@ -193,7 +193,7 @@ def supportLibraryVersion = "27.1.1"
def Lombok = "1.16.20"
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
api fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
@@ -217,7 +217,6 @@ dependencies {
api "com.darsh.multipleimageselect:multipleimageselect:1.0.4"
api "me.shaohui.advancedluban:library:1.3.5"
api "com.tencent.bugly:crashreport:2.8.6"
api "pl.droidsonroids.gif:android-gif-drawable:1.2.7"
// api "com.jude:rollviewpager:1.4.6"
implementation 'com.github.dongxingrong:RollViewPager:V1.0'

View File

@@ -125,6 +125,18 @@
android:name="android.max_aspect"
android:value="2.4" /> <!-- 刘海屏适配 end -->
<provider
android:name=".utils.BuglyFileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="name,authorities,exported,grantUriPermissions">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"
tools:replace="name,resource"/>
</provider>
<!-- 云信配置 begin ##################################################### -->
<!--
@@ -199,6 +211,7 @@
<service android:name="com.netease.nimlib.service.ResponseService" />
<!-- 云信集成小米推送 start -->
<!-- 配置的service和receiver -->
<provider
@@ -363,6 +376,12 @@
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:theme="@android:style/Theme.Translucent" />
<activity
android:name="com.alipay.sdk.auth.AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"

View File

@@ -49,10 +49,13 @@ import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.crashreport.CrashReport;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.yizhuan.erban.BuildConfig;
import com.yizhuan.erban.MainActivity;
import com.yizhuan.erban.MiddleActivity;
import com.yizhuan.erban.NimMiddleActivity;
import com.yizhuan.erban.R;
@@ -124,7 +127,7 @@ import static com.yizhuan.xchat_android_constants.XChatConstants.XM_APP_ID;
import static com.yizhuan.xchat_android_constants.XChatConstants.XM_APP_KEY;
import static com.yizhuan.xchat_android_constants.XChatConstants.XM_CERTIFICATE_NAME;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION;
//import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION;
/**
* @author chenran
@@ -196,8 +199,7 @@ public class XChatApplication extends Application {
LogUtils.d(channel + "");
initEnv(channel);
// 注册自定义推送消息处理,这个是可选项
NIMPushClient.registerMixPushMessageHandler(new PushMessageHandler());
//延迟初始化云信
NIMClient.init(this, null, options());
@@ -211,7 +213,8 @@ public class XChatApplication extends Application {
if (inMainProcess(this)) {
// 注册自定义推送消息处理,这个是可选项
NIMPushClient.registerMixPushMessageHandler(new PushMessageHandler());
RxJavaPlugins.setErrorHandler(throwable -> {
throwable.printStackTrace();
// print it
@@ -231,11 +234,14 @@ public class XChatApplication extends Application {
CrashReport.setAppChannel(this, channel);
}
if (!isDebug()) {
CrashReport.initCrashReport(this.getApplicationContext(), XChatConstants.BUGLY_KEY_RELEASE, false);
} else {
CrashReport.initCrashReport(this.getApplicationContext(), XChatConstants.BUGLY_KEY_DEBUG, true);
initBuglyUpdate();
Bugly.init(this, BuildConfig.DEBUG ? XChatConstants.BUGLY_KEY_DEBUG : XChatConstants.BUGLY_KEY_RELEASE, BuildConfig.DEBUG);
if (!TextUtils.isEmpty(channel)) {
Bugly.setAppChannel(this, channel);
}
//生命周期监听
if (lifeManager == null) {
lifeManager = new ActivityLifeManager();
@@ -339,6 +345,7 @@ public class XChatApplication extends Application {
SDKOptions options = new SDKOptions();
options.disableAwake = true;
options.asyncInitSDK = true;
// options.customPushContentType = "";
if (isDebug()) {
options.checkManifestConfig = true;
}
@@ -416,9 +423,9 @@ public class XChatApplication extends Application {
} else if (customAttachment instanceof OpenSignInAttachment) {
return getContentFromOpenSignIn(customAttachment);
}
else if (customAttachment.getFirst() == CUSTOM_MSG_PUSH_NOTIFIFICATION){
return getContentRoomInvite(customAttachment);
}
// else if (customAttachment.getFirst() == CUSTOM_MSG_PUSH_NOTIFIFICATION){
// return getContentRoomInvite(customAttachment);
// }
}
// 采用SDK默认文案
return "收到一条消息";
@@ -428,12 +435,15 @@ public class XChatApplication extends Application {
public String makeTicker(String nick, IMMessage message) {
if (message.getMsgType() == MsgTypeEnum.custom) {
CustomAttachment customAttachment = (CustomAttachment) message.getAttachment();
if (customAttachment != null){
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
return message.getFromNick();
} else if (customAttachment instanceof OpenSignInAttachment) {
return getContentFromOpenSignIn(customAttachment);
} else if (customAttachment instanceof RoomInviteFansAttachment){
return getContentRoomInvite(customAttachment);
}
// else if (customAttachment instanceof RoomInviteFansAttachment){
// return getContentRoomInvite(customAttachment);
// }
}
}
// 采用SDK默认文案
@@ -459,7 +469,7 @@ public class XChatApplication extends Application {
if (attachment instanceof RoomInviteFansAttachment) {
RoomInviteFansInfo roomInviteFansInfo = ((RoomInviteFansAttachment) attachment).getRoomInviteFansInfo();
if (roomInviteFansInfo != null) {
result = roomInviteFansInfo.getPushTitle();
result = roomInviteFansInfo.getData().getData().getContent();
}
}
if (TextUtils.isEmpty(result)) {
@@ -486,6 +496,115 @@ public class XChatApplication extends Application {
return packageName.equals(processName);
}
/**
* 初始化bugly版本升级
*/
private void initBuglyUpdate() {
/***** Beta高级设置 *****/
/**
* true表示app启动自动初始化升级模块;
* false不会自动初始化;
* 开发者如果担心sdk初始化影响app启动速度可以设置为false
* 在后面某个时刻手动调用Beta.init(getApplicationContext(),false);
*/
// Beta.autoInit = true;
/**
* true表示初始化时自动检查升级;
* false表示不会自动检查升级,需要手动调用Beta.checkUpgrade()方法;
*/
// Beta.autoCheckUpgrade = true;
/**
* 设置升级检查周期为60s(默认检查周期为0s)60s内SDK不重复向后台请求策略);
*/
// Beta.upgradeCheckPeriod = 60 * 1000;
/**
* 设置启动延时为1s默认延时3sAPP启动1s后初始化SDK避免影响APP启动速度;
*/
Beta.initDelay = 5 * 1000;
/**
* 设置sd卡的Download为更新资源保存目录;
* 后续更新资源会保存在此目录需要在manifest中添加WRITE_EXTERNAL_STORAGE权限;
*/
// Beta.storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
/**
* 点击过确认的弹窗在APP下次启动自动检查更新时会再次显示;
*/
Beta.showInterruptedStrategy = true;
/**
* 只允许在MainActivity上显示更新弹窗其他activity上不显示弹窗;
* 不设置会默认所有activity都可以显示弹窗;
*/
Beta.canShowUpgradeActs.add(MainActivity.class);
/**
* 自定义布局
*/
Beta.upgradeDialogLayoutId = R.layout.upgrade_dialog;//关键代码写这个布局添加自己想要的
/**
* 设置自定义tip弹窗UI布局
* 注意因为要保持接口统一需要用户在指定控件按照以下方式设置tag否则会影响您的正常使用
* 标题beta_titleandroid:tag="beta_title"
* 提示信息beta_tip_message 如: android:tag="beta_tip_message"
* 取消按钮beta_cancel_button 如android:tag="beta_cancel_button"
* 确定按钮beta_confirm_button 如android:tag="beta_confirm_button"
* 详见layout/tips_dialog.xml
*/
//Beta.tipsDialogLayoutId = R.layout.tips_dialog;
// Beta.upgradeDialogLifecycleListener = new UILifecycleListener<UpgradeInfo>() {
// @Override
// public void onCreate(Context context, View view, UpgradeInfo upgradeInfo) {
//
// // 通过tag方式获取控件并更改布局内容
// TextView textView = (TextView) view.findViewWithTag("beta_upgrade_feature");
// // 更多的操作:比如设置控件的点击事件
// textView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
// }
// });
// }
//
// @Override
// public void onStart(Context context, View view, UpgradeInfo upgradeInfo) {
//
// }
//
// @Override
// public void onResume(Context context, View view, UpgradeInfo upgradeInfo) {
//
// // 注可通过这个回调方式获取布局的控件如果设置了id可通过findViewById方式获取如果设置了tag可以通过findViewWithTag具体参考下面例子:
//
//
// }
//
// @Override
// public void onPause(Context context, View view, UpgradeInfo upgradeInfo) {
//
// }
//
// @Override
// public void onStop(Context context, View view, UpgradeInfo upgradeInfo) {
//
// }
//
// @Override
// public void onDestroy(Context context, View view, UpgradeInfo upgradeInfo) {
//
//// ToastUtils.showGravityToast(MyApplication.this,"更新后注意通知栏下载进度...");
// }
//
// };
}
/**
* 获取当前进程名
*

View File

@@ -12,6 +12,7 @@ import android.text.TextUtils;
import android.view.View;
import com.netease.nim.uikit.StatusBarUtil;
import com.tencent.bugly.beta.Beta;
import com.tongdaxing.erban.upgrade.AppUpgradeHelper;
import com.trello.rxlifecycle3.android.ActivityEvent;
import com.yizhuan.erban.R;
@@ -174,8 +175,8 @@ public class SettingActivity extends BaseActivity implements View.OnClickListene
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
break;
case R.id.rly_check://检查更新
AppUpgradeHelper.checkAppUpgrade(this, true);
// AppUpgradeHelper.checkAppUpgrade(this, true);
Beta.checkUpgrade();
break;
case R.id.rly_lab:
startActivity(new Intent(getApplicationContext(), LabActivity.class));

View File

@@ -0,0 +1,152 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent_ban"
android:clipChildren="false"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialog_background"
android:gravity="center"
android:orientation="vertical"
>
<!-- 通过id设置的控件 -->
<!--<ImageView-->
<!--android:id="@+id/imageview"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:src="@mipmap/ic_launcher" />-->
<!--&lt;!&ndash;通过tag设置的控件 &ndash;&gt;-->
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:tag="textview"-->
<!--android:text="customText" />-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-35dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="beta_upgrade_banner"
android:scaleType="centerCrop"
android:src="@drawable/update_banner"/>
<!-- 【必设】升级标题控件tagbeta_title-->
<TextView
android:layout_width="wrap_content"
android:layout_height="42dp"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="10dp"
android:tag="beta_title"
android:text="title"
android:visibility="gone"
android:layout_gravity="center"
android:textColor="#273238"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发现新版本"
android:textColor="#ff795eef"
android:textSize="16sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:layout_marginTop="70dp"
/>
</FrameLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24.5dp"
android:paddingEnd="24.5dp"
android:paddingTop="@dimen/dp_10"
android:paddingBottom="@dimen/dp_6"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="4dp">
<!-- 【必设】升级信息控件tagbeta_upgrade_info-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="beta_upgrade_info"
android:text="info"
android:textColor="#757575"
android:textSize="14sp"
android:visibility="gone"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="@string/strUpgradeDialogFeatureLabel"
android:textColor="#273238"
android:textSize="14sp"
android:visibility="gone"/>
<!-- 【必设】更新属性控件tagbeta_upgrade_feature-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="beta_upgrade_feature"
android:text="feature"
android:lineSpacingExtra="5dp"
android:textColor="#666666"
android:textSize="12sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="15dp">
<!-- 【必设】取消按钮tagbeta_cancel_button-->
<TextView
android:layout_width="0dp"
android:layout_height="38dp"
android:layout_weight="1"
android:background="@drawable/bg_common_cancel"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:tag="beta_cancel_button"
android:text="下次再说"
android:layout_marginEnd="@dimen/dp_10"
android:textColor="#795EEF"
android:textSize="@dimen/dp_14"/>
<!-- 【必设】确认按钮tagbeta_confirm_button-->
<TextView
android:layout_width="0dp"
android:layout_height="38dp"
android:layout_weight="1"
android:background="@drawable/bg_common_confirm_normal"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:tag="beta_confirm_button"
android:text="立刻升级"
android:layout_marginStart="10dp"
android:textColor="@color/white"
android:textSize="@dimen/dp_14" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@@ -535,5 +535,6 @@
<color name="color_FF6B82">#FF6B82</color>
<color name="color_4d000000">#4d000000</color>
<color name="transparent_ban">#80000000</color>
</resources>

View File

@@ -2,5 +2,11 @@
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<root-path path="" name="camera_photos" />
<external-path name="download_apk" path="/Download" />
<!-- <external-path name="download_apk" path="/Download" />-->
<external-path
name="beta_external_path"
path="Download/" />
<external-path
name="beta_external_files_path"
path="Android/data/" />
</paths>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@@ -120,7 +120,7 @@ dependencies {
// RxJava support for Room
api 'androidx.room:room-rxjava2:2.2.5'
api 'com.tencent.bugly:crashreport_upgrade:1.4.2'
api project(':nim_uikit')
api project(':library')

View File

@@ -55,6 +55,10 @@
public static ** valueOf(java.lang.String);
}
#腾讯崩溃收集
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
# 易盾
-keep class com.netease.mobsec.**{*;}