-
安装本插件
修改插件里边高德地图的ak 为自己的申请的ak
文件路径:项目目录\node_modules\cordova-plugins-ths-hik-im\plugin.xml
修改内容:
<!-- f2a462a2c89e7787682569226dcc2eea 需要换成自己在高德地图网站上注册的 --> <meta-data android:name="com.amap.api.v2.apikey" android:value="f2a462a2c89e7787682569226dcc2eea" tools:replace="android:value"/>
-
同步生成安卓项目目录
-
拷贝 maven 到项目的 android 目录下(如果已经拷贝过了,不用重复拷贝)
-
修改android 目录下的build.gradle(修改一次即可,不用重复修改,除非重新添加了平台)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = "1.5.0" // 添加行 repositories { maven { url '../android/maven' } // 添加行 google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.2.1' classpath 'com.google.gms:google-services:4.3.5' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"// 添加行 classpath 'com.hatom.router:router-plugin:2.0.1-SNAPSHOT'// 添加行 // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } apply from: "variables.gradle" allprojects { repositories { maven { url '../maven' }// 添加行 google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
-
修改项目目录\android\app\src\main\Android Manifest.xml(按照注释部分修改,不要直接整体粘贴)
<?xml version="1.0" encoding="utf-8"?> <!-- xmlns:tools="http://schemas.android.com/tools" 新增的 --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="cn.com.ths.winter.olympics.games"> <queries> <package android:name="com.xmessage.phone"></package> </queries> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:networkSecurityConfig="@xml/network_config" android:theme="@style/AppTheme"> <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:name="cn.com.ths.winter.olympics.games.MainActivity" android:label="@string/title_activity_main" android:theme="@style/AppTheme.NoActionBarLaunch" android:windowSoftInputMode="adjustNothing" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- tools:replace="android:authorities" tools:replace="android:resource" 这两处修改可能会造成依赖库aar 中跟文件相关的功能不好使 ${applicationId}.fileprovider 改为${applicationId}.provider --> <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" tools:replace="android:authorities" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" tools:replace="android:resource"></meta-data> </provider> </application> <!-- Permissions --> <uses-permission android:name="android.permission.INTERNET" /> </manifest>
-
-
修改android/app/build.gradle
//apply plugin: 'com.android.application' plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-android-extensions' id 'kotlin-kapt' id 'HRouter' }
-
修改项目名\android\capacitor-cordova-android-plugins\src\main\Android Manifest.xml,在头部标签中添加(按照注释部分修改,不要直接整体粘贴)
<?xml version='1.0' encoding='utf-8'?> <manifest package="capacitor.android.plugins" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:amazon="http://schemas.amazon.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <!-- xmlns:tools="http://schemas.android.com/tools" 新增的 -->
const ip = '10.100.3.58'; // "10.100.3.58","443","silu","",
const edtPort = '443';
const name = 'silu';
const pwd = '';
(window as any).cordova.plugins.ThsHikIM.login(ip, edtPort, name, pwd,(res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
(window as any).cordova.plugins.ThsHikIM.loginOut((res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
(window as any).cordova.plugins.ThsHikIM.goChat((res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
(window as any).cordova.plugins.ThsHikIM.goContact((res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
(window as any).cordova.plugins.ThsHikIM.startMore((res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
(window as any).cordova.plugins.ThsHikIM.queryMsg("silu",(res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
(window as any).cordova.plugins.ThsHikIM.enterMsgDetail(msgItemJson,(res: any) => {
console.log(res);
},(err: any) => {
console.log(err);
});
document.addEventListener('ThsHikIM.receiveHLoginEventInAndroidCallback', data => {
console.log(data);
alert(JSON.stringify(data));
}, false);
document.addEventListener('ThsHikIM.receiveMessageInAndroidCallback', data => {
console.log(data);
alert(JSON.stringify(data));
}, false);