package com.example.basecore.util; import android.app.Activity; import android.app.ActivityOptions; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import java.util.List; public class SchemeUtils { public static final String rootUrl = "xll-jct-app://page"; private static final String appScheme = "xll-jct-app"; public static boolean openScheme(Context ctx, String scheme) { openScheme(ctx, scheme, null); return true; } /** * 过渡动画 */ public static boolean openSchemeWithTrans(Activity activity, String scheme) { openScheme(activity, scheme, ActivityOptions.makeSceneTransitionAnimation(activity).toBundle()); return true; } public static boolean openScheme(Context ctx, String scheme, Bundle bundle) { if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(scheme.trim()) || "null".equalsIgnoreCase(scheme)) { return false; } Uri uri = Uri.parse(scheme); if (uri != null) { String sc = uri.getScheme(); if (!appScheme.equalsIgnoreCase(sc)) { return false; } } if (ctx == null) { return false; } Intent intent = new Intent(Intent.ACTION_VIEW, uri); if (bundle != null) { ctx.startActivity(intent, bundle); } else { ctx.startActivity(intent); } return true; } public static boolean openSchemeWithParam(Context ctx, String scheme, Bundle bundle) { if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(scheme.trim()) || "null".equalsIgnoreCase(scheme)) { return false; } Uri uri = Uri.parse(scheme); if (uri != null) { String sc = uri.getScheme(); if (!appScheme.equalsIgnoreCase(sc)) { return false; } } if (ctx == null) { return false; } Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra("bundle", bundle); ctx.startActivity(intent); return true; } }