导航菜单

页面标题

页面副标题

夜猫麻将 v24.1.1 - MLifeWebActivity.java 源代码

正在查看: 夜猫麻将 v24.1.1 应用的 MLifeWebActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mostone.share.sdk.ui;

import android.app.Activity;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.mostone.open.sdk.c.e;
import com.mostone.open.sdk.c.g;
import java.io.File;
import org.xianliao.im.sdk.net.NetBaseReq;

public class MLifeWebActivity extends Activity {
    private static String[] PERMISSIONS_STORAGE = {"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"};
    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private String downloadFile;
    private long downloadId;
    private DownloadCompleteReceiver receiver;

    public class DownloadCompleteReceiver extends BroadcastReceiver {
        public DownloadCompleteReceiver() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            MLifeWebActivity mLifeWebActivity;
            DownloadManager downloadManager = (DownloadManager) context.getSystemService("download");
            if (MLifeWebActivity.this.downloadId != intent.getExtras().getLong("extra_download_id", -1L)) {
                return;
            }
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(MLifeWebActivity.this.downloadId);
            Cursor query2 = downloadManager.query(query);
            if (query2 == null || !query2.moveToFirst()) {
                return;
            }
            if (8 == query2.getInt(query2.getColumnIndex("status"))) {
                Toast.makeText(MLifeWebActivity.this, "app下载完成", 0).show();
                String string = query2.getString(query2.getColumnIndex("local_uri"));
                if (Build.VERSION.SDK_INT <= 23) {
                    String string2 = query2.getString(query2.getColumnIndex("local_filename"));
                    mLifeWebActivity = MLifeWebActivity.this;
                    string = "file://" + string2;
                } else if (string != null) {
                    mLifeWebActivity = MLifeWebActivity.this;
                }
                mLifeWebActivity.installAPP(Uri.parse(string), context);
            }
            query2.close();
        }
    }

    public void installAPP(Uri uri, Context context) {
        try {
            Intent dataAndType = new Intent("android.intent.action.VIEW").setDataAndType(uri, "application/vnd.android.package-archive");
            dataAndType.setFlags(268435456);
            context.startActivity(dataAndType);
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this, "默往下载完成,请手动打开通知栏安装默往", 0).show();
        }
    }

    private void promptInstall(File file) {
    }

    public void gotoUpdate(String str) {
        DownloadManager downloadManager = (DownloadManager) getSystemService("download");
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(str));
        request.setMimeType("application/vnd.android.package-archive");
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "life.apk");
        this.downloadFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator + "life.apk";
        request.setNotificationVisibility(1);
        request.setTitle("下载app");
        request.setVisibleInDownloadsUi(true);
        this.downloadId = downloadManager.enqueue(request);
        if (this.receiver == null) {
            this.receiver = new DownloadCompleteReceiver();
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.DOWNLOAD_COMPLETE");
        registerReceiver(this.receiver, intentFilter);
        Toast.makeText(this, "开始下载app", 0).show();
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        WebView webView = new WebView(this);
        setContentView(webView);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(false);
        settings.setAllowFileAccess(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLoadsImagesAutomatically(true);
        settings.setDefaultTextEncodingName(NetBaseReq.DEFAULT_CHARSET);
        webView.loadUrl(g.a().b("ad", "http://www.mostonetech.com/download"));
        webView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String str, String str2, String str3, String str4, long j) {
                MLifeWebActivity.this.gotoUpdate(str);
            }
        });
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView2, String str) {
                if (!str.startsWith("mostone://life.com")) {
                    webView2.loadUrl(str);
                    return true;
                }
                if (e.b(MLifeWebActivity.this)) {
                    try {
                        Intent intent = new Intent("android.intent.action.VIEW");
                        intent.setData(Uri.parse("mostone://life.com/notice"));
                        MLifeWebActivity.this.startActivity(intent);
                    } catch (Exception e) {
                    }
                }
                return true;
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DownloadCompleteReceiver downloadCompleteReceiver = this.receiver;
        if (downloadCompleteReceiver != null) {
            unregisterReceiver(downloadCompleteReceiver);
        }
    }

    @Override
    protected void onResume() {
        if (getRequestedOrientation() != 1) {
            setRequestedOrientation(1);
        }
        super.onResume();
    }
}