This video explains the steps that how the audio settings of your android phone can be controlled using an Android App from another phone. In this concept, you do not need internet settings and the settings will be controlled using SMS. So, basically 2 steps are shown here in this video. 1st is how to send SMS to the phone number of controlled device. 2nd how to read the SMS and do the respective operation as mentioned in the SMS.
This kind of Apps are useful, if you want to make the sound of your Phone audible in case it is lost somewhere in your home or workplace. In this concept, you can also use any phone to send a SMS message of predefined template and the controlled phone will react accordingly.
We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com
Source Code:
package com.example.myreingtoneremotecontrol;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.TextView;import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;import java.util.Timer;
import java.util.TimerTask;import static android.Manifest.permission.ACCESS_NOTIFICATION_POLICY;
import static android.Manifest.permission.READ_SMS;
import static android.Manifest.permission.SEND_SMS;public class MainActivity extends AppCompatActivity {
private TextView textView;
private Cursor cursor;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);textView = findViewById(R.id.textView);
ActivityCompat.requestPermissions(MainActivity.this,new String[]{ACCESS_NOTIFICATION_POLICY, SEND_SMS, READ_SMS}, PackageManager.PERMISSION_GRANTED);NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (!notificationManager.isNotificationPolicyAccessGranted()){
//Ask the user permission
Intent intent = new Intent((Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS));
startActivity(intent);
}Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {cursor = getContentResolver().query(Uri.parse(“content://sms”), null, null, null, null);
cursor.moveToFirst();if (cursor.getString(12).equalsIgnoreCase(“Mute”)){
((AudioManager)getSystemService(Context.AUDIO_SERVICE)).setRingerMode(AudioManager.RINGER_MODE_SILENT);runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(“Audio MUTED”);
}
});}
if (cursor.getString(12).equalsIgnoreCase(“UnMute”)){
((AudioManager)getSystemService(Context.AUDIO_SERVICE)).setRingerMode(AudioManager.RINGER_MODE_NORMAL);runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(“Audio UN-MUTED”);
}
});
}}
}, 0 , 2000);}
public void MuteButton(View view){
String number = “999999”;
String message = “Mute”;SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message, null, null);
}public void UnMuteButton(View view){
String number = “999999”;
String message = “UnMute”;SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message, null, null);}
}
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.myreingtoneremotecontrol”><uses-permission android:name=”android.permission.ACCESS_NOTIFICATION_POLICY”/>
<uses-permission android:name=”android.permission.SEND_SMS”/>
<uses-permission android:name=”android.permission.READ_SMS”/>
<uses-permission android:name=”android.permission.RECEIVE_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/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application></manifest>
Dear Sir,
I have enjoyed a lot your tutorials, in particular the ones with SMS tutorials and also the
one with a background ringtone.
I was wondering if it is possible to combine this two ideias: control the phone via SMS while running in the background (display switched off)
I am trying but it seems that the getContentResolver().query(Uri.parse(“content://sms”) does not work inside the class myBackgroundProcess.
Do you intend to publish a tutorial with this idea? for instance using the sms tracker tutorial while having the app in background?
Thank you for the good work, please continue to post android tutorials
Regards
Thanks for your comment. Also, it was great to know your idea. I will in-line my answers for your points.
– I was wondering if it is possible to combine this two ideas: control the phone via SMS while running in the background (display switched off)
Yes, it is definitely possible to control the phone via SMS or even through network (internet) while it is working in background. That’s how most of the hacking Apps and tracking software works and steals the data from the phone. But do not worry, it is not so straight forward. As google keeps upgrading it’s Android OS to reduce such risks. For example, it restricts the usage of certain operations (mostly data collection) while App is working in background (there are workaround to break it but it is for advance level). Also, Android OS will monitor all the background process and will shut it down in case it finds it inoperative or abusing the background thread (details of all the OS level restriction are not completely into public domain).
– I am trying but it seems that the getContentResolver().query(Uri.parse(“content://sms”) does not work inside the class myBackgroundProcess.
Yes, as hinted above, getContentResolver works only in the main thread and cannot be used in the background thread. (It is one of the restricted operation from Android OS). There are many work around to it. The simplest one is to pass the data from the main thread to the background process through the Intent (get/ put) APIs.
– Do you intend to publish a tutorial with this idea? for instance using the sms tracker tutorial while having the app in background?
There are couple of videos already posted which will do this job (more or less). However, given your proposal, I will try to put a separate tutorial on complete steps to do this. Thanks for your suggestion. In the meantime one can refer to my below webpages on this topic:
https://programmerworld.co/android/create-location-tracking-android-app-by-exchanging-location-information-over-firebase-database/
https://programmerworld.co/android/how-to-get-the-device-last-location-using-gps-network-without-using-map-layout-in-your-android-app/
https://programmerworld.co/android/how-to-create-background-process-in-your-android-app/
Cheers
Programmer World
–
Dear Sir,
Thank you for your reply and clarification on the subject.
I can see the implications on the security as you explain clearly. To be honest I came from the embedded/IoT world and I was wondering what to do with the old android phones that I have and not using. They are steal very powerful in therms of computation (even with a broken screen) that I was wondering if it would be possible to have an old android phone placed in my backyard collecting some simple data and sending it back via SMS. But for that it would need to be running my app in the background to minimize battery consumption, so that is why I am so interested in this subject.
Thank you for the suggestion of “pass the data from the main thread to the background process through the Intent (get/ put) APIs.” I am researching on this to understand more the idea of sharing data with the main and background thread.
Once more thank you for the suggestion and help
Regards