First question:Determine whether the mobile phone is currently using a SIM card or WiFiI wrote an encapsulation method, which can be used later:
[Java]
View plaincopyprint?
- /**
- * Check the Internet is
- * Mobile or WiFi
- * Add By wangxianming
- * In 2012-03-22
- */
- Private Boolean checkwifi (){
- Boolean iswificonnect = true;
- Connectivitymanager CM = (connectivitymanager) mcontext. getsystemservice (context. connectivity_service );
[Java]
View plaincopyprint?
- // Check the networkinfos numbers
- Networkinfo [] networkinfos = cm. getallnetworkinfo ();
- For (INT I = 0; I <networkinfos. length; I ++ ){
- If (networkinfos [I]. getstate () = networkinfo. state. Connected ){
- If (networkinfos [I]. GetType () = cm. type_mobile ){
- Iswificonnect = false;
- }
- If (networkinfos [I]. GetType () = cm. type_wifi ){
- Iswificonnect = true;
- }
- }
- }
- Return iswificonnect;
Example 2: determine whether the current mobile phone screen has the option of rotating the screen:
[Java]
View plaincopyprint?
- /**
- * Accelerometer_rotation ----> explain:
- *
- * Control whether the accelerometer will be
- * Used to change screen orientation.
- * If 0, it will not be used unless explicitly
- * Requested by the application;
- * If 1, it will be used by default
- * Unless explicitly disabled by the application.
- * Constant value: "accelerometer_rotation"
- */
- Systemgravity = settings. system. getint (this
- . Getcontentresolver (),
- Settings. system. accelerometer_rotation); // 1 is open; 0 is close;
The third is to register a broadcast that listens to the memory card status in the Code:
[Java]
View plaincopyprint?
- Intentfilter = new intentfilter );
- Intentfilter. addaction (intent. action_media_unmounted );
- Intentfilter. addaction (intent. action_media_eject );
- Intentfilter. addaction (intent. action_media_removed );
- Intentfilter. addaction (intent. action_media_bad_removal );
- Registerreceiver (sdcardlistener, intentfilter );
When registerreceiver () is used to register a broadcast, the unregisterreceiver () method appears in pairs.
If the broadcast is registered in the oncreate () method, it is released in the ondestroy () method.
If the broadcast is registered in the onresume () method, it is released in the onpause () method.
Write an internal broadcast class in the Code:
[Java]
View plaincopyprint?
- <Span style = "font-size: 16px; color: #000000;"> private final broadcastreceiver sdcardlistener = new broadcastreceiver (){
- Public void onreceive (context, intent ){
- Toast. maketext (summaryappmainactivityactivity. This, R. String. sd_removed, 2000). Show ();
- }
- }; </Span>
Fourth, Full Screen Settings: write a simple method;
[Java]
View plaincopyprint?
- <Span style = "font-size: 16px; color: #000000;"> // set the activity is fullscreen
- Private void setfullscreen (){
- Misfullscreen =! Misfullscreen;
- If (misfullscreen ){
- Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,
- Windowmanager. layoutparams. flag_fullscreen );
- } Else {
- Getwindow (). clearflags (windowmanager. layoutparams. flag_fullscreen );
- }
- } </Span>
- <Span style = "color: # ff6600;"> <strong> <span style = "font-size: 18px;"> so few items are sorted out today, take the time to connect the knowledge! Haha, go to bed. See you next time!
- I attended the mobile voice Developer Conference today. I am sorry that Liu Chuanzhi and Li Kaifu leijun were not present. Well, I got a little bit of it. I listened to their on-site interviews!