Android displays power usage, mobile phone information, battery history, usage statistics, and WiFi usage

Source: Internet
Author: User

1. Enter * #4636 # * in the dialing interface to view

2.*#06 # view the IMEI information of the mobile phone

The source code is as follows:

Public void aftertextchanged (editable input ){
If (specialcharsequencemgr. handlechars (this, input. tostring (), mdigits )){
// A special sequence was entered, clear the digits
Mdigits. gettext (). Clear ();
}

If (! Isdigitsempty ()){
Mdigits. setbackgrounddrawable (mdigitsbackground );
} Else {
Mdigits. setcursorvisible (false );
Mdigits. setbackgrounddrawable (mdigitsemptybackground );
}

Updatedialanddeletebuttonenabledstate ();
}

2. specialcharsequencemgr class processing input results

/*
* Copyright (c) 2006 the android open source project
*
* Licensed under the Apache license, version 2.0 (the "License ");
* You may not use this file before t in compliance with the license.
* You may obtain a copy of the license
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* Distributed under the license is distributed on an "as is" basis,
* Without warranties or conditions of any kind, either express or implied.
* See the license for the specific language governing permissions and
* Limitations under the license.
*/

Package com. Android. Contacts. update;

Import Android. App. alertdialog;
Import Android. App. keyguardmanager;
Import Android. App. progressdialog;
Import Android. content. asyncqueryhandler;
Import Android. content. contentresolver;
Import Android. content. context;
Import Android. content. dialoginterface;
Import Android. content. intent;
Import Android. database. cursor;
Import android.net. Uri;
Import Android. OS. RemoteException;
Import Android. telephony. phonenumberutils;
Import Android. telephony. telephonymanager;
Import Android. util. log;
Import Android. View. windowmanager;
Import Android. widget. edittext;
Import Android. widget. Toast;

/**
* Helper class to listen for some magic character sequences
* That are handled specially by the dialer.
*
* Todo: There's lots of duplicated code between this class and
* Corresponding class under apps/phone. Let's figure out a way
* Unify these two classes (in the framework? In a common shared library ?)
*/
Public class specialcharsequencemgr {
Private Static final string tag = "specialcharsequencemgr ";
Private Static final string mmi_imei_display = "* #06 #";

/** This class is never instantiated .*/
Private specialcharsequencemgr (){
}

Static Boolean handlechars (context, string input, edittext textfield ){
Return handlechars (context, input, false, textfield );
}

Static Boolean handlechars (context, string input ){
Return handlechars (context, input, false, null );
}

Static Boolean handlechars (context, string input, Boolean usesystemwindow,
Edittext textfield ){

// Get rid of the separators so that the string gets parsed correctly
String dialstring = phonenumberutils. stripseparators (input );

If (handleimeidisplay (context, dialstring, usesystemwindow)
| Handlepinentry (context, dialstring)
| Handleadnentry (context, dialstring, textfield)
| Handlesecretcode (context, dialstring )){
Return true;
}

Return false;
}

/**
* Handles secret codes to launch arbitrary activities in the form of * # <code> #*#*.
* If a secret code is encountered an intent is started with the android_secret_code: // <code>
* Uri.
*
* @ Param context the context to use
* @ Param input the text to check for a secret code in
* @ Return true if a secret code was encountered
*/
Static Boolean handlesecretcode (context, string input ){
// Secret codes are in the form * # <code> #*#*
Int Len = input. Length ();
If (LEN> 8 & input. startswith ("* #") & input. endswith ("#*#*")){
Intent intent = new intent ("android. provider. telephony. secret_code ",
Uri. parse ("android_secret_code: //" + input. substring (4, len-4 )));
Context. sendbroadcast (intent );
Return true;
}

Return false;
}

/**
* Handle ADN requests by filling in the sim contact number into the requested
* Edittext.
*
* This code works alongside the asynchronous query handler {@ link queryhandler}
* And query cancel handler implemented in {@ link simcontactquerycookie }.
*/
Static Boolean handleadnentry (context, string input, edittext textfield ){
/* ADN entries are of the form "n (n )#"*/

// If the phone is keyguard-restricted, then just ignore this
// Input. We want to make sure that SIM card contacts are not
// Exposed unless the phone is unlocked, and this code can be
// Accessed from the emergency dialer.
Keyguardmanager =
(Keyguardmanager) Context. getsystemservice (context. keyguard_service );
If (keyguardmanager. inkeyguardrestrictedinputmode ()){
Return false;
}

Int Len = input. Length ();
If (LEN> 1) & (LEN <5) & (input. endswith ("#"))){
Try {
// Get the ordinal number of the sim contact
Int Index = integer. parseint (input. substring (0, len-1 ));

// The original code that navigated to a sim contacts list view did not
// Highlight the requested contact correctly, a requirement for ptcrb
// Certification. This behaviour is consistent with the UI paradigm
// For touch-enabled lists, so it does not make sense to try to work
// Around it. Instead we fill in the requested phone number
// The Dialer text field.

// Create the async query Handler
Queryhandler handler = new queryhandler (context. getcontentresolver ());

// Create the cookie object
Simcontactquerycookie SC = new simcontactquerycookie (index-1, handler,
Adn_query_token );

// Setup the cookie Fields
SC. contactnum = index-1;
SC. settextfield (textfield );

// Create the progress Dialog
SC. progressdialog = new progressdialog (context );
SC. progressdialog. settitle (R. String. simcontacts_title );
SC. progressdialog. setmessage (context. gettext (R. String. simcontacts_emptyloading ));
SC. progressdialog. setindeterminate (true );
SC. progressdialog. setcancelable (true );
SC. progressdialog. setoncancellistener (SC );
SC. progressdialog. getwindow (). addflags (
Windowmanager. layoutparams. flag_blur_behind );

// Display the progress Dialog
SC. progressdialog. Show ();

// Run the query.
Handler. startquery (adn_query_token, SC, Uri. parse ("content: // ICC/ADN "),
New String [] {adn_phone_number_column_name}, null, null );
Return true;
} Catch (numberformatexception ex ){
// Ignore
}
}
Return false;
}

