Android mobile guard-pop-up dialog box, android guard

Source: Internet
Author: User

Android mobile guard-pop-up dialog box, android guard

In the article "Android mobile guard-Parse json and message mechanisms to send different types of messages", message mechanisms have not yet been fully implemented to send different types of information. In the case of exceptions, the following code prompts an exception in the toast prompt:

Private Handler mHandler = new Handler () {// public void handleMessage (android. OS. message msg) {switch (msg. what) {case UPDATE_VERSION: // the pop-up dialog box prompts the user to update // showUpdateDialog (); break; case ENTER_HOME: // enter the main interface of the application. enterHome (); break; case URL_ERROR: ToastUtil. show (getApplicationContext (), "url exception"); enterHome (); break; case IO_ERROR: ToastUtil. show (getApplicationContext (), "Read exception"); enterHome (); break; case JSON_ERROR: ToastUtil. show (getApplicationContext (), "json parsing exception"); enterHome (); break; default: break ;}};};

As the pop-up toast operation is common, it is written as a tool class for simple encapsulation, so that it can be called later.


Create a tool class: ToastUtil. java

Package com. wuyudong. mobilesafe. utils; import android. content. context; import android. widget. toast; public class ToastUtil {// print Toast/*** @ param context Context * @ param message print text content */public static void show (context, String message) {Toast. makeText (context, message, 0 );}}

If the current version number is <server version number, an update prompt is displayed in the dialog box.

/*** Dialog box appears, prompting you to update */protected void showUpdateDialog () {System. out. println ("showUpdateDialog"); // the dialog box depends on the Builder builder = new AlertDialog of the activity. builder (this); // set the icon builder in the upper left corner. setIcon (R. drawable. ic_launcher); builder. setTitle ("version Update"); // sets the description content builder. setMessage (mVersionDes); // click the active button to update the builder immediately. setPositiveButton ("update now", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// download apk, apk URL, downloadUrl downloadApk () ;}}); builder. setNegativeButton ("later", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// cancel dialog box, enter enterHome ();}}); builder. show ();}

The implementation result is as follows:

The downloadApk () function is implemented in the next article.

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.