Added option "ring"
This commit is contained in:
parent
c32f334016
commit
195c29b7b9
|
@ -23,7 +23,13 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.LocateMyDevice"
|
||||
tools:targetApi="30">
|
||||
|
||||
<activity
|
||||
android:name=".RingerActivity"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ShowMessageActivity"
|
||||
android:exported="false"
|
||||
|
@ -31,8 +37,7 @@
|
|||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="" />
|
||||
</activity>
|
||||
<!-- https://developer.android.com/guide/topics/manifest/receiver-element -->
|
||||
</activity> <!-- https://developer.android.com/guide/topics/manifest/receiver-element -->
|
||||
<receiver
|
||||
android:name=".SmsReceiver"
|
||||
android:directBootAware="true"
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package com.xfarrow.locatemydevice;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
public class RingerActivity extends AppCompatActivity {
|
||||
|
||||
private Ringtone ringtoneManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_ringer);
|
||||
showOnLockscreen();
|
||||
setViews();
|
||||
startRinging();
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/35356848/android-how-to-launch-activity-over-lock-screen
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
private void showOnLockscreen(){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
|
||||
{
|
||||
setShowWhenLocked(true);
|
||||
setTurnScreenOn(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
|
||||
private void setViews(){
|
||||
Button stopButton = findViewById(R.id.stopButton);
|
||||
|
||||
stopButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stopRinging();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startRinging(){
|
||||
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
|
||||
ringtoneManager = RingtoneManager.getRingtone(this, ringtone);
|
||||
ringtoneManager.setVolume(1f);
|
||||
ringtoneManager.play();
|
||||
}
|
||||
|
||||
private void stopRinging(){
|
||||
ringtoneManager.stop();
|
||||
finishAffinity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed(){
|
||||
stopRinging();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.xfarrow.locatemydevice;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
@ -21,6 +22,7 @@ public class ShowMessageActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
// https://stackoverflow.com/questions/35356848/android-how-to-launch-activity-over-lock-screen
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
private void showOnLockscreen(){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,8 @@ import android.location.Criteria;
|
|||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
|
@ -65,7 +67,9 @@ public class SmsHandler {
|
|||
+ "|"
|
||||
+ Utils.LOCK_OPTION
|
||||
+ "|"
|
||||
+ Utils.SHOW_MESSAGE_OPTION + "\\s+\"[\\w\\W]*[\"]$";
|
||||
+ Utils.SHOW_MESSAGE_OPTION + "\\s+\"[\\w\\W]*[\"]$"
|
||||
+ "|"
|
||||
+ Utils.RING_OPTION;
|
||||
|
||||
Pattern pattern = Pattern.compile(regexToMatch);
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
|
@ -320,7 +324,7 @@ public class SmsHandler {
|
|||
Utils.sendSms(smsManager, responseSms.toString(), sender);
|
||||
}
|
||||
|
||||
//show
|
||||
// show
|
||||
else if(providedOption.contains(Utils.SHOW_MESSAGE_OPTION)){
|
||||
String messageToDisplay = message.substring(message.indexOf("\"") + 1,
|
||||
message.lastIndexOf("\""));
|
||||
|
@ -332,5 +336,14 @@ public class SmsHandler {
|
|||
Utils.sendSms(smsManager, "Displayed on screen", sender);
|
||||
}
|
||||
|
||||
// ring
|
||||
else if(providedOption.equals(Utils.RING_OPTION)){
|
||||
|
||||
Intent ringerActivityIntent = new Intent(context, RingerActivity.class);
|
||||
ringerActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(ringerActivityIntent);
|
||||
|
||||
Utils.sendSms(smsManager, "Ringing", sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public class Utils {
|
|||
public static final String WIFI_OPTION = "wifi";
|
||||
public static final String LOCK_OPTION = "lock";
|
||||
public static final String SHOW_MESSAGE_OPTION = "show";
|
||||
public static final String RING_OPTION = "ring";
|
||||
public static final String WIFI_ENABLE_SUBOPTION = "-enable";
|
||||
public static final String WIFI_DISABLE_SUBOPTION = "-disable";
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".RingerActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/stopButton"
|
||||
android:layout_width="330dp"
|
||||
android:layout_height="330dp"
|
||||
android:text="STOP"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:textSize="50sp"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue