package io.github.plastix.forage.util;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;

public class ActivityUtils {

    private ActivityUtils() {
        throw new UnsupportedOperationException("No Instantiation!");
    }

    /**
     * Returns an intent for launching the application settings for the app with the specified activity.
     *
     * @param activity Activity of app to launch settings for.
     * @return Intent object.
     */
    public static Intent getApplicationSettingsIntent(@NonNull Activity activity) {
        Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + activity.getPackageName()));
        return intent;
    }

    /**
     * Overloaded version of {@link #setSupportActionBarTitle(Activity, String)}.
     *
     * @param activity Activity to set action bar on.
     * @param titleID  String ID of title.
     */
    public static void setSupportActionBarTitle(@NonNull Activity activity, @StringRes int titleID) {
        setSupportActionBarTitle(activity, activity.getString(titleID));
    }

    /**
     * Sets the support action bar title for the specified activity.
     *
     * @param activity Activity to set action bar on. Must be a {@link AppCompatActivity}.
     * @param title    String title to set.
     */
    public static void setSupportActionBarTitle(@NonNull Activity activity, String title) {
        ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(title);
        }
    }

    /**
     * Sets the support action bar back button. The activity still has to manage the back button
     * event correctly!
     *
     * @param delegate AppCompatDelegate for the AppCompatActivity you want to modify.
     */
    public static void setSupportActionBarBack(@NonNull AppCompatDelegate delegate) {
        ActionBar bar = delegate.getSupportActionBar();
        if (bar != null) {
            delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
            delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

}

package io.github.plastix.forage.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;

public class ActivityUtils {

    private ActivityUtils() {
        throw new UnsupportedOperationException("No Instantiation!");
    }

    /**
     * Returns an intent for launching the application settings for the app with the specified activity.
     *
     * @param context Context instance
     * @return Intent object.
     */
    public static Intent getApplicationSettingsIntent(@NonNull Context context) {
        Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + context.getPackageName()));

        return intent;
    }

    /**
     * Overloaded version of {@link #setSupportActionBarTitle(Activity, String)}.
     *
     * @param activity Activity to set action bar on.
     * @param titleID  String ID of title.
     */
    public static void setSupportActionBarTitle(@NonNull Activity activity, @StringRes int titleID) {
        setSupportActionBarTitle(activity, activity.getString(titleID));
    }

    /**
     * Sets the support action bar title for the specified activity.
     *
     * @param activity Activity to set action bar on. Must be a {@link AppCompatActivity}.
     * @param title    String title to set.
     */
    public static void setSupportActionBarTitle(@NonNull Activity activity, String title) {
        ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(title);
        }
    }

    /**
     * Sets the support action bar back button. The activity still has to manage the back button
     * event correctly!
     *
     * @param delegate AppCompatDelegate for the AppCompatActivity you want to modify.
     */
    public static void setSupportActionBarBack(@NonNull AppCompatDelegate delegate) {
        ActionBar bar = delegate.getSupportActionBar();
        if (bar != null) {
            delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
            delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

}

Switch getApplicationSettingsIntent to take in a Context