ソースを参照

微信小程序埋点完成

huyuguo 4 年 前
コミット
9fbdce0248

+ 11 - 12
app/src/main/java/com/electric/chargingpile/activity/HomeAdActivity.java

3
import android.app.Activity;
3
import android.app.Activity;
4
import android.content.Intent;
4
import android.content.Intent;
5
import android.os.Bundle;
5
import android.os.Bundle;
6
6
import androidx.constraintlayout.widget.ConstraintLayout;
7
import androidx.constraintlayout.widget.ConstraintLayout;
8
7
import android.util.Log;
9
import android.util.Log;
8
import android.view.View;
10
import android.view.View;
9
import android.widget.ImageView;
11
import android.widget.ImageView;
47
        super.onCreate(savedInstanceState);
49
        super.onCreate(savedInstanceState);
48
        setContentView(R.layout.activity_home_ad);
50
        setContentView(R.layout.activity_home_ad);
49
        BarColorUtil.initStatusBarColor(HomeAdActivity.this);
51
        BarColorUtil.initStatusBarColor(HomeAdActivity.this);
50
        Log.e(TAG, "onCreate: 111" + 111);
51
        initViews();
52
        initViews();
52
        initDatas();
53
        initDatas();
53
54
    }
54
    }
55
55
56
    private void setTimer() {
56
    private void setTimer() {
134
134
135
    private void uploadDmp(String url) {
135
    private void uploadDmp(String url) {
136
        url = Util.generateDmpUrl(url);
136
        url = Util.generateDmpUrl(url);
137
        OkHttpUtils.get().url(url).build().connTimeOut(3000).readTimeOut(3000)
138
                .execute(new StringCallback() {
139
                    @Override
140
                    public void onError(Call call, Exception e) {
141
                        e.printStackTrace();
142
                    }
137
        OkHttpUtils.get().url(url).build().connTimeOut(3000).readTimeOut(3000).execute(new StringCallback() {
138
            @Override
139
            public void onError(Call call, Exception e) {
140
                e.printStackTrace();
141
            }
143
142
144
                    @Override
145
                    public void onResponse(String response) {
146
                    }
147
                });
143
            @Override
144
            public void onResponse(String response) {
145
            }
146
        });
148
    }
147
    }
149
148
150
    private void loadAdImage() {
149
    private void loadAdImage() {

+ 33 - 53
app/src/main/java/com/electric/chargingpile/activity/MyWebViewActivity.java

19
import android.os.Environment;
19
import android.os.Environment;
20
import android.os.Handler;
20
import android.os.Handler;
21
import android.provider.MediaStore;
21
import android.provider.MediaStore;
22
22
import androidx.annotation.NonNull;
23
import androidx.annotation.NonNull;
23
import androidx.core.content.FileProvider;
24
import androidx.core.content.FileProvider;
25
24
import android.util.Log;
26
import android.util.Log;
25
import android.view.KeyEvent;
27
import android.view.KeyEvent;
26
import android.view.View;
28
import android.view.View;
43
import com.afollestad.materialdialogs.DialogAction;
45
import com.afollestad.materialdialogs.DialogAction;
44
import com.afollestad.materialdialogs.MaterialDialog;
46
import com.afollestad.materialdialogs.MaterialDialog;
45
import com.blankj.utilcode.util.LogUtils;
47
import com.blankj.utilcode.util.LogUtils;
48
import com.electric.chargingpile.BuildConfig;
46
import com.electric.chargingpile.R;
49
import com.electric.chargingpile.R;
47
import com.electric.chargingpile.application.MainApplication;
50
import com.electric.chargingpile.application.MainApplication;
48
import com.electric.chargingpile.data.ChargingShareBean;
51
import com.electric.chargingpile.data.ChargingShareBean;
57
import com.electric.chargingpile.view.AlertDialogTwo;
60
import com.electric.chargingpile.view.AlertDialogTwo;
58
import com.google.gson.Gson;
61
import com.google.gson.Gson;
59
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
62
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
63
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
64
import com.tencent.mm.opensdk.openapi.IWXAPI;
65
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
60
import com.umeng.analytics.MobclickAgent;
66
import com.umeng.analytics.MobclickAgent;
61
import com.zhy.http.okhttp.OkHttpUtils;
67
import com.zhy.http.okhttp.OkHttpUtils;
62
import com.zhy.http.okhttp.callback.StringCallback;
68
import com.zhy.http.okhttp.callback.StringCallback;
111
        super.onCreate(savedInstanceState);
117
        super.onCreate(savedInstanceState);
112
        setContentView(R.layout.activity_my_web_view);
118
        setContentView(R.layout.activity_my_web_view);
113
        BarColorUtil.initStatusBarColor(MyWebViewActivity.this);
119
        BarColorUtil.initStatusBarColor(MyWebViewActivity.this);
114
115
//        getShareIntegral();
116
        getIntentData();
120
        getIntentData();
117
        initView();
121
        initView();
118
        initWebView();
122
        initWebView();
122
        mUrl = getIntent().getStringExtra("url");
126
        mUrl = getIntent().getStringExtra("url");
123
        advertiser = getIntent().getStringExtra("advertiser");
127
        advertiser = getIntent().getStringExtra("advertiser");
124
        Log.e(TAG, "getIntentData: " + mUrl);
128
        Log.e(TAG, "getIntentData: " + mUrl);
125
        if (advertiser!=null && advertiser.equals("1")) {
129
        if (advertiser != null && advertiser.equals("1")) {
126
            mUrl = Util.generateDmpUrl(mUrl);
130
            mUrl = Util.generateDmpUrl(mUrl);
127
        }
131
        }
128
    }
132
    }
161
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
165
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
162
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
166
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
163
        }
167
        }