Static Boolean handlepinentry (context, string input ){
If (input. startswith ("** 04") | input. startswith ("** 05") & input. endswith ("#")){
/* Try {
Return itelephony. stub. asinterface (servicemanager. getservice ("phone "))
. Handlepinmmi (input );
} Catch (RemoteException e ){
Log. E (TAG, "failed to handlepinmmi due to remote exception ");
Return false;
}*/
}
Return false;
}

Static Boolean handleimeidisplay (context, string input, Boolean usesystemwindow ){
If (input. Equals (mmi_imei_display )){
Int phonetype = (telephonymanager) Context. getsystemservice (
Context. telephony_service). getphonetype ();

If (phonetype = telephonymanager. phone_type_gsm ){
Showimeipanel (context, usesystemwindow );
Return true;
} Else if (phonetype = telephonymanager. phone_type_cdma ){
Showmeidpanel (context, usesystemwindow );
Return true;
}
}

Return false;
}

Static void showimeipanel (context, Boolean usesystemwindow ){
String imeistr = (telephonymanager) Context. getsystemservice (context. telephony_service ))
. Getdeviceid ();

Alertdialog Alert = new alertdialog. Builder (context)
. Settitle (R. String. IMEI)
. Setmessage (imeistr)
. Setpositivebutton (Android. R. String. OK, null)
. Setcancelable (false)
. Show ();
Alert. getwindow (). settype (windowmanager. layoutparams. type_priority_phone );
}

Static void showmeidpanel (context, Boolean usesystemwindow ){
String meidstr = (telephonymanager) Context. getsystemservice (context. telephony_service ))
. Getdeviceid ();

Alertdialog Alert = new alertdialog. Builder (context)
. Settitle (R. String. meid)
. Setmessage (meidstr)
. Setpositivebutton (Android. R. String. OK, null)
. Setcancelable (false)
. Show ();
Alert. getwindow (). settype (windowmanager. layoutparams. type_priority_phone );
}

/*******
* This code is used to handle SIM contact queries
*******/
Private Static final string adn_phone_number_column_name = "Number ";
Private Static final string adn_name_column_name = "name ";
Private Static final int adn_query_token =-1;

/**
* Cookie object that contains everything we need to communicate to
* Handler's onquery complete, as well as what we need in order to cancel
* The query (if requested ).
*
* Note, access to the textfield field is going to be synchronized, because
* The user can request a cancel at any time through the UI.
*/
Private Static class simcontactquerycookie implements dialoginterface. oncancellistener {
Public progressdialog;
Public int contactnum;

// Used to identify the query request.
Private int mtoken;
Private queryhandler mhandler;

// The text field we're re going to update
Private edittext textfield;

Public simcontactquerycookie (INT number, queryhandler handler, int token ){
Contactnum = number;
Mhandler = handler;
Mtoken = token;
}

/**
* Synchronized getter for the edittext.
*/
Public synchronized edittext gettextfield (){
Return textfield;
}

/**
* Synchronized setter for the edittext.
*/
Public synchronized void settextfield (edittext text ){
Textfield = text;
}

/**
* Cancel the ADN query by stopping the operation and signaling
* The cookie that a cancel request is made.
*/
Public synchronized void oncancel (dialoginterface DIALOG ){
// Close the progress Dialog
If (progressdialog! = NULL ){
Progressdialog. Dismiss ();
}

// Setting the textfield to null ensures that the UI does not get
// Updated.
Textfield = NULL;

// Cancel the operation if possible.
Mhandler. canceloperation (mtoken );
}
}

/**
* Asynchronous query handler that services requests to look up ADNS
*
* Queries originate from {@ link handleadnentry }.
*/
Private Static class queryhandler extends asyncqueryhandler {

Public queryhandler (contentresolver Cr ){
Super (CR );
}

/**
* Override basic onquerycomplete to fill in the textfield when
* We're handed the ADN cursor.
*/
@ Override
Protected void onquerycomplete (INT token, object cookie, cursor c ){
Simcontactquerycookie SC = (simcontactquerycookie) cookie;

// Close the progress dialog.
SC. progressdialog. Dismiss ();

// Get the edittext to update or see if the request was canceled.
Edittext text = SC. gettextfield ();

// If the textview is valid, and the cursor is valid and postionable
// On the nth number, then we update the text field and display
// Toast indicating the caller name.
If (C! = NULL) & (text! = NULL) & (c. movetoposition (SC. contactnum ))){
String name = C. getstring (C. getcolumnindexorthrow (adn_name_column_name ));
String number = C. getstring (C. getcolumnindexorthrow (adn_phone_number_column_name ));

// Fill the text in.
Text. gettext (). Replace (0, 0, number );

// Display the name as a toast
Context context = SC. progressdialog. getcontext ();
Name = context. getstring (R. String. menu_callnumber, name );
Toast. maketext (context, name, Toast. length_short)
. Show ();
}
}
}
}

Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.