开发指南

Android SDK


运行环境

Android 5.0 或更高


引入SDK

1. 在项目根目录的build.gradle中声明maven仓库, 如下所示:

allprojects {

    repositories {

        maven {

            url 'https://dl.bintray.com/weimob/maven'

        }

        maven {

            url 'https://maven.google.com'

        }

        mavenCentral()

        jcenter()

        google()    

    }

}

2. 在子项目build.gradle的dependencies中引入依赖:

compile 'com.web.library.groups:webviewsdk:1.0.0'


混淆规则

# WMWebView SDK start

-dontwarn com.web.**

-keep class com.web.library.groups.** { *; }

 

-dontwarn com.weimob.library.groups.**

-keep class com.weimob.library.groups.** { *; }

 

-dontwarn com.alibaba.fastjson.**

-keep class com.alibaba.fastjson.** { *; }

 

#Fresco

# Keep our interfaces so they can be used by other ProGuard rules.

# See http://sourceforge.net/p/proguard/bugs/466/

-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

 

# Do not strip any method/class that is annotated with @DoNotStrip

-keep @com.facebook.common.internal.DoNotStrip class *

-keepclassmembers class * {

    @com.facebook.common.internal.DoNotStrip *;

}

 

# Keep native methods

-keepclassmembers class * {

native <methods>;

}

 

#WMWebView SDK end


 配置

权限由接入方自己在manifast文件中配置,下面是SDK用到的相关权限

    <!-- 允许应用程序联网 -->

    <uses-permission android:name="android.permission.INTERNET" />

    <!-- 检测联网方式, 区分用户设备使用的是2G、3G或是WiFi -->

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <!-- 外部存储写入权限 -->

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- 为了更好的体验需要获取地理信息的权限 (以下非必须权限) -->

    <uses-permission android:name="android.permission.ACCESS_GPS" />

    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />

    <uses-permission android:name="android.permission.ACCESS_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

特殊权限说明:

· 外部存储读写权限是用于文件选择

· 网络状态权限是用于处理网络


初始化SDK

在AndroidManifest中配置scheme(支付回调需要对scheme进行匹配) 示例如下:

    <activity android:name=".Login.LoginActivity">

            <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" />

                <!--scheme : xxx.n.weimob.com-->

                <data android:scheme="wmsdk.n.weimob.com" />

            </intent-filter>

        </activity>

 

在Application或者加载页面之前对SDK进行初始化, 示例如下:

public class MyApplication extends Application {

    @Override

    public void onCreate() {

        super.onCreate();

        // 1.初始化SDK------------------------------

        // 需和manifest配置scheme一致

        // String scheme = "wmsdk.n.weimob.com";

  // WebViewSdk.getInstance().init(scheme);

 

    }

}

 

APP启动后获得ticket设置appTicket至SDK 示例如下:

public class MainActivity extends Activity {

    @Override

    public void onCreate() {

        super.onCreate();

        // 1.已登录直接setAppTicket------------------------------

        // WebViewSdk.getInstance().setAppTicket(appTicket);

        // 2.未登录则登录后setAppTicket------------------------------

        // Logoin.toLogin() -> onLoginSuccess -> WebViewSdk.getInstance().setAppTicket(appTicket);

 

    }

}

 

初始化WebviewActivity及webview, 示例如下:

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

 

    <com.web.library.groups.webviewsdk.core.WMWebView

        android:id="@+id/webView"

        android:layout_width="match_parent"

        android:layout_height="match_parent"/>

</LinearLayout>

 

登录认证

 


 


注:登录验证失败或登录超时务必重新登录并在登录成功后设置新的appTicket

public class WebviewActivity extends Activity {

    @Override

    public void onCreate() {

  super.onCreate();

        WebViewSdk.getInstance().setOnAuthExpiredListener(new

           WebViewSdk.OnAuthExpiredListener()  { 

               @Override

               public void onAuthExpired() {

                // TODO 登录超时或登录失效,需重新登录获取新的appTicket,根据需求自行添加逻辑

1) Login.toLogin

2) loginSuccess

3) WebViewSdk.getInstance().setAppTicket(appTicket);

           }

});

    }

}

否则请关闭WebviewActivity

 

WebViewActivity添加onActivityResult 示例如下:

public class WebviewActivity extends Activity {

    @Override

    public void onActivityResul (int requestCode, int resultCode, Intent data) {

        super. onActivityResult (requestCode, resultCode, data);

        webview.onActivityResult(requestCode, resultCode, data);

    }

}

 

loadUrl(url):

public class WebviewActivity extends Activity {

    

    private void load (String url) {

        webview.loadUrl(url);

    }

}


售前咨询热线

10105188

在线QQ咨询

关注微盟

扫描关注官方微信

总部咨询热线:10105188 QQ:4006305400 邮箱:feedback@weimob.com 举报电话:02180356016

地址:上海市宝山区长江路258号微盟大厦

Copyright © 2011-2019 yun.weimob.com. All Rights Reserved 上海微盟企业发展有限公司版权所有 沪ICP备14044897号-9