164
//        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
165
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
168
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
166
        webView.addJavascriptInterface(this, "cdz");
169
        webView.addJavascriptInterface(this, "cdz");
167
        webView.setWebViewClient(mWebViewClient);
170
        webView.setWebViewClient(mWebViewClient);
168
        if (null != mUrl && !"".equals(mUrl)) {
171
        if (null != mUrl && !"".equals(mUrl)) {
172
            if (mUrl.contains("?")) {
173
                mUrl = mUrl + "&version_code=" + BuildConfig.VERSION_CODE;
174
            } else {
175
                mUrl = mUrl + "?version_code=" + BuildConfig.VERSION_CODE;
176
            }
169
            webView.loadUrl(mUrl);
177
            webView.loadUrl(mUrl);
170
        }
178
        }
171
    }
179
    }
172
180
181
    // 93 3.5.5 小程序埋点
182
    @JavascriptInterface
183
    public void showminiprogram(final String user_name, String path, int type) {
184
        IWXAPI api = WXAPIFactory.createWXAPI(MyWebViewActivity.this,getResources().getString(R.string.wx_app_key));
185
        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
186
        req.userName = user_name;
187
        req.path = path;
188
        req.miniprogramType = type;
189
        api.sendReq(req);
190
    }
191
173
    @JavascriptInterface
192
    @JavascriptInterface
174
    public void showsharebtn(final String show) {
193
    public void showsharebtn(final String show) {
175
        runOnUiThread(new Runnable() {
194
        runOnUiThread(new Runnable() {
189
208
190
    @JavascriptInterface
209
    @JavascriptInterface
191
    public void freshpage(final String url) {
210
    public void freshpage(final String url) {
192
        Log.e(TAG, "freshpage: url=" + url);
193
        list.add(url);
211
        list.add(url);
194
//        refreshUrl = url;
195
    }
212
    }
196
213
197
198
    @JavascriptInterface
214
    @JavascriptInterface
199
    public void setrctext(final String s) {
215
    public void setrctext(final String s) {
200
        Log.e(TAG, "setrctext: s=" + s);
216
        Log.e(TAG, "setrctext: s=" + s);
222
238
223
    @JavascriptInterface
239
    @JavascriptInterface
224
    public void emitshareinfo(String shareInfo) {
240
    public void emitshareinfo(String shareInfo) {
225
//        LogUtils.e(shareInfo);
226
//        "分享标题##分享描述##分享ico##分享url"
241
//        "分享标题##分享描述##分享ico##分享url"
227
        String[] strarray = shareInfo.split("\\#\\#");
242
        String[] strarray = shareInfo.split("\\#\\#");
228
        if (strarray.length > 1) {
243
        if (strarray.length > 1) {
332
                        }
347
                        }
333
                    }
348
                    }
334
                }).build();
349
                }).build();
335
//        build.
336
        build.show();
350
        build.show();
337
    }
351
    }
338
352
362
                        }
376
                        }
363
                    }
377
                    }
364
                }).build();
378
                }).build();
365
//        build.
366
        build.show();
379
        build.show();
367
    }
380
    }
368
381
379
            @Override
392
            @Override
380
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
393
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
381
                getShareIntegral();
394
                getShareIntegral();
382
//                ToastUtil.showToast(getApplicationContext(),"分享成功",Toast.LENGTH_SHORT);
383
            }
395
            }
384
396
385
            @Override
397
            @Override
409
                if (MainApplication.isLogin()) {
421
                if (MainApplication.isLogin()) {
410
                    getShareIntegral();
422
                    getShareIntegral();
411
                }
423
                }
412
//                ToastUtil.showToast(getApplicationContext(),"分享成功",Toast.LENGTH_SHORT);
413
            }
424
            }
414
425
415
            @Override
426
            @Override
