Example usage for android.app Activity getBaseContext

List of usage examples for android.app Activity getBaseContext

Introduction

In this page you can find the example usage for android.app Activity getBaseContext.

Prototype

public Context getBaseContext() 

Source Link

Usage

From source file:Main.java

public static void startNewActivity(Activity origin, Class<? extends Activity> newActivity, Bundle bundle) {
    Intent intent = new Intent(origin.getBaseContext(), newActivity);
    if (bundle != null)
        intent.putExtras(bundle);/*from   ww  w .j  a v  a  2s  .  c  o m*/
    origin.startActivity(intent);
}

From source file:Main.java

public static void restartApp(Activity activity) {
    if (activity == null) {
        return;//from  w  ww.j a  v a2  s  .  co m
    }
    Intent i = activity.getBaseContext().getPackageManager()
            .getLaunchIntentForPackage(activity.getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(i);
    activity.finish();
}

From source file:com.ap.github.utils.ToastUtils.java

public static void showToastOnSubThread(@NonNull Activity activity, @NonNull String content) {
    activity.runOnUiThread(() -> Toast.makeText(activity.getBaseContext(), content, Toast.LENGTH_SHORT).show());
}

From source file:com.ap.github.utils.ToastUtils.java

public static void showToastOnSubThread(@NonNull Activity activity, @StringRes int stringResId) {
    activity.runOnUiThread(//from   ww  w  .  ja v a2s .c  om
            () -> Toast.makeText(activity.getBaseContext(), stringResId, Toast.LENGTH_SHORT).show());
}

From source file:com.canking.sdcardhelper.PermissionUtils.java

/**
 * ??//  www .  j  a v  a 2  s. co  m
 *
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static <C extends Context> boolean checkSettingAlertPermission(Activity cxt, int req, C t) {
    Activity activity = (Activity) cxt;
    if (!Settings.canDrawOverlays(activity.getBaseContext())) {
        Log.i(TAG, "Setting not permission");

        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + activity.getPackageName()));
        activity.startActivityForResult(intent, req);
        return false;
    }

    return true;
}

From source file:com.youshe.yangyi.common_app.util.PermissionUtils.java

/**
 * ??//from w  w  w  . j a v a  2  s  .  c om
 *
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static boolean checkSettingAlertPermission(Object cxt, int req) {
    if (cxt instanceof Activity) {
        Activity activity = (Activity) cxt;
        if (!Settings.canDrawOverlays(activity.getBaseContext())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + activity.getPackageName()));
            activity.startActivityForResult(intent, req);
            return false;
        }
    } else if (cxt instanceof Fragment) {
        Fragment fragment = (Fragment) cxt;
        if (!Settings.canDrawOverlays(fragment.getActivity())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + fragment.getActivity().getPackageName()));
            fragment.startActivityForResult(intent, req);
            return false;
        }
    } else {
        throw new RuntimeException("cxt is net a activity or fragment");
    }

    return true;
}

From source file:com.hengtiansoft.ecommerce.library.base.util.PermissionUtils.java

/**
 * ??//from w  ww. j av a2  s  . c o m
 *
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static boolean checkSettingAlertPermission(Object cxt, int req) {
    if (cxt instanceof Activity) {
        Activity activity = (Activity) cxt;
        if (!Settings.canDrawOverlays(activity.getBaseContext())) {
            LogUtil.i("Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + activity.getPackageName()));
            activity.startActivityForResult(intent, req);
            return false;
        }
    } else if (cxt instanceof Fragment) {
        Fragment fragment = (Fragment) cxt;
        if (!Settings.canDrawOverlays(fragment.getActivity())) {
            LogUtil.i("Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + fragment.getActivity().getPackageName()));
            fragment.startActivityForResult(intent, req);
            return false;
        }
    } else {
        throw new RuntimeException("cxt is net a activity or fragment");
    }

    return true;
}

From source file:com.lvbo.template.common.Utils.PermissionUtils.java

/**
 * ??/*from www  .j  a  v a2  s. c  o  m*/
 *
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static boolean checkSettingAlertPermission(Object cxt, int req) {
    if (cxt instanceof Activity) {
        Activity activity = (Activity) cxt;
        if (!Settings.canDrawOverlays(activity.getBaseContext())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + activity.getPackageName()));
            activity.startActivityForResult(intent, req);
            return false;
        }
    } else if (cxt instanceof Fragment) {
        Fragment fragment = (Fragment) cxt;
        if (!Settings.canDrawOverlays(fragment.getActivity())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + fragment.getActivity().getPackageName()));
            fragment.startActivityForResult(intent, req);
            Context c;
            return false;
        }
    } else {
        throw new RuntimeException("cxt is net a activity or fragment");
    }

    return true;
}

From source file:com.arantius.tivocommander.Utils.java

public final static void toast(Activity activity, int messageId, int length) {
    Context ctx = activity.getBaseContext();
    Toast.makeText(ctx, messageId, length).show();
}

From source file:com.arantius.tivocommander.Utils.java

public final static void toast(Activity activity, String message, int length) {
    Context ctx = activity.getBaseContext();
    Toast.makeText(ctx, message, length).show();
}