Added option "show"

This commit is contained in:
Alessandro Ferro 2022-10-03 10:00:40 +02:00
parent 8c95d895b4
commit cafcbbe661
9 changed files with 112 additions and 13 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
<bytecodeTargetLevel target="11" />
</component>
</project>

View File

@ -10,7 +10,7 @@ android {
minSdk 28
targetSdk 32
versionCode 1
versionName "0.1"
versionName "0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@ -25,6 +25,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {

View File

@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"versionName": "0.2",
"outputFile": "app-release.apk"
}
],

View File

@ -24,28 +24,35 @@
android:theme="@style/Theme.LocateMyDevice"
tools:targetApi="30">
<activity
android:name=".ShowMessageActivity"
android:exported="false"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<!-- https://developer.android.com/guide/topics/manifest/receiver-element -->
<receiver
android:name=".SmsReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true"
android:directBootAware="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver
android:name="AdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:exported="true">
android:name=".AdminReceiver"
android:exported="true"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin"/>
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
@ -58,7 +65,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="Settings" android:name=".SettingsActivity"/>
<activity
android:name=".SettingsActivity"
android:label="Settings" />
</application>
</manifest>

View File

@ -0,0 +1,51 @@
package com.xfarrow.locatemydevice;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.TextView;
public class ShowMessageActivity extends AppCompatActivity {
private TextView textToDisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_message);
showOnLockscreen();
setViews();
String messageToDisplay = getData();
textToDisplay.setText(messageToDisplay);
}
// https://stackoverflow.com/questions/35356848/android-how-to-launch-activity-over-lock-screen
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 String getData(){
Bundle extras = getIntent().getExtras();
if (extras != null) {
return extras.getString(Utils.SHOW_MESSAGE_OPTION);
}
return null;
}
private void setViews(){
textToDisplay = findViewById(R.id.text_to_display);
}
}

View File

@ -63,7 +63,9 @@ public class SmsHandler {
+ "|"
+ Utils.WIFI_OPTION + "((" + Utils.WIFI_ENABLE_SUBOPTION + ")|(" + Utils.WIFI_DISABLE_SUBOPTION + "))?"
+ "|"
+ Utils.LOCK_OPTION;
+ Utils.LOCK_OPTION
+ "|"
+ Utils.SHOW_MESSAGE_OPTION + "\\s+\"[\\w\\W]*[\"]$";
Pattern pattern = Pattern.compile(regexToMatch);
Matcher matcher = pattern.matcher(message);
@ -318,5 +320,16 @@ public class SmsHandler {
Utils.sendSms(smsManager, responseSms.toString(), sender);
}
//show
else if(providedOption.contains(Utils.SHOW_MESSAGE_OPTION)){
String messageToDisplay = message.substring(message.indexOf("\"") + 1,
message.lastIndexOf("\""));
Intent lockScreenMessage = new Intent(context, ShowMessageActivity.class);
lockScreenMessage.putExtra(Utils.SHOW_MESSAGE_OPTION, messageToDisplay);
lockScreenMessage.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(lockScreenMessage);
}
}
}

View File

@ -18,6 +18,7 @@ public class Utils {
public static final String CALL_ME_OPTION = "callme";
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 WIFI_ENABLE_SUBOPTION = "-enable";
public static final String WIFI_DISABLE_SUBOPTION = "-disable";

View File

@ -0,0 +1,22 @@
<?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=".MainActivity">
<TextView
android:id="@+id/text_to_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This device has been lost!"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:maxWidth="350sp"/>
</androidx.constraintlayout.widget.ConstraintLayout>