434
    public void telTask(final String s) {
445
    public void telTask(final String s) {
435
        if (hasCallPhonePermission()) {
446
        if (hasCallPhonePermission()) {
436
            // Have permission, do the thing!
447
            // Have permission, do the thing!
437
//            Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
438
            new com.electric.chargingpile.view.AlertDialog(MyWebViewActivity.this).builder()
448
            new com.electric.chargingpile.view.AlertDialog(MyWebViewActivity.this).builder()
439
                    .setMsg(s)
449
                    .setMsg(s)
440
                    .setPositiveButton("呼叫", new View.OnClickListener() {
450
                    .setPositiveButton("呼叫", new View.OnClickListener() {
472
        AlertDialogTwo wechatAlert = new AlertDialogTwo(MyWebViewActivity.this);
482
        AlertDialogTwo wechatAlert = new AlertDialogTwo(MyWebViewActivity.this);
473
        wechatAlert.builder().setTitle("温馨提示")
483
        wechatAlert.builder().setTitle("温馨提示")
474
                .setMsg("客服微信:chongdianzhuang2")
484
                .setMsg("客服微信:chongdianzhuang2")
475
                .setPositiveButton("复制", new View.OnClickListener(){
485
                .setPositiveButton("复制", new View.OnClickListener() {
476
                    @Override
486
                    @Override
477
                    public void onClick(View view) {
487
                    public void onClick(View view) {
478
                        ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
488
                        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
479
                        ClipData cdzData = ClipData.newPlainText("Label", "chongdianzhuang2");
489
                        ClipData cdzData = ClipData.newPlainText("Label", "chongdianzhuang2");
480
                        cm.setPrimaryClip(cdzData);
490
                        cm.setPrimaryClip(cdzData);
481
                        ToastUtil.showToast(getApplicationContext(), "微信号复制成功", Toast.LENGTH_SHORT);
491
                        ToastUtil.showToast(getApplicationContext(), "微信号复制成功", Toast.LENGTH_SHORT);
835
                }
845
                }
836
            }
846
            }
837
        };
847
        };
838
        OkHttpUtils.get()
839
                .url(url)
840
                .build()
841
                .execute(stringCallback);
848
        OkHttpUtils.get().url(url).build().execute(stringCallback);
842
    }
849
    }
843
850
844
    private void onResumeSkip() {
851
    private void onResumeSkip() {
897
        for (int i = 0; i < list.size(); i++) {
904
        for (int i = 0; i < list.size(); i++) {
898
            if (currentUrl.contains(list.get(i))) {
905
            if (currentUrl.contains(list.get(i))) {
899
                Log.e(TAG, "onResume: =" + "========");
906
                Log.e(TAG, "onResume: =" + "========");
900
//                ToastUtil.showToast(getApplicationContext(),"1111",Toast.LENGTH_SHORT);
901
                webView.reload();
907
                webView.reload();
902
                list.remove(list.get(i));
908
                list.remove(list.get(i));
903
                break;
909
                break;
919
            e.printStackTrace();
925
            e.printStackTrace();
920
        }
926
        }
921
        String replace = URLEncoder.encode(encode_token);
927
        String replace = URLEncoder.encode(encode_token);
922
//                    startActivity(new Intent(getApplication(), ShopActivity.class));
923
        Intent intent11 = new Intent();
928
        Intent intent11 = new Intent();
924
        intent11.setClass(getApplicationContext(), CreditActivity.class);
929
        intent11.setClass(getApplicationContext(), CreditActivity.class);
925
        intent11.putExtra("navColor", "#fcfcfc");    //配置导航条的背景颜色,请用#ffffff长格式。
930
        intent11.putExtra("navColor", "#fcfcfc");    //配置导航条的背景颜色,请用#ffffff长格式。
942
             */
947
             */
943
            public void onShareClick(WebView webView, String shareUrl, String shareThumbnail, String shareTitle, String shareSubtitle) {
948
            public void onShareClick(WebView webView, String shareUrl, String shareThumbnail, String shareTitle, String shareSubtitle) {
944
                //当分享按钮被点击时,会调用此处代码。在这里处理分享的业务逻辑。
949
                //当分享按钮被点击时,会调用此处代码。在这里处理分享的业务逻辑。
945
//                            new AlertDialog.Builder(webView.getContext())
946
//                                    .setTitle("分享信息")
947
//                                    .setItems(new String[] {"标题:"+shareTitle,"副标题:"+shareSubtitle,"缩略图地址:"+shareThumbnail,"链接:"+shareUrl}, null)
948
//                                    .setNegativeButton("确定", null)
949
//                                    .show();
950
951
                ChargingShareBean chargingShareBean = new ChargingShareBean();
950
                ChargingShareBean chargingShareBean = new ChargingShareBean();
952
                chargingShareBean.setIcon(shareThumbnail);
951
                chargingShareBean.setIcon(shareThumbnail);
953
                chargingShareBean.setTitle(shareTitle);
952
                chargingShareBean.setTitle(shareTitle);
954
                chargingShareBean.setUrl(shareUrl);
953
                chargingShareBean.setUrl(shareUrl);
955
                chargingShareBean.setText("");
954
                chargingShareBean.setText("");
956
957
958
                showSimpleBottomSheetGrid(chargingShareBean);
955
                showSimpleBottomSheetGrid(chargingShareBean);
959
960
961
            }
956
            }
962
957
963
            /**
958
            /**
973
                //当用户登录成功后,需要重新请求一次服务端,带上currentUrl。
968
                //当用户登录成功后,需要重新请求一次服务端,带上currentUrl。
974
                //用该方法中的webview变量加载请求链接。
969
                //用该方法中的webview变量加载请求链接。
975
                //服务端收到请求后在生成免登录url时,将currentUrl放入redirect参数,通知客户端302跳转到新生成的免登录URL。
970
                //服务端收到请求后在生成免登录url时,将currentUrl放入redirect参数,通知客户端302跳转到新生成的免登录URL。
976
                new AlertDialog.Builder(webView.getContext())
977
                        .setTitle("跳转登录")
978
                        .setMessage("跳转到登录页面?")
971
                new AlertDialog.Builder(webView.getContext()).setTitle("跳转登录").setMessage("跳转到登录页面?")
979
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
972
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
980
                            @Override
973
                            @Override
981
                            public void onClick(DialogInterface dialog, int which) {
974
                            public void onClick(DialogInterface dialog, int which) {
982
                                MainApplication.current_url = currentUrl;
975
                                MainApplication.current_url = currentUrl;
983
                                startActivity(new Intent(getApplicationContext(), LoginActivity.class));
976
                                startActivity(new Intent(getApplicationContext(), LoginActivity.class));
984
985
                            }
977
                            }
986
                        })
978
                        })
987
                        .setNegativeButton("否", null)
979
                        .setNegativeButton("否", null)
1009
            public void onLocalRefresh(WebView mWebView, String credits) {
1001
            public void onLocalRefresh(WebView mWebView, String credits) {
1010
                //String credits为积分商城返回的最新积分,不保证准确。
1002
                //String credits为积分商城返回的最新积分,不保证准确。
1011
                //触发更新本地积分,这里建议用ajax向自己服务器请求积分值,比较准确。
1003
                //触发更新本地积分,这里建议用ajax向自己服务器请求积分值,比较准确。
1012
//                    Toast.makeText(getApplicationContext(), "触发本地刷新积分:"+credits,Toast.LENGTH_SHORT).show();
1013
            }
1004
            }
1014
        };
1005
        };
1015
    }
1006
    }
1052
             */
1043
             */
1053
            public void onShareClick(WebView webView, String shareUrl, String shareThumbnail, String shareTitle, String shareSubtitle) {
1044
            public void onShareClick(WebView webView, String shareUrl, String shareThumbnail, String shareTitle, String shareSubtitle) {
1054
                //当分享按钮被点击时,会调用此处代码。在这里处理分享的业务逻辑。
1045
                //当分享按钮被点击时,会调用此处代码。在这里处理分享的业务逻辑。
1055
//                            new AlertDialog.Builder(webView.getContext())
1056
//                                    .setTitle("分享信息")
1057
//                                    .setItems(new String[] {"标题:"+shareTitle,"副标题:"+shareSubtitle,"缩略图地址:"+shareThumbnail,"链接:"+shareUrl}, null)
1058
//                                    .setNegativeButton("确定", null)
1059
//                                    .show();
1060
                ChargingShareBean chargingShareBean = new ChargingShareBean();
1046
                ChargingShareBean chargingShareBean = new ChargingShareBean();
1061
                chargingShareBean.setIcon(shareThumbnail);
1047
                chargingShareBean.setIcon(shareThumbnail);
1062
                chargingShareBean.setTitle(shareTitle);
1048
                chargingShareBean.setTitle(shareTitle);
1086
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
1072
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
1087
                            @Override
1073
                            @Override
1088
                            public void onClick(DialogInterface dialog, int which) {
1074
                            public void onClick(DialogInterface dialog, int which) {
1089
//                                        MainApplication.current_url = currentUrl;
1090
                                MainApplication.h5_url = currentUrl;
1075
                                MainApplication.h5_url = currentUrl;
1091
                                startActivity(new Intent(getApplicationContext(), LoginActivity.class));
1076
                                startActivity(new Intent(getApplicationContext(), LoginActivity.class));
1092
1077
1117
            public void onLocalRefresh(WebView mWebView, String credits) {
1102
            public void onLocalRefresh(WebView mWebView, String credits) {
1118
                //String credits为积分商城返回的最新积分,不保证准确。
1103
                //String credits为积分商城返回的最新积分,不保证准确。
1119
                //触发更新本地积分,这里建议用ajax向自己服务器请求积分值,比较准确。
1104
                //触发更新本地积分,这里建议用ajax向自己服务器请求积分值,比较准确。
1120
//                    Toast.makeText(getApplicationContext(), "触发本地刷新积分:" + credits, Toast.LENGTH_SHORT).show();
1121
            }
1105
            }
1122
        };
1106
        };
1123
    }
1107
    }
1240
            mOpenFileWebChromeClient.mFilePathCallback = null;
1224
            mOpenFileWebChromeClient.mFilePathCallback = null;
1241
            mOpenFileWebChromeClient.mFilePathCallbacks = null;
1225
            mOpenFileWebChromeClient.mFilePathCallbacks = null;
1242
        }
1226
        }
1243
//        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
1244
//            new AppSettingsDialog.Builder(MyWebViewActivity.this,
1245
//                    "该功能需要开启拨号权限,是否前往开启?").build().show();
1246
//        }
1247
    }
1227
    }
1248
1228
1249
    private boolean hasCallPhonePermission() {
1229
    private boolean hasCallPhonePermission() {
1351
                .canceledOnTouchOutside(false).itemsCallback(new MaterialDialog.ListCallback() {
1331
                .canceledOnTouchOutside(false).itemsCallback(new MaterialDialog.ListCallback() {
1352
            @Override
1332
            @Override
1353
            public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
1333
            public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
1354
                if (position == 0){
1334
                if (position == 0) {
1355
                    takeCamera();
1335
                    takeCamera();
1356
                } else if (position == 1) {
1336
                } else if (position == 1) {
1357
                    takePhoto();
1337
                    takePhoto();
1377
            File imageFile = ImageUitl.getFile(cameraFilePath);
1357
            File imageFile = ImageUitl.getFile(cameraFilePath);
1378
            Uri uri = parseUri(imageFile);
1358
            Uri uri = parseUri(imageFile);
1379
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
1359
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
1380
            try{
1360
            try {
1381
                startActivityForResult(intent, FILE_CAMERA_RESULT_CODE);
1361
                startActivityForResult(intent, FILE_CAMERA_RESULT_CODE);
1382
            } catch (Exception e) {
1362
            } catch (Exception e) {
1383
                e.printStackTrace();
1363
                e.printStackTrace();
1432
                    intent.setData(Uri.parse(url));
1412
                    intent.setData(Uri.parse(url));
1433
                    startActivity(intent);
1413
                    startActivity(intent);
1434
                } catch (ActivityNotFoundException e) {
1414
                } catch (ActivityNotFoundException e) {
1435
//                        MiscUtil.toastShortShow(mContext, "请安装微信最新版!");
1436
                }
1415
                }
1437
            } else if (url.startsWith("tel:")) {
1416
            } else if (url.startsWith("tel:")) {
1438
                Intent intent = new Intent(Intent.ACTION_VIEW,
1417
                Intent intent = new Intent(Intent.ACTION_VIEW,
1450
    @Override
1429
    @Override
1451
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
1430
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
1452
        super.onActivityResult(requestCode, resultCode, data);
1431
        super.onActivityResult(requestCode, resultCode, data);
1453
        if (null == mOpenFileWebChromeClient.mFilePathCallback && null == mOpenFileWebChromeClient.mFilePathCallbacks) return;
1432
        if (null == mOpenFileWebChromeClient.mFilePathCallback && null == mOpenFileWebChromeClient.mFilePathCallbacks)
1433
            return;
1454
        if (resultCode != RESULT_OK) {
1434
        if (resultCode != RESULT_OK) {
1455
            if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
1435
            if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
1456
                mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(null);
1436
                mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(null);
1501
            ClipData clipData = intent.getClipData();
1481
            ClipData clipData = intent.getClipData();
1502
            if (clipData != null) {
1482
            if (clipData != null) {
1503
                results = new Uri[clipData.getItemCount()];
1483
                results = new Uri[clipData.getItemCount()];
1504
                for (int i=0;i<clipData.getItemCount();i++) {
1484
                for (int i = 0; i < clipData.getItemCount(); i++) {
1505
                    ClipData.Item item = clipData.getItemAt(i);
1485
                    ClipData.Item item = clipData.getItemAt(i);
1506
                    results[i] = item.getUri();
1486
                    results[i] = item.getUri();
1507
                }
1487
                }
1508
            }
1488
            }
1509
            if (dataString != null) {
1489
            if (dataString != null) {
1510
                results = new Uri[] {Uri.parse(dataString)};
1490
                results = new Uri[]{Uri.parse(dataString)};
1511
            }
1491
            }
1512
            mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(results);
1492
            mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(results);
1513
            mOpenFileWebChromeClient.mFilePathCallbacks = null;
1493
            mOpenFileWebChromeClient.mFilePathCallbacks = null;

+ 17 - 80
app/src/main/java/com/electric/chargingpile/activity/WelcomeActivity.java

14
import android.os.Environment;
14
import android.os.Environment;
15
import android.os.Handler;
15
import android.os.Handler;
16
import android.os.Message;
16
import android.os.Message;
17

17
import androidx.annotation.NonNull;
18
import androidx.annotation.NonNull;
18
import androidx.viewpager.widget.ViewPager;
19
import androidx.viewpager.widget.ViewPager;
19
import androidx.appcompat.app.AlertDialog;
20
import androidx.appcompat.app.AlertDialog;
21

20
import android.util.Log;
22
import android.util.Log;
21
import android.view.LayoutInflater;
23
import android.view.LayoutInflater;
22
import android.view.View;
24
import android.view.View;
113
        public void handleMessage(Message msg) {
115
        public void handleMessage(Message msg) {
114
            switch (msg.what) {
116
            switch (msg.what) {
115
                case 1:
117
                case 1:
116

117
                    try {
118
                    try {
118

119
                        JSONArray jsonArray = new JSONArray(msg.obj.toString());
119
                        JSONArray jsonArray = new JSONArray(msg.obj.toString());
120

121
                        JSONObject jsonObj = new JSONObject(jsonArray.get(0).toString());
120
                        JSONObject jsonObj = new JSONObject(jsonArray.get(0).toString());
122
                        img = jsonObj.getString("img");
121
                        img = jsonObj.getString("img");
123

124

125
//                        Log.e("!!!!!pic", MainApplication.url + "/zhannew//uploadfile/" + img);
126

127
//						JSONObject jsonObj = new JSONObject(msg.obj.toString());
128
//						final String img = jsonObj.getString("img");
129

130

131
                    } catch (JSONException e) {
122
                    } catch (JSONException e) {
132
                        e.printStackTrace();
123
                        e.printStackTrace();
133
                    }
124
                    }
167
                                intent.putExtra("is_dui", is_dui);
158
                                intent.putExtra("is_dui", is_dui);
168
                                startActivity(intent);
159
                                startActivity(intent);
169
                                finish();
160
                                finish();
170
//                                mTimer.cancel();
171
                                overridePendingTransition(0, 0);
161
                                overridePendingTransition(0, 0);
172
                            } else {
162
                            } else {
173
                                new Handler().postDelayed(new Runnable() {
163
                                new Handler().postDelayed(new Runnable() {
174
                                    @Override
164
                                    @Override
175
                                    public void run() {
165
                                    public void run() {
176
                                        startActivity(new Intent(WelcomeActivity.this,
177
                                                MainMapActivity.class));
166
                                        startActivity(new Intent(WelcomeActivity.this, MainMapActivity.class));
178
                                        finish();
167
                                        finish();
179
//                                        mTimer.cancel();
180
                                    }
168
                                    }
181
                                }, 2000);
169
                                }, 2000);
182
                            }
170
                            }
215
                                MainApplication.huodonglabel = JsonUtils.getKeyResult(s, "meg");
203
                                MainApplication.huodonglabel = JsonUtils.getKeyResult(s, "meg");
216
                            }
204
                            }
217
                        }
205
                        }
218
//                        Toast.makeText(getApplicationContext(),MainApplication.huodonglabel,Toast.LENGTH_SHORT).show();
219
                        if (EmptyUtils.isEmpty(ad)) {
206
                        if (EmptyUtils.isEmpty(ad)) {
220
                            new Handler().postDelayed(new Runnable() {
207
                            new Handler().postDelayed(new Runnable() {
221
                                @Override
208
                                @Override
222
                                public void run() {
209
                                public void run() {
223
//                                    LogUtils.e("123123");
224
                                    startActivity(new Intent(WelcomeActivity.this,
225
                                            MainMapActivity.class));
210
                                    startActivity(new Intent(WelcomeActivity.this, MainMapActivity.class));
226
                                    finish();
211
                                    finish();
227
//                                    mTimer.cancel();
228
                                }
212
                                }
229
                            }, 1000);
213
                            }, 1000);
230
                        }
214
                        }
253
                                intent.putExtra("icon", icon);
237
                                intent.putExtra("icon", icon);
254
                                intent.putExtra("title", title);
238
                                intent.putExtra("title", title);
255
                                intent.putExtra("is_dui", is_dui);
239
                                intent.putExtra("is_dui", is_dui);
256
                                intent.putExtra("advertiser",advertiser);
240
                                intent.putExtra("advertiser", advertiser);
257
                                startActivity(intent);
241
                                startActivity(intent);
258
                                finish();
242
                                finish();
259
                                overridePendingTransition(0, 0);
243
                                overridePendingTransition(0, 0);
261
                                new Handler().postDelayed(new Runnable() {
245
                                new Handler().postDelayed(new Runnable() {
262
                                    @Override
246
                                    @Override
263
                                    public void run() {
247
                                    public void run() {
264
                                        startActivity(new Intent(WelcomeActivity.this,
265
                                                MainMapActivity.class));
248
                                        startActivity(new Intent(WelcomeActivity.this, MainMapActivity.class));
266
                                        finish();
249
                                        finish();
267
                                    }
250
                                    }
268
                                }, 2000);
251
                                }, 2000);
309
            viewPager = (ViewPager) findViewById(R.id.viewpager);
292
            viewPager = (ViewPager) findViewById(R.id.viewpager);
310
            viewPager.setVisibility(View.VISIBLE);
293
            viewPager.setVisibility(View.VISIBLE);
311
            views = new ArrayList<View>();
294
            views = new ArrayList<View>();
312
            one = LayoutInflater.from(this).inflate(
313
                    R.layout.viewpager_guide_one, null);
314
            two = LayoutInflater.from(this).inflate(
315
                    R.layout.viewpager_guide_two, null);
316
            three = LayoutInflater.from(this).inflate(
317
                    R.layout.viewpager_guide_three, null);
318
            four = LayoutInflater.from(this).inflate(
319
                    R.layout.viewpager_guide_four, null);
295
            one = LayoutInflater.from(this).inflate(R.layout.viewpager_guide_one, null);
296
            two = LayoutInflater.from(this).inflate(R.layout.viewpager_guide_two, null);
297
            three = LayoutInflater.from(this).inflate(R.layout.viewpager_guide_three, null);
298
            four = LayoutInflater.from(this).inflate(R.layout.viewpager_guide_four, null);
320
            enter = (ImageView) four.findViewById(R.id.bt_enter);
299
            enter = (ImageView) four.findViewById(R.id.bt_enter);
321
            enter.setOnClickListener(this);
300
            enter.setOnClickListener(this);
322

301

373
                    }
352
                    }
374
                    socket = new Socket(host, 9503);
353
                    socket = new Socket(host, 9503);
375
                    // 向服务器发送消息
354
                    // 向服务器发送消息
376
                    PrintWriter out = new PrintWriter(new BufferedWriter(
377
                            new OutputStreamWriter(socket.getOutputStream())), true);
355
                    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
378
                    out.println(params);
356
                    out.println(params);
379
                    // out.println("{\"fun\":\"getcity\"}");
357
                    // out.println("{\"fun\":\"getcity\"}");
380
                    // 接收来自服务器的消息
358
                    // 接收来自服务器的消息
381
                    BufferedReader br = new BufferedReader(new InputStreamReader(
382
                            socket.getInputStream()));
359
                    BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
383

360

384
                    String msg = br.readLine();
361
                    String msg = br.readLine();
385
//                    Log.d("dddddss",msg);
386
                    String token = msg;
362
                    String token = msg;
387
//                    Log.e("msg_init", msg);
388
                    int time = (int) (System.currentTimeMillis() / 1000);
363
                    int time = (int) (System.currentTimeMillis() / 1000);
389

364

390
                    MainMapActivity.cha = time - Integer.parseInt(msg);
365
                    MainMapActivity.cha = time - Integer.parseInt(msg);
396
                    initParams.append(",\"h\":\"" + Utils.getScreenHeight(WelcomeActivity.this) + "\"");
371
                    initParams.append(",\"h\":\"" + Utils.getScreenHeight(WelcomeActivity.this) + "\"");
397
                    initParams.append(",\"version_name\":\"" + BuildConfig.VERSION_NAME + "\"");
372
                    initParams.append(",\"version_name\":\"" + BuildConfig.VERSION_NAME + "\"");
398
                    initParams.append(",\"version_code\":\"" + BuildConfig.VERSION_CODE + "\"");
373
                    initParams.append(",\"version_code\":\"" + BuildConfig.VERSION_CODE + "\"");
399
                    initParams.append(",\"os\":\"android "+ Build.VERSION.RELEASE +"\""); // 操作系统及版本
374
                    initParams.append(",\"os\":\"android " + Build.VERSION.RELEASE + "\""); // 操作系统及版本
400
                    initParams.append(",\"brand\":\"" + Build.BRAND + "\""); // 品牌
375
                    initParams.append(",\"brand\":\"" + Build.BRAND + "\""); // 品牌
401
                    initParams.append(",\"model\":\"" + Build.MODEL + "\""); // 型号
376
                    initParams.append(",\"model\":\"" + Build.MODEL + "\""); // 型号
402
                    initParams.append("}");
377
                    initParams.append("}");
422
                        host = "59.110.68.162";
397
                        host = "59.110.68.162";
423
                    }
398
                    }
424
                    socket = new Socket(host, 9503); // IP:10.14.114.127,端口54321
399
                    socket = new Socket(host, 9503); // IP:10.14.114.127,端口54321
425
//                    SocketAddress socAddress = new InetSocketAddress("cdz.d1ev.com", 9503);
426
//                    socket.connect(socAddress, 5000);
427
                    // 向服务器发送消息
400
                    // 向服务器发送消息
428
                    PrintWriter out = new PrintWriter(new BufferedWriter(
429
                            new OutputStreamWriter(socket.getOutputStream())), true);
401
                    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
430
                    out.println(params);
402
                    out.println(params);
431
                    // out.println("{\"fun\":\"getcity\"}");
432
                    // 接收来自服务器的消息
403
                    // 接收来自服务器的消息
433
                    BufferedReader br = new BufferedReader(new InputStreamReader(
434
                            socket.getInputStream()));
435

436

404
                    BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
437
                    String msg = br.readLine();
405
                    String msg = br.readLine();
438
                    if (msg != null) {
406
                    if (msg != null) {
439
                        Message mes = new Message();
407
                        Message mes = new Message();
442
                        handler.sendMessage(mes);
410
                        handler.sendMessage(mes);
443
                        mTimer.cancel();
411
                        mTimer.cancel();
444
                    }
412
                    }
445

446

447
                } catch (Exception e) {
413
                } catch (Exception e) {
448
                    e.printStackTrace();
414
                    e.printStackTrace();
449

450
                }
415
                }
451
            }
416
            }
452
        }).start();
417
        }).start();
453

454
    }
418
    }
455

419

456

420

478
        Drawable drawable = null;
442
        Drawable drawable = null;
479
        try {
443
        try {
480
            // 可以在这里通过文件名来判断,是否本地有此图片
444
            // 可以在这里通过文件名来判断,是否本地有此图片
481

482
            drawable = Drawable.createFromStream(
483
                    new URL(imageUrl).openStream(), "adout.jpg");
484

445
            drawable = Drawable.createFromStream(new URL(imageUrl).openStream(), "adout.jpg");
485
            Message msg = new Message();
446
            Message msg = new Message();
486
            msg.obj = drawable;
447
            msg.obj = drawable;
487
            msg.what = 19;
448
            msg.what = 19;
488
            handler.sendMessage(msg);
449
            handler.sendMessage(msg);
489

490

491
        } catch (IOException e) {
450
        } catch (IOException e) {
492
            Log.d("test", e.getMessage());
451
            Log.d("test", e.getMessage());
493
        }
452
        }
501
    }
460
    }
