Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;

public class Main {
    /**
     * Helper method where either the application will open the {@link Settings#ACTION_APPLICATION_DETAILS_SETTINGS}
     * or {@link Settings#ACTION_MANAGE_APPLICATIONS_SETTINGS}
     *
     * @param context
     * @return
     */
    public static Intent getLaunchSettingsIntent(Context context) {
        Intent intent;
        try {
            // Direct the user to the application detail page where they can change the permissions.
            intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setData(Uri.parse("package:" + context.getPackageName()));
        } catch (ActivityNotFoundException e) {
            // Fails take then to the all applications screen.
            intent = new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
        }
        return intent;
    }
}