Program code
[Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]">
<uses-feature
android:name="[Link]"
android:required="true" />
<uses-permission android:name="[Link].ACCESS_FINE_LOCATION"/>
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="[Link].FOREGROUND_SERVICE" />
<uses-permission android:name="[Link].SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]">
<activity android:name=".RegisterNumberActivity"></activity>
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<service
android:name=".ServiceMine"
android:enabled="true"
android:foregroundServiceType="location" />
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">
<View
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:onClick="PopupMenu"
android:clickable="true"
android:focusable="true"
android:layout_margin="20dp"
android:background="@drawable/ic_baseline_more_vert_24"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center">
<TextView
android:id="@+id/textNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="@font/varela_round"
android:text="SOS Will Be Sent To\n"
android:textAlignment="center"
android:textSize="23sp"
android:textStyle="bold|italic" />
<[Link]
android:id="@+id/start"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_below="@+id/textNum"
android:layout_marginTop="13dp"
android:layout_marginBottom="10dp"
android:backgroundTint="#ffffff"
android:gravity="center"
android:onClick="startServiceV"
android:text="Start"
android:textColor="@color/black"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<[Link]
android:id="@+id/stop"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_below="@+id/start"
android:layout_marginTop="26dp"
android:backgroundTint="#ffffff"
android:gravity="center"
android:onClick="stopService"
android:text="stop"
android:textColor="@color/black"
app:cornerRadius="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/start" />
</RelativeLayout>
</RelativeLayout>
activity_register_number.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:background="@drawable/background"
android:layout_height="match_parent"
tools:context=".RegisterNumberActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Enter Number To\nSend SMS\nin\nEMERGENCY!"
android:textSize="28sp"
android:textStyle="italic|bold"
android:fontFamily="@font/varela_round"
android:textColor="@color/black"
android:id="@+id/text1"
android:textAlignment="center"/>
<[Link]
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:id="@+id/number"
android:layout_below="@id/text1"
style="@style/[Link]">
<[Link]
android:layout_width="match_parent"
android:hint="Number"
android:inputType="numberDecimal"
android:id="@+id/numberEdit"
android:maxLength="10"
android:fontFamily="@font/varela_round"
android:textAlignment="center"
android:layout_height="match_parent"/>
</[Link]>
<[Link]
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:onClick="saveNumber"
android:textColor="@color/black"
app:cornerRadius="10dp"
android:layout_below="@id/number"
android:layout_centerHorizontal="true"
android:fontFamily="@font/varela_round"
android:backgroundTint="#ffffff"
android:text="Finish"/>
</RelativeLayout>
</RelativeLayout>
activity_splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]:android="http://
[Link]/apk/res/android"
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashScreen">
<ImageView
android:id="@+id/girlVector"
android:layout_width="130dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:src="@drawable/girl_vector"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Feel Safe Everywhere"
android:fontFamily="@font/varela_round"
android:textSize="28sp"
android:layout_below="@id/girlVector"
app:layout_constraintTop_toBottomOf="@id/girlVector"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_centerHorizontal="true"/>
</[Link]>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivityextends AppCompatActivity {
@Override
protected void onResume() {
[Link]();
SharedPreferencessharedPreferences =
getSharedPreferences("MySharedPref",MODE_PRIVATE);
String ENUM = [Link]("ENUM","NONE");
if([Link]("NONE")){
startActivity(new Intent(this,[Link]));
}else {
TextViewtextView = findViewById([Link]);
[Link]("SOS Will Be Sent To\n"+ENUM);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
if ([Link].SDK_INT>= Build.VERSION_CODES.O) {
if ([Link].SDK_INT>= [Link].VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("MYID",
"CHANNELFOREGROUND", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager m = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
[Link](channel);
}
}
private ActivityResultLauncher<String[]>multiplePermissions=
registerForActivityResult(new [Link](), new
ActivityResultCallback<Map<String, Boolean>>() {
@Override
public void onActivityResult(Map<String, Boolean> result) {
for ([Link]<String,Boolean> entry : [Link]())
if(![Link]()){
Snackbarsnackbar = [Link](findViewById([Link]),"Permission Must
Be Granted!", Snackbar.LENGTH_INDEFINITE);
[Link]("Grant Permission", new [Link]() {
@Override
public void onClick(View v) {
[Link](new String[]{[Link]()});
[Link]();
}
});
[Link]();
}
});
public void stopService(View view) {
Intent notificationIntent = new Intent(this,[Link]);
[Link]("stop");
if ([Link].SDK_INT>= Build.VERSION_CODES.O) {
getApplicationContext().startForegroundService(notificationIntent);
[Link](findViewById([Link]),"Service Stopped!",
Snackbar.LENGTH_LONG).show();
}
}
public void startServiceV(View view) {
if ([Link](this, [Link].SEND_SMS) ==
PackageManager.PERMISSION_GRANTED&&[Link](this,
[Link].ACCESS_COARSE_LOCATION) ==
PackageManager.PERMISSION_GRANTED&&[Link](this,
[Link].ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED) {
Intent notificationIntent = new Intent(this,[Link]);
[Link]("Start");
if ([Link].SDK_INT>= Build.VERSION_CODES.O) {
getApplicationContext().startForegroundService(notificationIntent);
[Link](findViewById([Link]),"Service Started!",
Snackbar.LENGTH_LONG).show();
}
}else{
[Link](new String[]
{[Link].SEND_SMS,[Link].ACCESS_COARSE_LOCATION,Ma
[Link].ACCESS_FINE_LOCATION});
}
public void PopupMenu(View view) {
PopupMenupopupMenu = new PopupMenu([Link],view);
[Link]().inflate([Link],[Link]());
[Link](new [Link]() {
@Override
public booleanonMenuItemClick(MenuItem item) {
if([Link]() == [Link]){
startActivity(new Intent([Link],[Link]));
}
return true;
}
});
[Link]();
}
}
RegisterNumberActivity
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class RegisterNumberActivityextends AppCompatActivity {
TextInputEditTextnumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_register_number);
number = findViewById([Link]);
}
public void saveNumber(View view) {
String numberString = [Link]().toString();
if([Link]()==10){
SharedPreferencessharedPreferences =
getSharedPreferences("MySharedPref",MODE_PRIVATE);
[Link] = [Link]();
[Link]("ENUM", numberString);
[Link]();
[Link]();
}else {
[Link](this, "Enter Valid Number!", Toast.LENGTH_SHORT).show();
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ServiceMine extends Service {
booleanisRunning= false;
FusedLocationProviderClientfusedLocationClient;
@Nullable
@Override
public IBinderonBind(Intent intent) {
return null;
}
SmsManagermanager = [Link]();
String myLocation;
@Override
public void onCreate() {
[Link]();
fusedLocationClient= [Link](this);
if ([Link](this,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED&&[Link](this,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
[Link]()
.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
// Logic to handle location object
[Link]();
[Link]();
myLocation= "[Link]
+","+[Link]();
}else {
myLocation= "Unable to Find Location :(";
}
}
});
[Link](this, () -> {
//if you want to play siren sound you can do it here
//just create music player and play here
//before playing sound please set volume to max
SharedPreferencessharedPreferences =
getSharedPreferences("MySharedPref",MODE_PRIVATE);
String ENUM = [Link]("ENUM","NONE");
if(){
[Link](ENUM,null,"Im in Trouble!\nSending My Location :\
n"+myLocation,null,null);
}
});
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ([Link]().equalsIgnoreCase("STOP")) {
if(isRunning) {
[Link](true);
[Link]();
}
} else {
Intent notificationIntent = new Intent(this, [Link]);
PendingIntentpendingIntent = [Link](this, 0, notificationIntent, 0);
if ([Link].SDK_INT>=
[Link].VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("MYID",
"CHANNELFOREGROUND", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager m = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
[Link](channel);
Notification notification = new [Link](this, "MYID")
.setContentTitle("Women Safety")
.setContentText("Shake Device to Send SOS")
.setSmallIcon([Link].girl_vector)
.setContentIntent(pendingIntent)
.build();
[Link](115, notification);
isRunning= true;
return START_NOT_STICKY;
}
}
return [Link](intent,flags,startId);
@Override
public void onDestroy() {
[Link]();
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SplashScreenextends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_splash_screen);
new CountDownTimer(1000,500){
@Override
public void onTick(long millisUntilFinished) {
@Override
public void onFinish() {
startActivity(new Intent([Link],[Link]));
[Link]();
}
}.start();
}
}
[Link]
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="[Link]
<gradient android:type="linear" android:startColor="#E205524F"
android:endColor="#EB3249C5" android:angle="90"/>
</shape>
[Link]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<colorname="purple_200">#FFBB86FC</color>
<colorname="purple_500">#FF6200EE</color>
<colorname="purple_700">#FF3700B3</color>
<colorname="teal_200">#FF03DAC5</color>
<colorname="teal_700">#FF018786</color>
<colorname="black">#FF000000</color>
<colorname="white">#FFFFFFFF</color>
</resources>