502

461

503

462

504

505
    public void saveBitmap(Bitmap mBitmap) {
463
    public void saveBitmap(Bitmap mBitmap) {
506
        String dir_path = Environment.getExternalStorageDirectory() + File.separator + "d1ev/";
464
        String dir_path = Environment.getExternalStorageDirectory() + File.separator + "d1ev/";
507
        File directory = new File(dir_path);
465
        File directory = new File(dir_path);
542
                    long appTime1 = System.currentTimeMillis() / 1000;
500
                    long appTime1 = System.currentTimeMillis() / 1000;
543
                    long updatetime = appTime1 - 7200;
501
                    long updatetime = appTime1 - 7200;
544
                    String token = String.valueOf(updatetime);
502
                    String token = String.valueOf(updatetime);
545

546
                    String replace = URLEncoder.encode(DES3.encode(token));
503
                    String replace = URLEncoder.encode(DES3.encode(token));
547

548
                    url = MainApplication.url + "/zhannew/basic/web/index.php/ad/get?timer=" + replace;
504
                    url = MainApplication.url + "/zhannew/basic/web/index.php/ad/get?timer=" + replace;
549

550
                } catch (Exception e) {
505
                } catch (Exception e) {
551
                    e.printStackTrace();
506
                    e.printStackTrace();
552
                }
507
                }
