Skip to content
Snippets Groups Projects
Commit e742e756 authored by root's avatar root
Browse files

location not workijng maps working

parent 30bce5ea
No related branches found
No related tags found
No related merge requests found
Showing
with 514 additions and 197 deletions
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintLongLogTag" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="ResourceType" enabled="false" level="ERROR" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
...@@ -25,5 +25,6 @@ dependencies { ...@@ -25,5 +25,6 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=7C:8A:3C:0D:F3:30:A2:61:C6:0E:E4:DC:2D:4E:09:A2:47:20:32:20%3Bcom.speedyapps.keepyousafe
You can also add your credentials to an existing key, using these values:
Package name:
7C:8A:3C:0D:F3:30:A2:61:C6:0E:E4:DC:2D:4E:09:A2:47:20:32:20
SHA-1 certificate fingerprint:
7C:8A:3C:0D:F3:30:A2:61:C6:0E:E4:DC:2D:4E:09:A2:47:20:32:20
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
AIzaSyB3bf-8bbz85sz0ZejHkGN4GXigr-oUSxk
</string>
</resources>
...@@ -11,14 +11,16 @@ ...@@ -11,14 +11,16 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/kms" android:icon="@mipmap/kms"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/MyTheme"> android:theme="@style/MyTheme">
<activity android:name=".MainActivity"> <activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -26,24 +28,36 @@ ...@@ -26,24 +28,36 @@
</intent-filter> </intent-filter>
</activity> </activity>
<service
android:name=".alarmService"
android:enabled="true"
android:exported="true" />
<receiver android:name=".SMSReader$readSMS">
<intent-filter> <receiver android:name=".SMSManager" android:exported="true" >
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" /> <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service
android:name=".SMSReader"
android:enabled="true"
android:exported="true" />
<activity android:name=".ContactSelection" /> <activity android:name=".ContactSelection"
<activity android:name=".confirmationScreen"></activity> android:screenOrientation="portrait"/>
<activity android:name=".confirmationScreen"
android:screenOrientation="portrait"/>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package com.speedyapps.keepyousafe;
/**
* Created by SUBASH on 18-04-2017.
*/
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
/**
* Created by pethoalpar on 4/13/2016.
*/
public class GpsTool {
String locationProvider = LocationManager.GPS_PROVIDER;
private LocationManager locationManager;
private LocationListener locationListener;
public GpsTool(Context context){
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
this.turnOnGps(context);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
onGpsLocationChanged(location);
location.reset();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
onGpsStatusChanged(provider, status, extras);
}
@Override
public void onProviderEnabled(String provider) {
onGpsProviderEnabled(provider);
}
@Override
public void onProviderDisabled(String provider) {
onGpsProviderDisabled(provider);
}
};
startGpsUpdate();
}
public void onGpsLocationChanged(Location location) {
//Location change.
}
public void onGpsStatusChanged(String provider, int status, Bundle extras) {
}
public void onGpsProviderEnabled(String provider) {
}
public void onGpsProviderDisabled(String provider) {
}
public Location getLocation(){
return locationManager.getLastKnownLocation(locationProvider);
}
public void startGpsUpdate(){
locationManager.requestLocationUpdates(locationProvider, 1000, 0, locationListener);
}
public void stopGpsUpdate(){
locationManager.removeUpdates(locationListener);
}
public void turnOnGps(Context context){
boolean isEnabled = locationManager.isProviderEnabled(locationProvider);
if(!isEnabled){
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(intent);
}
}
}
...@@ -27,8 +27,7 @@ import java.util.List; ...@@ -27,8 +27,7 @@ import java.util.List;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
Intent intent; Intent intent;
int choice; int choice;
private TextView textView; MapsActivity maps ;
private GpsTool gpsTool;
SharedPreferences firsttime; SharedPreferences firsttime;
private static final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 291; private static final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 291;
int backCount=0; int backCount=0;
...@@ -38,6 +37,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -38,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
requestPermissionsApp(); requestPermissionsApp();
maps=new MapsActivity();
firsttime = this.getSharedPreferences("firsttimecheck",MODE_PRIVATE); firsttime = this.getSharedPreferences("firsttimecheck",MODE_PRIVATE);
SharedPreferences.Editor editor = firsttime.edit(); SharedPreferences.Editor editor = firsttime.edit();
String checkString = firsttime.getString("status","false"); String checkString = firsttime.getString("status","false");
...@@ -57,8 +57,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -57,8 +57,8 @@ public class MainActivity extends AppCompatActivity {
} }
intent = new Intent(MainActivity.this,confirmationScreen.class); intent = new Intent(MainActivity.this,confirmationScreen.class);
choice=0; choice=0;
Intent serviceIntent = new Intent(MainActivity.this,SMSReader.class); //Intent serviceIntent = new Intent(MainActivity.this,SMSReader.class);
startService(serviceIntent); //startService(serviceIntent);
ImageButton help = (ImageButton)findViewById(R.id.helpButton); ImageButton help = (ImageButton)findViewById(R.id.helpButton);
help.setOnLongClickListener(new View.OnLongClickListener(){ help.setOnLongClickListener(new View.OnLongClickListener(){
public boolean onLongClick(View v){ public boolean onLongClick(View v){
...@@ -69,23 +69,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -69,23 +69,7 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
textView = (TextView) this.findViewById(R.id.loc);
if (gpsTool == null) {
gpsTool = new GpsTool(this) {
@Override
public void onGpsLocationChanged(Location location) {
super.onGpsLocationChanged(location);
refreshLocation(location);
}
};
} }
}
public void contact(View v) public void contact(View v)
{ {
backCount=0; backCount=0;
...@@ -161,18 +145,18 @@ public class MainActivity extends AppCompatActivity { ...@@ -161,18 +145,18 @@ public class MainActivity extends AppCompatActivity {
sb.append("Longitude:").append(longitude).append("\n"); sb.append("Longitude:").append(longitude).append("\n");
sb.append("Latitude:").append(latitude).append("\n"); sb.append("Latitude:").append(latitude).append("\n");
sb.append("Altitude:").append(altitude); sb.append("Altitude:").append(altitude);
textView.setText(sb.toString()); Intent intent = new Intent(MainActivity.this,MapsActivity.class);
startActivity(intent);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
gpsTool.stopGpsUpdate();
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
gpsTool.startGpsUpdate();
} }
} }
package com.speedyapps.keepyousafe;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
SharedPreferences sp;
Double latitude,longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
sp=getSharedPreferences("locationinfo",MODE_PRIVATE);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
final Handler handler = new Handler();
Runnable run = new Runnable() {
@Override
public void run() {
if(Double.parseDouble(sp.getString("latitude","0.0"))!=latitude&&!(sp.getString("latitude","null").equals("null"))) {
Toast.makeText(MapsActivity.this, "Calling updateMap", Toast.LENGTH_SHORT).show();
updateLocation();
handler.postDelayed(this, 1000);
}
}
};
handler.post(run);
}
@Override
protected void onStart() {
super.onStart();
sp.edit().putString("status","running").commit();
}
@Override
protected void onStop() {
super.onStop();
sp.edit().putString("status","stopped").commit();
}
@Override
protected void onPause() {
super.onPause();
sp.edit().putString("status","paused").commit();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
updateLocation();
}
public void updateLocation(){
latitude=Double.parseDouble(sp.getString("latitude","0.00"));
longitude=Double.parseDouble(sp.getString("longitude","0.00"));
Toast.makeText(this, ""+latitude+longitude, Toast.LENGTH_SHORT).show();
if(latitude!=0.00) {
LatLng currentLocation = new LatLng(latitude,longitude);
mMap.addMarker(new MarkerOptions().position(currentLocation).title("Last known Location !"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),18));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),18));
}
}
}
package com.speedyapps.keepyousafe;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SMSManager extends BroadcastReceiver {
private String TAG = SMSManager.class.getSimpleName();
String latitudepart=null,longitudepart=null;
Double latitude,longitude;
SharedPreferences sp;
public SMSManager() {
}
@Override
public void onReceive(Context context, Intent intent) {
// Get the data (SMS data) bound to intent
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
Toast.makeText(context, "OK", Toast.LENGTH_SHORT).show();
sp=context.getSharedPreferences("locationinfo",Context.MODE_PRIVATE);
sp.edit().putString("status","stoped").commit();
String str = "",sender="";
if (bundle != null) {
// Retrieve the SMS Messages received
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
// For every SMS message received
for (int i=0; i < msgs.length; i++) {
// Convert Object array
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
// Sender's phone number
sender += msgs[i].getOriginatingAddress();
// Fetch the text message
str += msgs[i].getMessageBody().toString();
// Newline <img draggable="false" class="emoji" alt="🙂" src="https://s.w.org/images/core/emoji/72x72/1f642.png">
str += "\n";
}
Toast.makeText(context, "`Sender : "+sender+" Message : "+str, Toast.LENGTH_SHORT).show();
}
if(str.contains("Help Me!!!!")){
//myContext.startService(alarm);
String[] coordinates = str.split(">");
latitudepart=coordinates[1].split(",")[0];
longitudepart=coordinates[1].split(",")[1];
sp.edit().putString("latitude",latitudepart).putString("longitude",longitudepart).commit();
Log.i("lat","lat"+latitudepart);
Intent mapsIntent = new Intent(context, MapsActivity.class);
//mapsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mapsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// if(!sp.getString("status","null").equals("running")) {
context.startActivity(mapsIntent);
// }
// if(sp.getString("status","null").equals("paused")){
// context.stopService(mapsIntent);
context.startActivity(mapsIntent);
}
}
}
...@@ -28,52 +28,50 @@ public class SMSReader extends Service { ...@@ -28,52 +28,50 @@ public class SMSReader extends Service {
// TODO: Return the communication channel to the service. // TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented"); throw new UnsupportedOperationException("Not yet implemented");
} }
public static class readSMS extends BroadcastReceiver{ public class readSMS extends BroadcastReceiver{
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final SmsManager sms = SmsManager.getDefault();
final Intent alarm = new Intent(myContext,alarmService.class); final Intent alarm = new Intent(myContext,alarmService.class);
// Retrieves a map of extended data from the intent. // Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras(); final Bundle bundle = intent.getExtras();
Toast.makeText(context, "Received Message", Toast.LENGTH_SHORT).show();
try {
if (bundle != null) { if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus"); final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) { for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); SmsMessage rcvdmsg =null;
String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String message = null;
for(int p=0;p<pdusObj.length;p++){
String senderNum = phoneNumber; rcvdmsg=SmsMessage.createFromPdu((byte[])pdusObj[p]);
String message = currentMessage.getDisplayMessageBody(); }
byte[] data=null;
Log.d("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message); data=rcvdmsg.getUserData();
if(data!=null){
for(int index=0;index<data.length;index++){
message+=Character.toString((char)data[index]);
}
}
int count=0; int count=0;
Handler handler = new Handler(); Handler handler = new Handler();
if(message.equals("Help Me!!!!")){ if(message.contains("Help Me!!!!")){
myContext.startService(alarm); //myContext.startService(alarm);
handler.postDelayed(new Runnable() { String[] coordinates = message.split(">");
public void run() { String latitudepart=coordinates[1].split(",")[0];
myContext.stopService(alarm); String longitudepart=coordinates[1].split(",")[1];
Log.i("lat","lat"+latitudepart);
} Intent mapsIntent = new Intent(myContext,MapsActivity.class);
},5000); mapsIntent.putExtra("latitude",Double.parseDouble(latitudepart));
mapsIntent.putExtra("longitude",Double.parseDouble(longitudepart));
startActivity(mapsIntent);
} }
// Show alert // Show alert
int duration = Toast.LENGTH_LONG; int duration = Toast.LENGTH_LONG;
} // end for loop } // end for loop
} // bundle is null } // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" +e);
} }
} }
} }
}
...@@ -39,7 +39,6 @@ public class alarmService extends Service { ...@@ -39,7 +39,6 @@ public class alarmService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
mediaPlayer.start(); mediaPlayer.start();
forceFullVolume(); forceFullVolume();
return super.onStartCommand(intent, flags, startId); return super.onStartCommand(intent, flags, startId);
} }
......
package com.speedyapps.keepyousafe; package com.speedyapps.keepyousafe;
import android.Manifest;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SmsManager; import android.telephony.SmsManager;
...@@ -15,25 +30,37 @@ import android.widget.Toast; ...@@ -15,25 +30,37 @@ import android.widget.Toast;
import org.w3c.dom.Text; import org.w3c.dom.Text;
public class confirmationScreen extends AppCompatActivity { import java.util.List;
public class confirmationScreen extends AppCompatActivity implements LocationListener {
public static int SMS_SEND_INTERVAL=2000;
LocationManager locationManager;
TextView textView; TextView textView;
EditText editText; EditText editText;
Double latitude = null, longitude = null,newlat=null,newlong=null;
Handler timehandler;
SharedPreferences sharedpreferences, sp, shared; SharedPreferences sharedpreferences, sp, shared;
String n,n1; String n;
String n1;
LocationProvider provider;
int count, i; int count, i;
public static String file1 = "MyPREFERENCES"; public static String file1 = "MyPREFERENCES";
public static String file2 = "PREFERENCES"; public static String file2 = "PREFERENCES";
public static String file3 = "COUNT"; public static String file3 = "COUNT";
Handler handler, handler2; Handler handler, handler2;
Intent alarmIntent ; Runnable run, run2,run3;
Runnable run,run2;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_confirmation_screen); setContentView(R.layout.activity_confirmation_screen);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getProvider(LocationManager.GPS_PROVIDER);
Toast.makeText(this, "Provider"+provider, Toast.LENGTH_SHORT).show();
handler = new Handler(); handler = new Handler();
handler2 = new Handler(); handler2 = new Handler();
alarmIntent = new Intent(confirmationScreen.this,alarmService.class); timehandler = new Handler();
//alarmIntent = new Intent(confirmationScreen.this, alarmService.class);
textView = (TextView) findViewById(R.id.countDown); textView = (TextView) findViewById(R.id.countDown);
editText = (EditText) findViewById(R.id.editTextPIN); editText = (EditText) findViewById(R.id.editTextPIN);
sharedpreferences = getSharedPreferences(file1, Context.MODE_PRIVATE); sharedpreferences = getSharedPreferences(file1, Context.MODE_PRIVATE);
...@@ -44,65 +71,224 @@ public class confirmationScreen extends AppCompatActivity { ...@@ -44,65 +71,224 @@ public class confirmationScreen extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
textView.setText("" + i); textView.setText("" + i);
if((i--)<=0){ if ((i) == 0) {
Toast.makeText(confirmationScreen.this, "distress called", Toast.LENGTH_SHORT).show();
distressCall(); distressCall();
handler.removeCallbacks(this); handler.removeCallbacks(this);
} else{
i--;
if(i<=0)
i=0;
handler.postDelayed(this, 100);
} }
else
handler.postDelayed(this,1000);
} }
}; };
handler.post(run);
run2 = new Runnable() { run2 = new Runnable() {
@Override @Override
public void run() { public void run() {
if (editText.getText().toString().equals("2020")) { if (editText.getText().toString().equals("2020")) {
stopService(alarmIntent); //stopService(alarmIntent);
handler.removeCallbacks(run); handler.removeCallbacks(run);
handler2.removeCallbacks(this); handler2.removeCallbacks(this);
timehandler.removeCallbacks(run3);
Toast.makeText(confirmationScreen.this, "Distress Calls Cancelled!", Toast.LENGTH_SHORT).show(); Toast.makeText(confirmationScreen.this, "Distress Calls Cancelled!", Toast.LENGTH_SHORT).show();
Intent main = new Intent(confirmationScreen.this, MainActivity.class); Intent main = new Intent(confirmationScreen.this, MainActivity.class);
startActivity(main); startActivity(main);
finish(); finish();
} } else
else
handler2.postDelayed(this, 100); handler2.postDelayed(this, 100);
} }
}; };
handler.post(run);
handler2.post(run2); handler2.post(run2);
} }
public void distressCall() { public void distressCall() {
startService(alarmIntent); // startService(alarmIntent);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location location = getLastKnownLocation();
Toast.makeText(this, "Initial Location var : "+location.getLatitude()+location.getLongitude(), Toast.LENGTH_SHORT).show();
if(location!=null){
latitude=location.getLatitude();
longitude=location.getLongitude();
count = shared.getInt("count", 0); count = shared.getInt("count", 0);
Log.d("COUNT", String.valueOf(count)); Log.d("COUNT", String.valueOf(count));
for (int i = 1; i <= count; i++) for (int i = 1; i <= count; i++) {
{
n1 = sp.getString("value" + i, ""); n1 = sp.getString("value" + i, "");
n = sharedpreferences.getString(n1, ""); n = sharedpreferences.getString(n1, "");
Log.d("sub", n); Log.d("sub", n);
try try {
{ if (!(n.isEmpty())) {
if(!(n.isEmpty())) sendSMS(n, "Help Me!!!!>" + latitude + "," + longitude);
{
sendSMS(n, "Help Me!!!!");
} }
} catch (Exception e) {
} }
catch (Exception e){}
} }
} }
run3 = new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(confirmationScreen.this, "Old longitude :"+longitude+" New Longitude : "+newlong, Toast.LENGTH_SHORT).show();
}
});
if (longitude != newlong && newlong != null) {
count = shared.getInt("count", 0);
Log.d("COUNT", String.valueOf(count));
for (int i = 1; i <= count; i++) {
n1 = sp.getString("value" + i, "");
n = sharedpreferences.getString(n1, "");
Log.d("sub", n);
try {
if (!(n.isEmpty())) {
sendSMS(n, "Help Me!!!!>" + newlat + "," + newlong);
}
} catch (Exception e) {
}
}
latitude=newlat;
longitude=newlong;
}
timehandler.postDelayed(this, SMS_SEND_INTERVAL);
}
};
timehandler.postDelayed(run3,SMS_SEND_INTERVAL);
}
public void sendSMS(String phoneNumber, String message) public void sendSMS(String phoneNumber, String message)
{ {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null); String SMS_SENT = "SMS_SENT";
String SMS_DELIVERED = "SMS_DELIVERED";
PendingIntent sentPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMS_SENT), 0);
PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMS_DELIVERED), 0);
// For when the SMS has been sent
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(context, "SMS sent successfully", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(context, "Generic failure cause", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(context, "Service is currently unavailable", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(context, "No pdu provided", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(context, "Radio was explicitly turned off", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SMS_SENT));
// For when the SMS has been delivered
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SMS_DELIVERED));
// Get the default instance of SmsManager
SmsManager smsManager = SmsManager.getDefault();
// Send a text based SMS
smsManager.sendTextMessage(phoneNumber, null, message, sentPendingIntent, deliveredPendingIntent);
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {
Toast.makeText(this, "Please Enter the PIN CODE in order to Go Back!!!", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Please Enter the PIN CODE in order to Go Back!!!", Toast.LENGTH_SHORT).show();
} }
@Override
public void onLocationChanged(Location location) {
Toast.makeText(this, "new Location : "+latitude+","+longitude, Toast.LENGTH_SHORT).show();
newlat=location.getLatitude();
newlong=location.getLongitude();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled Provider", Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacks(run);
handler2.removeCallbacks(run2);
timehandler.removeCallbacks(run3);
}
@Override
public void onProviderDisabled(String provider) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
final String message = "Please Enable GPS to continue !";
builder.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
startActivity(new Intent(action));
d.dismiss();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
d.cancel();
}
});
builder.create().show();
}
private Location getLastKnownLocation() {
List<String> providers = locationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location l = locationManager.getLastKnownLocation(provider);
Log.d("last known location, provider: %s, location: %s", provider+l);
if (l == null) {
continue;
}
if (bestLocation == null
|| l.getAccuracy() < bestLocation.getAccuracy()) {
Log.d("found best last known location: %s", ""+l);
bestLocation = l;
}
}
if (bestLocation == null) {
return null;
}
return bestLocation;
}
} }
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.speedyapps.keepyousafe.MapsActivity" />
<resources> <resources>
<string name="app_name">KeepMeSafe</string> <string name="app_name">KeepMeSafe</string>
<string name="title_activity_maps">Map</string>
</resources> </resources>
<resources>
<!--
TODO: Before you release your application, you need a Google Maps API key.
To do this, you can either add your release key credentials to your existing
key, or create a new key.
Note that this file specifies the API key for the release build target.
If you have previously set up a key for the debug target with the debug signing certificate,
you will also need to set up a key for your release certificate.
Follow the directions here:
https://developers.google.com/maps/documentation/android/signup
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
YOUR_KEY_HERE
</string>
</resources>
...@@ -5,7 +5,7 @@ buildscript { ...@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
#Mon Dec 28 10:00:20 PST 2015 #Fri Apr 21 13:28:53 IST 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment