Brief Analysis of Android Mobile Security Off Automatic Update

  • 2021-06-29 12:02:27
  • OfStack

Recommended reading:

Brief Analysis on Properties of Android Mobile Guard Custom Control

Four ways to save data, network, broadcasting provider, SharedPreferences, database

Get the SharedPreferences object through the getSharedPreferences() method, parameters: name, mode

For example, config, MODE_PRIVATE

Call the edit() method of the SharedPreferences object to get the Editor object

Call the putBoolean() method of the Editor object and put in the Boolean data, parameter: key-value pair, "update" false

Call the commit() method of the Editor object to submit data

View/data/data/Package Name/shared_perfs/config.xml This generated xml file

Use the command line adb shell cd to the directory above and the cat command to view the file

Call the getBoolean() method of the SharedPreferences object to get the saved data, parameters: key, default value

Make a judgment, set the status to ture, set the text content

Settings Check Download Section

Determine if the saved state is automatically updated

Call code to detect automatic updates if they are updated automatically

If not automatically updated, delay two seconds, automatically jump to home page

Call the postDelayed() method of the Handler object with parameters: Runable object, milliseconds of delay

Inherit the Runable object using an anonymous internal class, override the run() method, which jumps to the home page

TextView section of upgrade progress, hidden by default, android:visibility="gone"gone is hidden and empty

Inside the callback function during the download process, this 1 instantly appears

Calling setVisibility (View.VISIBLE) on the TextView object

SettingActivity:


package com.qingguow.mobilesafe;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import com.qingguow.mobilesafe.ui.SettingItemView;
public class SettingActivity extends Activity {
private SettingItemView siv_item;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
siv_item=(SettingItemView) findViewById(R.id.siv_item);
sp=getSharedPreferences("config", MODE_PRIVATE);
// Set state based on saved data 
boolean update=sp.getBoolean("update", false);
if(update){
siv_item.setChecked(true);
siv_item.setDesc(" Automatic updates are on ");
}else{
siv_item.setChecked(false);
siv_item.setDesc(" Automatic updates have been turned off ");
}
// Automatic Update Click Events 
siv_item.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Editor editor=sp.edit();
if(siv_item.isChecked()){
// Settings unchecked 
siv_item.setChecked(false);
siv_item.setDesc(" Automatic updates have been turned off ");
editor.putBoolean("update", false);
}else{
// Settings Selected 
siv_item.setChecked(true);
siv_item.setDesc(" Automatic updates are on ");
editor.putBoolean("update", true);
}
editor.commit();
}
});
}
}

The above content is about the Android mobile guard turning off the automatic update related knowledge, which is introduced to you in this site. I hope it will be helpful to you!


Related articles: