<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ty.sql.dqwgsw">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/icon"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/Theme.AppCompat.NoActionBar" >
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>


// android:theme=“@style/Theme.AppCompat.NoActionBar” 安卓在新建完成项目之后会有一个标题栏,把这个标题栏去掉。
// android:usesCleartextTraffic=“true” //要加上这句话啊 允许明文访问,自从Android 6.0(API级别23)开始,Android操作系统默认不允许应用程序使用明文,以增强网络安全性和用户数据的保护。然而,有些应用可能需要连接到不支持HTTPS的旧服务器,或者是在开发过程中需要使用明文传输来方便调试。在这种情况下,开发者可以在应用的AndroidManifest.xml中设置android:usesCleartextTraffic=“true”,这样系统就会允许该应用使用明文。

注意:有些页面在存在跨域请求。要设置允许跨域。还有存储。比如localStorage的存储。允许网络访问等

package ty.sql.dqwgsw;

import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {
    private static final int MY_PERMISSIONS_REQUEST_INTERNET = 1;
    private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
    private WebView myWebView = null;
    private SendingProgressDialog m_progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); // 不显示是程序的标题栏

        setContentView(R.layout.activity_main);

       //设置沉浸式的通知状态栏  并且状态栏的高度没有了。
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

//        //把状态栏设置成透明的
//        View decorView = getWindow().getDecorView();
//        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);



      //  getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,WindowManager.LayoutParams. FLAG_FULLSCREEN); //设置全屏

