hanwenjie 1 год назад
Родитель
Сommit
cd595884ed

+ 9 - 0
app/build.gradle

@@ -6,6 +6,9 @@ buildscript {
         mavenLocal()
         mavenCentral()
         google()
+        flatDir {
+            dirs 'libs'   // jar目录
+        }
     }
     dependencies {
         classpath "com.tencent.vasdolly:plugin:3.0.6"
@@ -24,6 +27,10 @@ android {
         versionName "1.0.5"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        ndk {
+            // 设置支持的SO库架构
+            abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
+        }
     }
 
     signingConfigs {
@@ -99,5 +106,7 @@ dependencies {
     implementation 'com.github.jenly1314:zxing-lite:2.2.1'
     implementation group: 'cn.hutool', name: 'hutool-core', version: '5.8.20'
     implementation group: 'cn.hutool', name: 'hutool-http', version: '5.8.20'
+//    implementation files('libs/pgy_analytics_sdk.jar')
+    implementation 'com.tencent.bugly:crashreport:latest.release' //其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如4.0.3
     api "com.tencent.vasdolly:helper:3.0.6"
 }

+ 21 - 1
app/src/main/AndroidManifest.xml

@@ -8,8 +8,18 @@
     <uses-permission android:name="android.permission.TRANSMIT_IR" />
     <!-- Android Market会根据uses-feature过滤所有你设备不支持的应用,即无红外功能的设备看不到此应用 -->
     <uses-feature android:name="android.hardware.ConsumerIrManager" />
-    
+
+    <uses-permission
+        android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
+        tools:ignore="ProtectedPermissions" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />  <!-- 获取设备信息 -->
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取网络信息权限-->
+    <uses-permission android:name="android.permission.READ_LOGS"
+        tools:ignore="ProtectedPermissions" />
+
+
     <application
+        android:name=".MyApplication"
         android:allowBackup="true"
         android:dataExtractionRules="@xml/data_extraction_rules"
         android:fullBackupContent="@xml/backup_rules"
@@ -20,6 +30,16 @@
         android:theme="@style/Theme.InfraredRemote"
         android:usesCleartextTraffic="true"
         tools:targetApi="31">
+
+        <!-- 配置APP ID -->
+        <meta-data
+            android:name="BUGLY_APPID"
+            android:value="651efab0e9" />
+        <!-- 配置Bugly调试模式(true或者false)-->
+        <meta-data
+            android:name="BUGLY_ENABLE_DEBUG"
+            android:value="true" />
+
         <activity
             android:name=".MainActivity"
             android:exported="true">

+ 20 - 0
app/src/main/java/com/info666/app/infraredRemote/MyApplication.java

@@ -0,0 +1,20 @@
+package com.info666.app.infraredRemote;
+
+import android.app.Application;
+import android.content.Context;
+
+import com.tencent.bugly.crashreport.CrashReport;
+
+public class MyApplication extends Application {
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        CrashReport.UserStrategy userStrategy = new CrashReport.UserStrategy(this);
+        //在attachBaseContext方法中调用初始化sdk
+        CrashReport.initCrashReport(getApplicationContext(), "651efab0e9", true);
+
+    }
+
+
+}

+ 11 - 0
app/src/main/java/com/info666/app/infraredRemote/activity/InfraredRemoteActivity.java

@@ -7,6 +7,7 @@ import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
 import android.webkit.JavascriptInterface;
+import android.webkit.WebChromeClient;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
@@ -18,6 +19,7 @@ import androidx.appcompat.app.AppCompatActivity;
 import com.info666.app.infraredRemote.R;
 import com.info666.app.infraredRemote.api.ConsumerIrManagerApi;
 import com.king.zxing.CameraScan;
+import com.tencent.bugly.crashreport.CrashReport;
 import com.tencent.vasdolly.helper.ChannelReaderUtil;
 
 import java.lang.reflect.Method;
@@ -40,6 +42,15 @@ public class InfraredRemoteActivity extends AppCompatActivity {
 
     private void initView(){
         this.webView = findViewById(R.id.wb_infrared_remote);
+        // 设置WebChromeClient
+        this.webView.setWebChromeClient(new WebChromeClient() {
+            @Override
+            public void onProgressChanged(WebView webView, int progress) {
+                // 增加Javascript异常监控
+                CrashReport.setJavascriptMonitor(webView, true);
+                super.onProgressChanged(webView, progress);
+            }
+        });
     }
 
     private void initData(){

+ 22 - 8
app/src/main/java/com/info666/app/infraredRemote/api/ConsumerIrManagerApi.java

@@ -8,6 +8,8 @@ import android.util.Log;
 import android.webkit.JavascriptInterface;
 
 import com.alibaba.fastjson2.JSON;
+import com.tencent.bugly.crashreport.BuglyLog;
+import com.tencent.bugly.crashreport.CrashReport;
 
 import cn.hutool.core.exceptions.ExceptionUtil;
 
@@ -42,14 +44,25 @@ public class ConsumerIrManagerApi {
      */
     @JavascriptInterface
     public boolean hasIrEmitter() {
+        boolean has = this.checkHasIrEmitter();
+        if(!has){
+            CrashReport.postCatchedException(new RuntimeException("不支持红外"));
+        }
+        return has;
+    }
+
+    public boolean checkHasIrEmitter(){
         //android4.4及以上版本&有红外功能
         if (service != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+            BuglyLog.d("ConsumerIrManagerApi", "hasIrEmitter("+service.hasIrEmitter()+")");
             return service.hasIrEmitter();
         }
+        BuglyLog.e("ConsumerIrManagerApi", "hasIrEmitter(false)");
         //android4.4以下及4.4以上没红外功能
         return false;
     }
 
+
     /**
      * 发射红外信号
      *
@@ -60,15 +73,16 @@ public class ConsumerIrManagerApi {
     public void transmit(int carrierFrequency, int[] pattern) {
         if (service != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             //异步发射
-            try {
-                mHandler.post(()->{
-                    Log.d("ConsumerIrManagerApi","transmit("+carrierFrequency+","+ JSON.toJSONString(pattern) +")");
+            mHandler.post(() -> {
+                try {
+                    BuglyLog.d("ConsumerIrManagerApi", "transmit(" + carrierFrequency + "," + JSON.toJSONString(pattern) + ")");
                     service.transmit(carrierFrequency, pattern);
-                });
-            }catch (Exception e){
-                e.printStackTrace();
-                Log.e("--红外发射失败--", ExceptionUtil.getSimpleMessage(e));
-            }
+                } catch (Exception e) {
+                    BuglyLog.e("--红外发射失败--", ExceptionUtil.getSimpleMessage(e));
+                    CrashReport.postCatchedException(e);
+                    throw e;
+                }
+            });
         }
     }