Android Determines whether the device is an emulator or a real machine and sets the screen brightness of the activity

Source: Internet
Author: User

The

/** determines whether the emulator is. If true, it is currently the emulator
     * @param context
     * @return
*/ 

  code is as follows copy code

public static Boolean Isemulator (context context) { 
         Telephonymanager TM = (Telephonymanager) context.getsystemservice (context.telephony_ SERVICE); 
        String IMEI = Tm.getdeviceid (); 
         if (IMEI = null | | imei.equals ("000000000000000")) { 
             return true; 
        } 
        return false; 
}

This method does not have a lot of test, should be work, the general true machine has IMEI, but also saw the construction machine IMEI is 000000000000000 or 0.


Two
sets the screen brightness of the current activity instead of setting the system's screen brightness, and then restores the system's brightness after exiting the current activity. Just look at the code, okay?

The code is as follows Copy Code

Windowmanager.layoutparams LP = GetWindow (). GetAttributes ();

lp.screenbrightness = 0.5f;
GetWindow (). SetAttributes (LP);

The range of screenbrightness values is 0 to 1. Be careful not to set to 0, the screen will be black, completely invisible.

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.