// 如果你的应用面向Android 6.0 (API level 23)或以上版本,还需要在运行时请求权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET)
                    != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.INTERNET},
                        MY_PERMISSIONS_REQUEST_INTERNET);
                // 处理用户响应的回调方法
                // @Override
                // public void onRequestPermissionsResult(int requestCode,
                //         String[] permissions, int[] grantResults) {
                //     if (requestCode == MY_PERMISSIONS_REQUEST_INTERNET) {
                //         if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //             // 权限被授予
                //         }
                //     }
                // }
            }
        }

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
        }

        
        

        myWebView = (WebView) findViewById(R.id.homeView);

        CookieManager.getInstance().removeAllCookie();
        WebSettings webSettings = myWebView.getSettings();//获得webSettings设置对象
        //下面3行是WebView支持JS并能够和JS代码间进行交互的设置

        webSettings.setDomStorageEnabled(true); //开启localStorage存储
        webSettings.setAllowFileAccess(true);


        
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(false);

        //设置为ChromeClinet 才能执行js代码
        WebChromeClient webChromeClient = new WebChromeClient();
        myWebView.setWebChromeClient(webChromeClient);


        webSettings.setBuiltInZoomControls(false);
        webSettings.setPluginState(WebSettings.PluginState.ON);//这里是支持flash的相关设置
        // 设置允许文件访问
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true); //允许跨域请求
        myWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        myWebView.getSettings().setSupportMultipleWindows(true);
        myWebView.setWebContentsDebuggingEnabled(true); //调试模式
        MyWebViewClient mWebClient = new MyWebViewClient();
        myWebView.setWebViewClient(mWebClient);//向WebView提供一个WebViewClient,这样就可以在你的WebView中打开链接了
        /*myWebView.setWebChromeClient(new myChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                setProgress(progress * 100);
            }
        });*/
   //     myWebView.loadUrl("file:///android_asset/www/login.html");
        myWebView.loadUrl("file:///android_asset/www/dist/indexLogin.html");
    }

    private class MyWebViewClient extends WebViewClient
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.indexOf("tel:") >= 0) {// 页面上有数字会导致系统会自动连接电话,屏蔽此功能
                return true;
            }
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (m_progressDialog != null) {
                m_progressDialog.stop();
            }
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            try {
                initSendingDialog("正在加载网页,请稍后...");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    protected void initSendingDialog(String message) {
        // TODO Auto-generated method stub
        if (m_progressDialog == null) {
            m_progressDialog = new SendingProgressDialog(this, message);
        }
        m_progressDialog.start();
    }

    /**
     * 按键响应,在WebView中查看网页时,按返回键的时候按浏览历史退回,如果不做此项处理则整个WebView返回退出
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack())
        {
            // 返回键退回
            myWebView.goBack();//返回上一个历史网页
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}

//下面是

//新建一个SendingProgressDialog.java 的类 文件。



package ty.sql.dqwgsw;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.KeyEvent;

/**
 * @author sang
 * @version 创建时间:2014-7-10 上午9:25:00 类说明
 */
public class SendingProgressDialog {
    public ProgressDialog dialog;
    private final String message = "正在发送中,请稍候...";

    public SendingProgressDialog(Context paramContext) {
        this(paramContext, null);
    }

    public SendingProgressDialog(Context paramContext, String paramString) {

        dialog = new ProgressDialog(paramContext){

            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {
                if(this.isShowing()){
                    return false;
                }
                return super.onKeyDown(keyCode, event);
            }

        };
        this.dialog.setCancelable(true);
        if (paramString == null) {
            this.dialog.setMessage(message);
        } else {
            this.dialog.setMessage(paramString);
        }
    }

    public void start() {
        try {
            this.dialog.show();
        } catch (Exception e) {
        }

    }

    public void stop() {
        try {
            if (this.dialog != null) {
                this.dialog.dismiss();
                this.dialog.cancel();
            }
        } catch (Exception e) {
        }
    }
}

//在activity_main.xml 中 添加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" >

    <WebView
        android:id="@+id/homeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

//在build.gradle 中 minifyEnabled true proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’ 设置代码混淆 并在proguard-rules.pro文件中添加最下面的代码。


plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 33
    buildToolsVersion "33.0.2"

    defaultConfig {
        applicationId "ty.sql.dqwgsw"
        minSdkVersion 19
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true  
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

//proguard-rules.pro 文件中填写的代码




# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

#指定代码的压缩级别
-optimizationpasses 5

#包明不混合大小写
-dontusemixedcaseclassnames

#不去忽略非公共的库类
-dontskipnonpubliclibraryclasses

#优化 不优化输入的类文件
-dontoptimize

#预校验
-dontpreverify

#混淆时是否记录日志
-verbose

# 混淆时所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

#保护注解
-keepattributes *Annotation*

# 保持哪些类不被混淆
-keep public class * extends android.app.Fragment
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
#如果有引用v4包可以添加下面这行
-keep public class * extends android.support.v4.app.Fragment

#忽略警告
-ignorewarning

##记录生成的日志数据,gradle build时在本项目根目录输出##

#apk 包内所有 class 的内部结构
-dump class_files.txt
#未混淆的类和成员
-printseeds seeds.txt
#列出从 apk 中删除的代码
-printusage unused.txt
#混淆前后的映射
-printmapping mapping.txt

########记录生成的日志数据,gradle build时 在本项目根目录输出-end######

#####混淆保护自己项目的部分代码以及引用的第三方jar包library#######

#-libraryjars libs/umeng-analytics-v5.2.4.jar

#三星应用市场需要添加:sdk-v1.0.0.jar,look-v1.0.1.jar
#-libraryjars libs/sdk-v1.0.0.jar
#-libraryjars libs/look-v1.0.1.jar


#如果不想混淆 keep 掉
-keep class com.lippi.recorder.iirfilterdesigner.** {*; }
#友盟
-keep class com.umeng.**{*;}
#项目特殊处理代码

#忽略警告
-dontwarn com.lippi.recorder.utils**
#保留一个完整的包
-keep class com.lippi.recorder.utils.** {
     *;
}

-keep class com.lippi.recorder.utils.AudioRecorder{*;}

#如果引用了v4或者v7包
-dontwarn android.support.**

####混淆保护自己项目的部分代码以及引用的第三方jar包library-end####

-keep public class * extends android.view.View {
     public <init>(android.content.Context);
     public <init>(android.content.Context, android.util.AttributeSet);
     public <init>(android.content.Context, android.util.AttributeSet, int);
     public void set*(...);
}

#保持 native 方法不被混淆
-keepclasseswithmembernames class * {
     native <methods>;
}

#保持自定义控件类不被混淆
-keepclasseswithmembers class * {
     public <init>(android.content.Context, android.util.AttributeSet);
}

#保持自定义控件类不被混淆
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}

#保持 Parcelable 不被混淆
-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

#保持 Serializable 不被混淆
-keepnames class * implements java.io.Serializable

#保持 Serializable 不被混淆并且enum 类也不被混淆
-keepclassmembers class * implements java.io.Serializable {
     static final long serialVersionUID;
     private static final java.io.ObjectStreamField[] serialPersistentFields;
     !static !transient <fields>;
     !private <fields>;
     !private <methods>;
     private void writeObject(java.io.ObjectOutputStream);
     private void readObject(java.io.ObjectInputStream);
     java.lang.Object writeReplace();
     java.lang.Object readResolve();
}


#保持枚举 enum 类不被混淆 如果混淆报错,建议直接使用上面的 -keepclassmembers class * implements java.io.Serializable即可
#-keepclassmembers enum * {
# public static **[] values();
# public static ** valueOf(java.lang.String);
#}

-keepclassmembers class * {
     public void *ButtonClicked(android.view.View);
}


#不混淆资源类
-keepclassmembers class **.R$* {
     public static <fields>;
}

#避免混淆泛型 如果混淆报错建议关掉
#–keepattributes Signature

#移除log 测试了下没有用还是建议自己定义一个开关控制是否输出日志
#-assumenosideeffects class android.util.Log {
#  public static boolean isLoggable(java.lang.String, int);
#  public static int v(...);
#  public static int i(...);
#  public static int w(...);
#  public static int d(...);
#  public static int e(...);
#}

#如果用用到Gson解析包的,直接添加下面这几行就能成功混淆,不然会报错。
#gson
#-libraryjars libs/gson-2.2.2.jar
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

把vue打包好的dist文件放在这里
在这里插入图片描述

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部