Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;

public class Main {

    public static final void openGPS(Context context) {
        try {
            if (!isOpenGPS(context)) {
                Intent GPSIntent = new Intent();
                GPSIntent.setClassName("com.android.settings",
                        "com.android.settings.widget.SettingsAppWidgetProvider");
                GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
                GPSIntent.setData(Uri.parse("custom:3"));
                PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean isOpenGPS(Context context) {
        LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (!alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
            return false;
        }
        return true;
    }
}