Skip to content

Commit

Permalink
Added permission for location access
Browse files Browse the repository at this point in the history
  • Loading branch information
graham22 committed Jan 24, 2024
1 parent 1dac5cf commit 5d61674
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
8 changes: 6 additions & 2 deletions code/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="256"
android:versionName="2.5.6" >
android:versionCode="257"
android:versionName="2.5.7" >

<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
Expand All @@ -13,6 +13,10 @@
android:minSdkVersion="31"/>
<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>

<uses-permission android:name="android.permission. ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".MainApplication"
android:allowBackup="true"
Expand Down
2 changes: 1 addition & 1 deletion code/Android/app/src/main/assets/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>About SkyeTracker</title>
</head>
<body>
<h2>SkyeTracker (version 2.5.6)</h2>
<h2>SkyeTracker (version 2.5.7)</h2>
<p>
<h5>
<a href="https://www.buymeacoffee.com/r4K2HIB" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;

import androidx.core.app.ActivityCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.core.content.PermissionChecker;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -61,28 +65,32 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
btnUploadLocation = (Button) rootView.findViewById(R.id.btnUploadLocation);
btnUploadLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (selfPermissionGranted(Manifest.permission.ACCESS_FINE_LOCATION) == false) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(INITIAL_PERMS, INITIAL_REQUEST);
if (selfPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION) == false) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(INITIAL_PERMS, INITIAL_REQUEST);
}
}
}
LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if (selfPermissionGranted(Manifest.permission.ACCESS_FINE_LOCATION)) {
@SuppressLint("MissingPermission") Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if (location == null){
Toast.makeText(getActivity(),"Location Not found",Toast.LENGTH_LONG).show();
}else {
lat.setText(String.format("%.6f", location.getLatitude()));
lon.setText(String.format("%.6f", location.getLongitude()));
longitude = location.getLongitude();
latitude = location.getLatitude();
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 101);
}

LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if (selfPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION)) {
@SuppressLint("MissingPermission") Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

if (location == null) {
Toast.makeText(getActivity(), "Location Not found", Toast.LENGTH_LONG).show();
} else {
lat.setText(String.format("%.6f", location.getLatitude()));
lon.setText(String.format("%.6f", location.getLongitude()));
longitude = location.getLongitude();
latitude = location.getLatitude();
Gson gson = new Gson();
ConfigLocation configLocation = new ConfigLocation(latitude, longitude);
String json = "SetC|" + gson.toJson(configLocation);
MainApplication.SendCommand(json);
}
}
}
Gson gson = new Gson();
ConfigLocation configLocation = new ConfigLocation(latitude, longitude);
String json = "SetC|" + gson.toJson(configLocation);
MainApplication.SendCommand(json);
}
});

Expand Down

0 comments on commit 5d61674

Please sign in to comment.