575
                    msg.obj = json;
530
                    msg.obj = json;
576
                    msg.what = 1;
531
                    msg.what = 1;
577
                    handler.sendMessage(msg);
532
                    handler.sendMessage(msg);
578
                    Log.e("url", json);
579
//                    Log.i("token解密:", DES3.decode(encode_token));
580
                } catch (Exception e) {
533
                } catch (Exception e) {
581
                    e.printStackTrace();
534
                    e.printStackTrace();
582
                    Message msg = new Message();
535
                    Message msg = new Message();
628
        String operator = ProfileManager.getInstance().getKeyOperator(getApplicationContext());
581
        String operator = ProfileManager.getInstance().getKeyOperator(getApplicationContext());
629
        String localOperators = "";
582
        String localOperators = "";
630
        if (StringUtils.isEmpty(operator)) {
583
        if (StringUtils.isEmpty(operator)) {
631
//            LogUtils.e("读取本地");
632
            localOperators = getResources().getString(R.string.app_operator_list);
584
            localOperators = getResources().getString(R.string.app_operator_list);
633
        } else {
585
        } else {
634
//            LogUtils.e("读取缓存");
635
            localOperators = operator;
586
            localOperators = operator;
636
        }
587
        }
637
        Gson gson = new Gson();
588
        Gson gson = new Gson();
661
                if (code.equals("200")) {
612
                if (code.equals("200")) {
662
                    String data = JsonUtils.getKeyResult(response, "data");
613
                    String data = JsonUtils.getKeyResult(response, "data");
663
                    ProfileManager.getInstance().setAppOperator(getApplicationContext(), data);
614
                    ProfileManager.getInstance().setAppOperator(getApplicationContext(), data);
664
//                    LogUtils.e(ProfileManager.getInstance().getKeyOperator(getApplicationContext()));
665
                    Gson gson = new Gson();
615
                    Gson gson = new Gson();
666
                    ll = gson.fromJson(data, new TypeToken<List<OperatorData>>() {
616
                    ll = gson.fromJson(data, new TypeToken<List<OperatorData>>() {
667
                    }.getType());
617
                    }.getType());
676
    }
626
    }
677

627

678
    @Override
628
    @Override
679
    public void onRequestPermissionsResult(int requestCode,
680
                                           @NonNull String[] permissions,
681
                                           @NonNull int[] grantResults) {
629
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
682
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
630
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
683
        // EasyPermissions handles the request result.
631
        // EasyPermissions handles the request result.
684
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
632
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
686

634

687
    @Override
635
    @Override
688
    public void onPermissionsGranted(int requestCode, List<String> perms) {
636
    public void onPermissionsGranted(int requestCode, List<String> perms) {
689
        LogUtils.e("onPermissionsGranted");
690
        for (String s : perms) {
637
        for (String s : perms) {
691
            if (s.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
638
            if (s.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
692
                new Handler().postDelayed(new Runnable() {
639
                new Handler().postDelayed(new Runnable() {
702

649

703
    @Override
650
    @Override
704
    public void onPermissionsDenied(int requestCode, List<String> perms) {
651
    public void onPermissionsDenied(int requestCode, List<String> perms) {
705
        LogUtils.e("onPermissionsDenied");
706
        for (String s : perms) {
652
        for (String s : perms) {
707
            if (s.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
653
            if (s.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
708
                AlertDialog.Builder builder = new AlertDialog.Builder(WelcomeActivity.this);
654
                AlertDialog.Builder builder = new AlertDialog.Builder(WelcomeActivity.this);
722
            }
668
            }
723
            break;
669
            break;
724
        }
670
        }
725

726

727
    }
671
    }
728

672

729
    @AfterPermissionGranted(RC_CAMERA_PERM)
673
    @AfterPermissionGranted(RC_CAMERA_PERM)
730
    public void cameraTask() {
674
    public void cameraTask() {
731
        if (isPermissionOK()) {
675
        if (isPermissionOK()) {
732
            // Have permission, do the thing!
733
//            Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
734
//            ifTimeout();
735
        } else {
676
        } else {
736
            // Ask for one permission
677
            // Ask for one permission
737
            EasyPermissions.requestPermissions(
678
            EasyPermissions.requestPermissions(
754
                }
695
                }
755
            }, 1000);
696
            }, 1000);
756
            // Have permission, do the thing!
697
            // Have permission, do the thing!
757
//            Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
758
//            ifTimeout();
759
        } else {
698
        } else {
760
            // Ask for one permission
699
            // Ask for one permission
761
            EasyPermissions.requestPermissions(
700
            EasyPermissions.requestPermissions(
804
            }
743
            }
805
        }
744
        }
806
    }
745
    }
807

808

809
}
746
}

+ 13 - 0
app/src/main/java/com/electric/chargingpile/wxapi/WXEntryActivity.java

12
import android.os.Bundle;
12
import android.os.Bundle;
13
import android.os.PersistableBundle;
13
import android.os.PersistableBundle;
14
import android.widget.Toast;
14
import android.widget.Toast;
15
16
import com.tencent.mm.opensdk.constants.ConstantsAPI;
17
import com.tencent.mm.opensdk.modelbase.BaseResp;
18
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
19
15
import cn.sharesdk.wechat.utils.WXAppExtendObject;
20
import cn.sharesdk.wechat.utils.WXAppExtendObject;
16
import cn.sharesdk.wechat.utils.WXMediaMessage;
21
import cn.sharesdk.wechat.utils.WXMediaMessage;
17
import cn.sharesdk.wechat.utils.WechatHandlerActivity;
22
import cn.sharesdk.wechat.utils.WechatHandlerActivity;
57
        }
62
        }
58
    }
63
    }
59
64
65
    public void onResp(BaseResp resp) {
66
        if (resp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {
67
            WXLaunchMiniProgram.Resp launchMiniProResp = (WXLaunchMiniProgram.Resp) resp;
68
            String extraData = launchMiniProResp.extMsg;
69
            System.out.println(extraData);
70
        }
71
    }
72
60
73
61
}
74
}

+ 4 - 1
app/src/main/res/layout/activity_welcome.xml

1
<?xml version="1.0" encoding="utf-8"?>
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:tools="http://schemas.android.com/tools"
3
    android:id="@+id/rl_welcome"
4
    android:id="@+id/rl_welcome"
4
    android:layout_width="match_parent"
5
    android:layout_width="match_parent"
5
    android:layout_height="match_parent">
6
    android:layout_height="match_parent">
12
        android:layout_centerVertical="true"
13
        android:layout_centerVertical="true"
13
        android:background="#ffffff"
14
        android:background="#ffffff"
14
        android:orientation="vertical">
15
        android:orientation="vertical">
16

15
        <ImageView
17
        <ImageView
16
            android:id="@+id/img_welcome"
18
            android:id="@+id/img_welcome"
17
            android:layout_width="160dp"
19
            android:layout_width="160dp"
20
            android:layout_marginTop="240dp"
22
            android:layout_marginTop="240dp"
21
            android:contentDescription="@null"
23
            android:contentDescription="@null"
22
            android:src="@drawable/bg_welcome_text"
24
            android:src="@drawable/bg_welcome_text"
23
            android:visibility="visible" />
25
            android:visibility="visible"
26
            tools:visibility="gone" />
24
    </LinearLayout>
27
    </LinearLayout>
25
    <!-- logo end    -->
28
    <!-- logo end    -->
26

29