cordova-plugins-ths-hik-im

1.0.8 • Public • Published

cordova-plugins-ths-hik-im

使用步骤

  1. 安装本插件

    修改插件里边高德地图的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"/>
    
  2. 同步生成安卓项目目录

  3. 拷贝 maven 到项目的 android 目录下(如果已经拷贝过了,不用重复拷贝)

  4. 修改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
    }
    
    
    1. 修改项目目录\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>
      
      
  5. 修改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'
    }
    
  6. 修改项目名\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" 新增的
    -->
    

使用示例

1 登录IM并跳转到消息页面

  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);
  });
   

2 退出

 
  (window as any).cordova.plugins.ThsHikIM.loginOut((res: any) => {
    console.log(res);
  },(err: any) => {
    console.log(err);
  });
   

3 跳转到聊天信息页面(需先调用登录)

 
  (window as any).cordova.plugins.ThsHikIM.goChat((res: any) => {
    console.log(res);
  },(err: any) => {
    console.log(err);
  });
   

4 跳转到联系人页面(需先调用登录)

 
  (window as any).cordova.plugins.ThsHikIM.goContact((res: any) => {
    console.log(res);
  },(err: any) => {
    console.log(err);
  });
   

5 跳转到查看更多页面

 (window as any).cordova.plugins.ThsHikIM.startMore((res: any) => {
    console.log(res);
  },(err: any) => {
    console.log(err);
  });

6 查询历史聊天信息列表

 (window as any).cordova.plugins.ThsHikIM.queryMsg("silu",(res: any) => {
    console.log(res);
  },(err: any) => {
    console.log(err);
  });

7 跳转进入聊天信息详情

 (window as any).cordova.plugins.ThsHikIM.enterMsgDetail(msgItemJson,(res: any) => {
    console.log(res);
  },(err: any) => {
    console.log(err);
  });

8 监听登录结果回调

document.addEventListener('ThsHikIM.receiveHLoginEventInAndroidCallback', data => {
      console.log(data);
      alert(JSON.stringify(data));
}, false);

9 监听收到新消息结果回调

document.addEventListener('ThsHikIM.receiveMessageInAndroidCallback', data => {
      console.log(data);
      alert(JSON.stringify(data));
}, false);

常见错误

1

Package Sidebar

Install

npm i cordova-plugins-ths-hik-im

Weekly Downloads

0

Version

1.0.8

License

ISC

Unpacked Size

186 kB

Total Files

9

Last publish

Collaborators

  • liuyx