Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sholat.app;
- import android.Manifest;
- import android.app.AlarmManager;
- import android.app.PendingIntent;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.os.Bundle;
- import android.os.Handler;
- import android.support.annotation.Nullable;
- import android.support.v4.app.ActivityCompat;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.Switch;
- import android.widget.TextView;
- import com.sholat.app.location_service.GpsManager;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Set;
- import java.util.TimeZone;
- /**
- * Created by agustinaindah on 22/04/2018.
- */
- public class SetAlarm2Activity extends AppCompatActivity {
- public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
- public TextView mDate, mFajrTime, mDzuhurTime, mAsharTime, mMagribTime, mIsyaTime;
- public Button mSycronLoc;
- public PrayTime prayers;
- public double timezone;
- public Calendar now, Dzuhur, Ashar, Magrib, Isya, Fajr;
- public String dzuhur, ashar, magrib, isya, fajr;
- public ProgressDialog dialog;
- public String[] months = {"Januari", "Februari", "March", "April",
- "Mei", "Juni", "Juli", "Augustus", "September", "Oktober",
- "November", "Desember"};
- public Switch mSwVibrateFajr, mSwSoundFajr, mSwVibrateDzuhur, mSwSoundDzuhur, mSwVibrateAshar,
- mSwSoundAshar, mSwVibrateMagrib, mSwSoundMagrib, mSwVibrateIsya, mSwSoundIsya;
- private boolean withVibrate = false;
- private boolean withSound = false;
- private boolean withVibrateMg = false;
- private boolean withSoundMg = false;
- private boolean withVibrateIs = false;
- private boolean withSoundIs = false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setTitle("Jadwal Sholat");
- setContentView(R.layout.activity_set_alarm2);
- checkLocationPermission();
- mDate = (TextView) findViewById(R.id.txtDate);
- mFajrTime = (TextView) findViewById(R.id.txtFajrTime);
- mDzuhurTime = (TextView) findViewById(R.id.txtDzuhurTime);
- mAsharTime = (TextView) findViewById(R.id.txtAsharTime);
- mMagribTime = (TextView) findViewById(R.id.txtMagribrTime);
- mIsyaTime = (TextView) findViewById(R.id.txtIsyaTime);
- mSycronLoc = (Button) findViewById(R.id.btnSycronLoc);
- mSwVibrateFajr = (Switch) findViewById(R.id.swVibrateFajr);
- mSwSoundFajr = (Switch) findViewById(R.id.swSoundFajr);
- mSwVibrateDzuhur = (Switch) findViewById(R.id.swVibrateDzuhur);
- mSwSoundDzuhur = (Switch) findViewById(R.id.swSoundDzuhur);
- mSwVibrateAshar = (Switch) findViewById(R.id.swVibrateAshar);
- mSwSoundAshar = (Switch) findViewById(R.id.swSoundAshar);
- mSwVibrateMagrib = (Switch) findViewById(R.id.swVibrateMagrib);
- mSwSoundMagrib = (Switch) findViewById(R.id.swSoundMagrib);
- mSwVibrateIsya = (Switch) findViewById(R.id.swVibrateIsya);
- mSwSoundIsya = (Switch) findViewById(R.id.swSoundIsya);
- startAlarm();
- initView();
- initAlarmFajr();
- initAlarmDzuhur();
- initAlarmAshar();
- initAlarmMagrib();
- initAlarmIsya();
- dialog = new ProgressDialog(SetAlarm2Activity.this);
- displayTime();
- mSycronLoc.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- dialog.setMessage("Loading...");
- dialog.show();
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- reload();
- dialog.dismiss();
- }
- }, 1000);
- }
- });
- }
- private void displayTime() {
- Calendar calendar = Calendar.getInstance();
- SimpleDateFormat format = new SimpleDateFormat("EEEE ,d MMMM yyyy");
- mDate.setText(format.format(calendar.getTime()));
- }
- private void initView() {
- mSwVibrateFajr.setChecked(SharedPref.getBoolean(Consts.CBVIBFAJR));
- mSwVibrateFajr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withVibrate = isChecked;
- SharedPref.saveBoolean(Consts.CBVIBFAJR, withVibrate);
- }
- });
- mSwSoundFajr.setChecked(SharedPref.getBoolean(Consts.CBSOUNDFAJR));
- mSwSoundFajr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withSound = isChecked;
- SharedPref.saveBoolean(Consts.CBSOUNDFAJR, withSound);
- }
- });
- mSwVibrateDzuhur.setChecked(SharedPref.getBoolean(Consts.CBVIBDZUHUR));
- mSwVibrateDzuhur.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withVibrate = isChecked;
- SharedPref.saveBoolean(Consts.CBVIBDZUHUR, withVibrate);
- }
- });
- mSwSoundDzuhur.setChecked(SharedPref.getBoolean(Consts.CBSOUNDDZUHUR));
- mSwSoundDzuhur.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withSound = isChecked;
- SharedPref.saveBoolean(Consts.CBSOUNDDZUHUR, withSound);
- }
- });
- mSwVibrateAshar.setChecked(SharedPref.getBoolean(Consts.CBVIBASHAR));
- mSwVibrateAshar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withVibrate = isChecked;
- SharedPref.saveBoolean(Consts.CBVIBASHAR, withVibrate);
- }
- });
- mSwSoundAshar.setChecked(SharedPref.getBoolean(Consts.CBSOUNDASHAR));
- mSwSoundAshar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withSound = isChecked;
- SharedPref.saveBoolean(Consts.CBSOUNDASHAR, withSound);
- }
- });
- //mSwVibrateMagrib.setChecked(SharedPref.getBoolean(Consts.CBVIBMAGRIB));
- mSwVibrateMagrib.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withVibrateMg = isChecked;
- //SharedPref.saveBoolean(Consts.CBVIBMAGRIB, withVibrate);
- }
- });
- //mSwSoundMagrib.setChecked(SharedPref.getBoolean(Consts.CBSOUNDMAGRIB));
- mSwSoundMagrib.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
- withSoundMg = isChecked;
- //SharedPref.saveBoolean(Consts.CBSOUNDMAGRIB, withSound);
- }
- });
- //mSwVibrateIsya.setChecked(SharedPref.getBoolean(Consts.CBVIBISYA));
- mSwVibrateIsya.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- withVibrateIs = isChecked;
- //SharedPref.saveBoolean(Consts.CBVIBISYA, withVibrate);
- }
- });
- //mSwSoundIsya.setChecked(SharedPref.getBoolean(Consts.CBSOUNDISYA));
- mSwSoundIsya.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- withSoundIs = isChecked;
- //SharedPref.saveBoolean(Consts.CBVIBISYA, withSound);
- }
- });
- }
- private void startAlarm() {
- timezone = (Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance().getTimeInMillis())) / (1000 * 60 * 60);
- prayers = new PrayTime();
- prayers.setTimeFormat(prayers.Time24); //format waktu
- prayers.setCalcMethod(prayers.Egypt); //kalulasi menurut
- prayers.setAsrJuristic(prayers.Shafii);
- prayers.setAdjustHighLats(prayers.MidNight);
- prayers.setTimeZone(prayers.getTimeZone());
- prayers.setFajrAngle(21.9);
- prayers.setIshaAngle(18.6);
- int[] offsets = {0, 0, 0, 0, 0, 0, 0}; // {Fajr,Dhuhr,Asr,Maghrib,Isha}
- prayers.tune(offsets);
- now = Calendar.getInstance(TimeZone.getDefault());
- now.setTimeInMillis(System.currentTimeMillis());
- Dzuhur = Calendar.getInstance(TimeZone.getDefault());
- Dzuhur.setTimeInMillis(System.currentTimeMillis());
- Ashar = Calendar.getInstance(TimeZone.getDefault());
- Ashar.setTimeInMillis(System.currentTimeMillis());
- Magrib = Calendar.getInstance(TimeZone.getDefault());
- Magrib.setTimeInMillis(System.currentTimeMillis());
- Isya = Calendar.getInstance(TimeZone.getDefault());
- Isya.setTimeInMillis(System.currentTimeMillis());
- Fajr = Calendar.getInstance(TimeZone.getDefault());
- Fajr.setTimeInMillis(System.currentTimeMillis());
- /*prefsEditor.putLong("Latitude", Double.doubleToLongBits(location.getLatitude()));*/
- GpsManager gpsManager = new GpsManager(SetAlarm2Activity.this);
- gpsManager.checkIfLocationAvailable();
- String lat = String.valueOf(gpsManager.getLatitude());
- String lng = String.valueOf(gpsManager.getLongitude());
- SharedPref.saveString(Consts.LATITUDE, lat);
- SharedPref.saveString(Consts.LONGITUDE, lng);
- double latD = Double.parseDouble(SharedPref.getString(Consts.LATITUDE));
- double lngD = Double.parseDouble(SharedPref.getString(Consts.LONGITUDE));
- if (gpsManager.isLocationEnabled()) {
- ArrayList<String> prayerTimes = prayers.getPrayerTimes(now, latD, lngD, timezone);
- ArrayList<String> prayerNames = prayers.getTimeNames();
- SharedPref.saveString(Consts.FAJR, prayerTimes.get(0));
- SharedPref.saveString(Consts.DHUHR, prayerTimes.get(2));
- SharedPref.saveString(Consts.ASR, prayerTimes.get(3));
- SharedPref.saveString(Consts.MAGHRIB, prayerTimes.get(4));
- SharedPref.saveString(Consts.ISHA, prayerTimes.get(6));
- }
- mFajrTime.setText(SharedPref.getString(Consts.FAJR));
- mDzuhurTime.setText(SharedPref.getString(Consts.DHUHR));
- mAsharTime.setText(SharedPref.getString(Consts.ASR));
- mMagribTime.setText(SharedPref.getString(Consts.MAGHRIB));
- mIsyaTime.setText(SharedPref.getString(Consts.ISHA));
- dzuhur = SharedPref.getString(Consts.DHUHR);
- int jamD = Integer.parseInt(dzuhur.substring(0, 2));
- int menitD = Integer.parseInt(dzuhur.substring(3));
- Dzuhur.set(Calendar.HOUR_OF_DAY, jamD);
- Dzuhur.set(Calendar.MINUTE, menitD);
- Dzuhur.set(Calendar.SECOND, 0);
- Dzuhur.set(Calendar.MILLISECOND, 0);
- ashar = SharedPref.getString(Consts.ASR);
- int jamA = Integer.parseInt(ashar.substring(0, 2));
- int menitA = Integer.parseInt(ashar.substring(3));
- Ashar.set(Calendar.HOUR_OF_DAY, jamA);
- Ashar.set(Calendar.MINUTE, menitA);
- Ashar.set(Calendar.SECOND, 0);
- Ashar.set(Calendar.MILLISECOND, 0);
- magrib = SharedPref.getString(Consts.MAGHRIB);
- int jamM = Integer.parseInt(magrib.substring(0, 2));
- int menitM = Integer.parseInt(magrib.substring(3));
- Magrib.set(Calendar.HOUR_OF_DAY, jamM);
- Magrib.set(Calendar.MINUTE, menitM);
- Magrib.set(Calendar.SECOND, 0);
- Magrib.set(Calendar.MILLISECOND, 0);
- isya = SharedPref.getString(Consts.ISHA);
- int jamI = Integer.parseInt(isya.substring(0, 2));
- int menitI = Integer.parseInt(isya.substring(3));
- Isya.set(Calendar.HOUR_OF_DAY, jamI);
- Isya.set(Calendar.MINUTE, menitI);
- Isya.set(Calendar.SECOND, 0);
- Isya.set(Calendar.MILLISECOND, 0);
- fajr = SharedPref.getString(Consts.FAJR);
- int jamF = Integer.parseInt(fajr.substring(0, 2));
- int menitF = Integer.parseInt(fajr.substring(3));
- Fajr.set(Calendar.HOUR_OF_DAY, jamF);
- Fajr.set(Calendar.MINUTE, menitF);
- Fajr.set(Calendar.SECOND, 0);
- Fajr.set(Calendar.MILLISECOND, 0);
- Fajr.add(Calendar.DAY_OF_MONTH, 1);
- }
- public void reload() {
- timezone = (Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance().getTimeInMillis())) / (1000 * 60 * 60);
- prayers = new PrayTime();
- prayers.setTimeFormat(prayers.Time24); //format waktu
- prayers.setCalcMethod(prayers.Egypt); //kalulasi menurut
- prayers.setAsrJuristic(prayers.Shafii);
- prayers.setAdjustHighLats(prayers.MidNight);
- prayers.setTimeZone(prayers.getTimeZone());
- prayers.setFajrAngle(21.9);
- prayers.setIshaAngle(18.6);
- int[] offsets = {0, 0, 0, 0, 0, 0, 0}; // {Fajr,Dhuhr,Asr,Maghrib,Isha}
- prayers.tune(offsets);
- now = Calendar.getInstance(TimeZone.getDefault());
- now.setTimeInMillis(System.currentTimeMillis());
- Dzuhur = Calendar.getInstance(TimeZone.getDefault());
- Dzuhur.setTimeInMillis(System.currentTimeMillis());
- Ashar = Calendar.getInstance(TimeZone.getDefault());
- Ashar.setTimeInMillis(System.currentTimeMillis());
- Magrib = Calendar.getInstance(TimeZone.getDefault());
- Magrib.setTimeInMillis(System.currentTimeMillis());
- Isya = Calendar.getInstance(TimeZone.getDefault());
- Isya.setTimeInMillis(System.currentTimeMillis());
- Fajr = Calendar.getInstance(TimeZone.getDefault());
- Fajr.setTimeInMillis(System.currentTimeMillis());
- /*prefsEditor.putLong("Latitude", Double.doubleToLongBits(location.getLatitude()));*/
- GpsManager gpsManager = new GpsManager(SetAlarm2Activity.this);
- gpsManager.checkIfLocationAvailable();
- String lat = String.valueOf(gpsManager.getLatitude());
- String lng = String.valueOf(gpsManager.getLongitude());
- SharedPref.saveString(Consts.LATITUDE, lat);
- SharedPref.saveString(Consts.LONGITUDE, lng);
- double latD = Double.parseDouble(SharedPref.getString(Consts.LATITUDE));
- double lngD = Double.parseDouble(SharedPref.getString(Consts.LONGITUDE));
- if (gpsManager.isLocationEnabled()) {
- ArrayList<String> prayerTimes = prayers.getPrayerTimes(now, latD, lngD, timezone);
- ArrayList<String> prayerNames = prayers.getTimeNames();
- SharedPref.saveString(Consts.FAJR, prayerTimes.get(0));
- SharedPref.saveString(Consts.DHUHR, prayerTimes.get(2));
- SharedPref.saveString(Consts.ASR, prayerTimes.get(3));
- SharedPref.saveString(Consts.MAGHRIB, prayerTimes.get(4));
- SharedPref.saveString(Consts.ISHA, prayerTimes.get(6));
- }
- mFajrTime.setText(SharedPref.getString(Consts.FAJR));
- mDzuhurTime.setText(SharedPref.getString(Consts.DHUHR));
- mAsharTime.setText(SharedPref.getString(Consts.ASR));
- mMagribTime.setText(SharedPref.getString(Consts.MAGHRIB));
- mIsyaTime.setText(SharedPref.getString(Consts.ISHA));
- dzuhur = SharedPref.getString(Consts.DHUHR);
- int jamD = Integer.parseInt(dzuhur.substring(0, 2));
- int menitD = Integer.parseInt(dzuhur.substring(3));
- Dzuhur.set(Calendar.HOUR_OF_DAY, jamD);
- Dzuhur.set(Calendar.MINUTE, menitD);
- Dzuhur.set(Calendar.SECOND, 0);
- Dzuhur.set(Calendar.MILLISECOND, 0);
- ashar = SharedPref.getString(Consts.ASR);
- int jamA = Integer.parseInt(ashar.substring(0, 2));
- int menitA = Integer.parseInt(ashar.substring(3));
- Ashar.set(Calendar.HOUR_OF_DAY, jamA);
- Ashar.set(Calendar.MINUTE, menitA);
- Ashar.set(Calendar.SECOND, 0);
- Ashar.set(Calendar.MILLISECOND, 0);
- magrib = SharedPref.getString(Consts.MAGHRIB);
- int jamM = Integer.parseInt(magrib.substring(0, 2));
- int menitM = Integer.parseInt(magrib.substring(3));
- Magrib.set(Calendar.HOUR_OF_DAY, jamM);
- Magrib.set(Calendar.MINUTE, menitM);
- Magrib.set(Calendar.SECOND, 0);
- Magrib.set(Calendar.MILLISECOND, 0);
- isya = SharedPref.getString(Consts.ISHA);
- int jamI = Integer.parseInt(isya.substring(0, 2));
- int menitI = Integer.parseInt(isya.substring(3));
- Isya.set(Calendar.HOUR_OF_DAY, jamI);
- Isya.set(Calendar.MINUTE, menitI);
- Isya.set(Calendar.SECOND, 0);
- Isya.set(Calendar.MILLISECOND, 0);
- fajr = SharedPref.getString(Consts.FAJR);
- int jamF = Integer.parseInt(fajr.substring(0, 2));
- int menitF = Integer.parseInt(fajr.substring(3));
- Fajr.set(Calendar.HOUR_OF_DAY, jamF);
- Fajr.set(Calendar.MINUTE, menitF);
- Fajr.set(Calendar.SECOND, 0);
- Fajr.set(Calendar.MILLISECOND, 0);
- Fajr.add(Calendar.DAY_OF_MONTH, 1);
- }
- public void initAlarmFajr() {
- if (Fajr.after(now)) {
- Intent intent = new Intent(this, VibrateAlarm.class);
- intent.putExtra("EXTRA_WITH_SOUND", withSound);
- intent.putExtra("EXTRA_WITH_VIBRATE", withVibrate);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- alarmManager.set(AlarmManager.RTC_WAKEUP, Fajr.getTimeInMillis(), pendingIntent);
- }
- }
- public void initAlarmDzuhur() {
- if (Dzuhur.after(now)) {
- AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(this, VibrateAlarm.class);
- intent.putExtra("EXTRA_WITH_SOUND", withSound);
- intent.putExtra("EXTRA_WITH_VIBRATE", withVibrate);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- alarmManager.set(AlarmManager.RTC_WAKEUP, Dzuhur.getTimeInMillis(), pendingIntent);
- }
- }
- public void initAlarmAshar() {
- if (Ashar.after(now)) {
- Intent intent = new Intent(this, VibrateAlarm.class);
- intent.putExtra("EXTRA_WITH_SOUND", withSound);
- intent.putExtra("EXTRA_WITH_VIBRATE", withVibrate);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- alarmManager.set(AlarmManager.RTC_WAKEUP, Ashar.getTimeInMillis(), pendingIntent);
- }
- }
- public void initAlarmMagrib() {
- if (Magrib.after(now)) {
- Intent intent = new Intent(this, VibrateAlarm.class);
- intent.putExtra("EXTRA_WITH_SOUND", withSoundMg);
- intent.putExtra("EXTRA_WITH_VIBRATE", withVibrateMg);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 3, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- alarmManager.set(AlarmManager.RTC_WAKEUP, Magrib.getTimeInMillis(), pendingIntent);
- }
- }
- public void initAlarmIsya() {
- if (Isya.after(now)) {
- Intent intent = new Intent(this, VibrateAlarm.class);
- intent.putExtra("EXTRA_WITH_SOUND", false);
- intent.putExtra("EXTRA_WITH_VIBRATE", true);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 4, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
- alarmManager.set(AlarmManager.RTC_WAKEUP, Isya.getTimeInMillis(), pendingIntent);
- }
- }
- public boolean checkLocationPermission() {
- if (ContextCompat.checkSelfPermission(this,
- Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
- // Should we show an explanation?
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,
- Manifest.permission.ACCESS_FINE_LOCATION)) {
- // Show an explanation to the user *asynchronously* -- don't block
- // this thread waiting for the user's response! After the user
- // sees the explanation, try again to request the permission.
- new AlertDialog.Builder(this)
- .setTitle(R.string.title_location_permission)
- .setMessage(R.string.text_location_permission)
- .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- //Prompt the user once explanation has been shown
- ActivityCompat.requestPermissions(SetAlarm2Activity.this,
- new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
- MY_PERMISSIONS_REQUEST_LOCATION);
- }
- })
- .create()
- .show();
- } else {
- // No explanation needed, we can request the permission.
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
- MY_PERMISSIONS_REQUEST_LOCATION);
- }
- return false;
- } else {
- return true;
- }
- }
- @Override
- public void onRequestPermissionsResult(int requestCode,
- String permissions[], int[] grantResults) {
- switch (requestCode) {
- case MY_PERMISSIONS_REQUEST_LOCATION: {
- // If request is cancelled, the result arrays are empty.
- if (grantResults.length > 0
- && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- // permission was granted, yay! Do the
- // location-related task you need to do.
- if (ContextCompat.checkSelfPermission(this,
- Manifest.permission.ACCESS_FINE_LOCATION)
- == PackageManager.PERMISSION_GRANTED) {
- //Request location updates:
- GpsManager gpsManager = new GpsManager(SetAlarm2Activity.this);
- gpsManager.getLatitude();
- gpsManager.getLongitude();
- }
- } else {
- // permission denied, boo! Disable the
- // functionality that depends on this permission.
- }
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement