导航菜单

页面标题

页面副标题

Cashalo v2.25.0.0 - IntentUtils.java 源代码

正在查看: Cashalo v2.25.0.0 应用的 IntentUtils.java JAVA 源代码文件

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


package com.oriente.adapter.utils;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import androidx.core.content.FileProvider;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import com.oriente.core.page.PageManager;
import com.oriente.core.utils.FileUtils;
import com.oriente.core.utils.StringUtils;
import java.io.File;
import java.util.Iterator;

public class IntentUtils {
    private static final String KEY_HAS_CAMERA_DENY_FOREVER = "key_has_camera_deny_forever";

    public static Intent intentImageCamera(Uri uri) {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        intent.putExtra("output", uri);
        return intent;
    }

    public static Intent intentImageLocal(String str) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction("android.intent.action.GET_CONTENT");
        return str == null ? intent : Intent.createChooser(intent, str);
    }

    public static boolean call(Context context, String str) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.DIAL");
        intent.setData(Uri.parse("tel:" + str));
        return openIntentSafe(context, intent);
    }

    public static boolean openEmail(Context context, String str, String... strArr) {
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType("plain/text");
        intent.putExtra("android.intent.extra.EMAIL", strArr);
        intent.putExtra("android.intent.extra.SUBJECT", "");
        intent.putExtra("android.intent.extra.TEXT", "");
        return openIntentSafe(context, Intent.createChooser(intent, str));
    }

    public static boolean openBrowser(Context context, String str) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setData(Uri.parse(str));
        return openIntentSafe(context, intent);
    }

    public static boolean openImage(Context context, String str) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setDataAndType(Uri.parse("file:///" + str), "image/*");
        return openIntentSafe(context, intent);
    }

    public static boolean openAudio(Context context, String str) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setDataAndType(Uri.parse("file:///" + str), "audio/*");
        return openIntentSafe(context, intent);
    }

    public static boolean openVideo(Context context, String str) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setDataAndType(Uri.parse("file:///" + str), "video/*");
        return openIntentSafe(context, intent);
    }

    public static boolean shareApplication(Context context, String str) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.SEND");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.setType("text/plain");
        intent.putExtra("android.intent.extra.TEXT", str);
        return openIntentSafe(context, intent);
    }

    public static boolean openAirplaneMode(Context context) {
        Intent intent = new Intent();
        intent.setAction("android.settings.AIRPLANE_MODE_SETTINGS");
        return openIntentSafe(context, intent);
    }

    public static boolean openWIFI(Context context) {
        Intent intent = new Intent();
        intent.setAction("android.settings.WIFI_SETTINGS");
        return openIntentSafe(context, intent);
    }

    public static boolean openGPRS(Context context) {
        Intent intent = new Intent("android.settings.LOCATION_SOURCE_SETTINGS");
        intent.addFlags(268435456);
        if (openIntentSafe(context, intent)) {
            return true;
        }
        Intent intent2 = new Intent();
        intent2.setAction("android.settings.WIRELESS_SETTINGS");
        return openIntentSafe(context, intent2);
    }

    public static boolean installApp(Context context, Uri uri, String str) {
        boolean canRequestPackageInstalls;
        Intent intent = new Intent("android.intent.action.VIEW");
        if (uri == null || !uri.toString().endsWith(".apk")) {
            return false;
        }
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(268435456);
        if (Build.VERSION.SDK_INT >= 24) {
            if (Build.VERSION.SDK_INT >= 26) {
                canRequestPackageInstalls = context.getPackageManager().canRequestPackageInstalls();
                if (!canRequestPackageInstalls) {
                    Intent intent2 = new Intent("android.settings.MANAGE_UNKNOWN_APP_SOURCES");
                    intent2.addFlags(268435456);
                    return openIntentSafe(context, intent2);
                }
            }
            Uri uriForFile = FileProvider.getUriForFile(context, str, new File(uri.getPath()));
            intent.addFlags(1);
            intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(uri, "application/vnd.android.package-archive");
        }
        return openIntentSafe(context, intent);
    }

    public static void scanFile(Context context, File file) {
        Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
        intent.setData(Uri.fromFile(file));
        context.sendBroadcast(intent);
    }

    public static boolean openFile(File file) {
        Intent intent = new Intent();
        intent.addFlags(268435456);
        intent.setAction("android.intent.action.VIEW");
        intent.setDataAndType(Uri.fromFile(file), FileUtils.getMIMEType(file));
        return openIntentSafe(PageManager.getTopActivity(), intent);
    }

    public static boolean openSetting(Context context, String str) {
        if (context == null || StringUtils.isInvisibleOrNull(str)) {
            return false;
        }
        try {
            Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
            intent.setData(Uri.parse("package:" + str));
            intent.addFlags(268435456);
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException unused) {
            Intent intent2 = new Intent("android.settings.MANAGE_APPLICATIONS_SETTINGS");
            intent2.addFlags(268435456);
            openIntentSafe(context, intent2);
            return true;
        }
    }

    public static boolean openIntentSafe(Context context, Intent intent) {
        try {
            context.startActivity(intent);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static void startLaunchIntentForPackage(Context context, String str) {
        PackageManager packageManager = context.getPackageManager();
        new Intent();
        Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(str);
        if (launchIntentForPackage == null) {
            return;
        }
        context.startActivity(launchIntentForPackage);
    }

    public static boolean isIntentSafe(Context context, Intent intent) {
        return context.getPackageManager().queryIntentActivities(intent, 0).size() > 0;
    }

    public static boolean isPackageExist(Context context, String str) {
        Iterator<PackageInfo> it = context.getPackageManager().getInstalledPackages(UserMetadata.MAX_INTERNAL_KEY_SIZE).iterator();
        while (it.hasNext()) {
            if (str.endsWith(it.next().packageName)) {
                return true;
            }
        }
        return false;
    }

    public static void startGoogleMap(Context context, String str, String str2, String str3, String str4, String str5) {
        StringBuffer stringBuffer = new StringBuffer("google.navigation:q=");
        if (StringUtils.isNotEmpty(str4)) {
            stringBuffer.append(str4);
        } else {
            stringBuffer.append(str2 + "," + str3);
        }
        if (StringUtils.isNotEmpty(str5)) {
            stringBuffer.append("&mode=" + str5.substring(0, 1).toLowerCase());
        }
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuffer.toString()));
        intent.setPackage(str);
        openIntentSafe(context, intent);
    }

    public static void startWazeMap(Context context, String str, String str2, String str3, String str4, String str5) {
        StringBuffer stringBuffer = new StringBuffer("https://waze.com/ul?navigate=yes");
        if (StringUtils.isNotEmpty(str4)) {
            stringBuffer.append("&q=").append(str4);
        }
        if (StringUtils.isNotEmpty(str2) && StringUtils.isNotEmpty(str3)) {
            stringBuffer.append("&ll=").append(str2 + "," + str3);
        }
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuffer.toString()));
        intent.setPackage(str);
        openIntentSafe(context, intent);
    }
}