Bugfixes and improvements
This commit is contained in:
parent
ccc09e35e7
commit
529fe80bba
|
@ -11,7 +11,7 @@
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -28,55 +28,47 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPermissions(){
|
private void checkPermissions(){
|
||||||
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.RECEIVE_SMS
|
||||||
|
) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.SEND_SMS
|
||||||
|
) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||||
|
) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
|
||||||
|
this,
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(this,
|
ActivityCompat.requestPermissions(
|
||||||
new String[]{Manifest.permission.RECEIVE_SMS},
|
this,
|
||||||
Utils.PERMISSION_SMS_RECEIVE);
|
new String[]{
|
||||||
|
Manifest.permission.RECEIVE_SMS,
|
||||||
|
Manifest.permission.SEND_SMS,
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
|
},
|
||||||
|
Utils.PERMISSION_MULTIPLE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(this,
|
|
||||||
new String[]{Manifest.permission.SEND_SMS},
|
|
||||||
Utils.PERMISSION_SMS_SEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(this,
|
|
||||||
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
|
|
||||||
Utils.PERMISSION_ACCESS_COARSE_LOCATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(this,
|
|
||||||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
|
|
||||||
Utils.PERMISSION_ACCESS_FINE_LOCATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
ActivityCompat.requestPermissions(this,
|
|
||||||
new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
|
|
||||||
Utils.PERMISSION_ACCESS_BACKGROUND_LOCATION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if (requestCode == Utils.PERMISSION_SMS_RECEIVE) {
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(requestCode == Utils.PERMISSION_SMS_SEND){
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(requestCode == Utils.PERMISSION_ACCESS_FINE_LOCATION){
|
|
||||||
|
|
||||||
|
// Grant Background location if and only if FINE_LOCATION is already granted
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
|
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED)
|
||||||
|
{
|
||||||
|
ActivityCompat.requestPermissions(this,
|
||||||
|
new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
|
||||||
|
Utils.PERMISSION_ACCESS_BACKGROUND_LOCATION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
import java.security.cert.CertPathValidatorException;
|
import java.security.cert.CertPathValidatorException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -68,21 +69,20 @@ public class SmsHandler {
|
||||||
|
|
||||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
// location not enabled
|
||||||
if(!locationManager.isLocationEnabled()){
|
if(!locationManager.isLocationEnabled()){
|
||||||
// TODO: get last known location (requies google play services)
|
// TODO: get last known location (requies google play services)
|
||||||
smsManager.sendTextMessage(sender, null,
|
String response ="Location is not enabled. Unable to serve request.";
|
||||||
"Location is not enabled. " +
|
ArrayList<String> parts = smsManager.divideMessage(response);
|
||||||
"Unable to serve request.",null, null);
|
smsManager.sendMultipartTextMessage (sender, null, parts,null, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Location permission not granted
|
// Location permission not granted
|
||||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
String response ="Location permission is not granted. Unable to serve request.";
|
||||||
|
ArrayList<String> parts = smsManager.divideMessage(response);
|
||||||
smsManager.sendTextMessage(sender, null,
|
smsManager.sendMultipartTextMessage (sender, null, parts,null, null);
|
||||||
"Location permission is not granted. " +
|
|
||||||
"Unable to serve request.",null, null);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,15 +169,19 @@ public class SmsHandler {
|
||||||
resultSms.append("System ID: ").append(((CellInfoCdma) tower).getCellIdentity().getSystemId()).append("\n");
|
resultSms.append("System ID: ").append(((CellInfoCdma) tower).getCellIdentity().getSystemId()).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsManager.sendTextMessage(sender, null, resultSms.toString(),null, null);
|
ArrayList<String> parts = smsManager.divideMessage(resultSms.toString());
|
||||||
|
smsManager.sendMultipartTextMessage (sender, null, parts,null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendGpsCoordinates(SmsManager smsManager, String sendTo, double latitude, double longitude){
|
private void sendGpsCoordinates(SmsManager smsManager, String sendTo, double latitude, double longitude){
|
||||||
smsManager.sendTextMessage(sendTo, null,
|
|
||||||
"Coordinates are:" +
|
String response = "Coordinates are:" +
|
||||||
"\nLatitude: " + latitude +
|
"\nLatitude: " + latitude +
|
||||||
"\nLongitude: " + longitude + "\n" +
|
"\nLongitude: " + longitude + "\n" +
|
||||||
Utils.buildOSMLink(latitude, longitude), null, null);
|
Utils.buildOSMLink(latitude, longitude);
|
||||||
|
|
||||||
|
ArrayList<String> parts = smsManager.divideMessage(response);
|
||||||
|
smsManager.sendMultipartTextMessage (sendTo, null, parts,null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,8 @@ import java.util.Locale;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static final int PERMISSION_SMS_RECEIVE = 100;
|
public static final int PERMISSION_MULTIPLE = 100;
|
||||||
public static final int PERMISSION_SMS_SEND = 101;
|
public static final int PERMISSION_ACCESS_BACKGROUND_LOCATION = 101;
|
||||||
public static final int PERMISSION_ACCESS_FINE_LOCATION = 102;
|
|
||||||
public static final int PERMISSION_ACCESS_COARSE_LOCATION = 103;
|
|
||||||
public static final int PERMISSION_ACCESS_BACKGROUND_LOCATION = 104;
|
|
||||||
|
|
||||||
|
|
||||||
public static final String LOCATE_OPTION = "locate";
|
public static final String LOCATE_OPTION = "locate";
|
||||||
|
|
Loading…
Reference in New Issue