导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - NoInternetActivity.java 源代码

正在查看: Clash Legends v0.0.1 应用的 NoInternetActivity.java JAVA 源代码文件

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


package com.clash.legends.ui.activities;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.clash.legends.utils.LocaleHelper;
import java.util.List;

public class NoInternetActivity extends AppCompatActivity {
    TextView appname;
    Context context;
    boolean internet = true;
    TextView nointernetconection;
    Resources resources;

    public static boolean isAppRunning(Context context, String packageName) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
        if (procInfos != null) {
            for (ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
                if (processInfo.processName.equals(packageName)) {
                    return true;
                }
            }
            return false;
        }
        return false;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(2131558464);
        Context locale = LocaleHelper.setLocale(this);
        this.context = locale;
        this.resources = locale.getResources();
        this.nointernetconection = (TextView) findViewById(2131362836);
        TextView textView = (TextView) findViewById(2131361948);
        this.appname = textView;
        textView.setText(this.resources.getString(2131886168));
        this.nointernetconection.setText(this.resources.getString(2131886628));
        final Handler tipsHanlder = new Handler();
        Runnable tipsRunnable = new Runnable() {
            @Override
            public void run() {
                tipsHanlder.postDelayed(this, 1000L);
                if (NoInternetActivity.isAppRunning(NoInternetActivity.this.getApplicationContext(), NoInternetActivity.this.getPackageName())) {
                    NoInternetActivity noInternetActivity = NoInternetActivity.this;
                    if (noInternetActivity.isAppOnForeground(noInternetActivity.getApplicationContext(), NoInternetActivity.this.getPackageName())) {
                        if (!NoInternetActivity.this.isNetworkAvailable()) {
                            NoInternetActivity.this.internet = true;
                        } else if (NoInternetActivity.this.internet) {
                            NoInternetActivity.this.internet = false;
                            Intent intent = new Intent(NoInternetActivity.this.getApplicationContext(), (Class<?>) FirstActivity.class);
                            NoInternetActivity.this.startActivity(intent);
                        }
                    }
                }
            }
        };
        tipsHanlder.post(tipsRunnable);
    }

    public boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public boolean isAppOnForeground(Context context, String appPackageName) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
        if (appProcesses == null) {
            return false;
        }
        for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
            if (appProcess.importance == 100 && appProcess.processName.equals(appPackageName)) {
                return true;
            }
        }
        return false;
    }
}