"WebView loads local HTML, native apk HTML, and remote URLs"
Copy Code code as follows:
Open the index.html file in the asset directory in this package
Wview.loadurl ("file:///android_asset/index.html");
Open the index.html file in the local SD card
Wview.loadurl ("content://com.android.htmlfileprovider/sdcard/index.html");
Opens the HTML file for the specified URL
Wview.loadurl ("Http://m.xxx.net");
"Get screen resolution"
Copy Code code as follows:
Get through WindowManager
Displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
System.out.println ("Heigth:" + dm.heightpixels);
System.out.println ("width:" + dm.widthpixels);
Access via resources
Displaymetrics dm2 = Getresources (). Getdisplaymetrics ();
System.out.println ("heigth2:" + dm2.heightpixels);
System.out.println ("width2:" + dm2.widthpixels);
Get the default resolution for the screen
Display display = Getwindowmanager (). Getdefaultdisplay ();
System.out.println ("Width-display:" + display.getwidth ());
System.out.println ("Heigth-display:" + display.getheight ());
Get through WindowManager
Displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
System.out.println ("Heigth:" + dm.heightpixels);
System.out.println ("width:" + dm.widthpixels);
Access via resources
Displaymetrics dm2 = Getresources (). Getdisplaymetrics ();
System.out.println ("heigth2:" + dm2.heightpixels);
System.out.println ("width2:" + dm2.widthpixels);
Get the default resolution for the screen
Display display = Getwindowmanager (). Getdefaultdisplay ();
System.out.println ("Width-display:" + display.getwidth ());
System.out.println ("Heigth-display:" + display.getheight ());
"Remove the screen title and Full-screen display"
Copy Code code as follows:
Remove title
Requestwindowfeature (Window.feature_no_title);
Set Full Screen
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Remove title
Requestwindowfeature (Window.feature_no_title);
Set Full Screen
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
"Set the orientation of the screen"
Configuring the properties of an activity in the Manifest.xml file
Copy Code code as follows:
<activity android:name= ". Animateactivity "android:label=" @string/app_name "
android:screenorientation= "Landscape" ><!--Landscape Horizontal Screen Portrait vertical screen-->
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Control in the program is generally controlled in the OnCreate and OnDestroy methods in the activity, because the system restarts the activity when the screen direction changes. Therefore, it is necessary to save the relevant data before the activity is destroyed, so that it can be reloaded in the next OnCreate method and update the layout of the screen.
Copy Code code as follows:
public void OnCreate (Bundle savedinstancestate) {
Force horizontal Screen
Setrequestedorientation (Activityinfo.screen_orientation_landscape);
TODO Update screen layout
}
public void OnDestroy () {
if (getrequestedorientation () = = Activityinfo.screen_orientation_landscape) {
Save data
}else if (getrequestedorientation () = = activityinfo.screen_orientation_portrait) {
Save data
}
}
"Get memory card path and space usage"
Copy Code code as follows:
Get the memory card path
File Sdcarddir = Environment.getexternalstoragedirectory ();
Statfs look at the use of file system space
File Sdcarddir = Environment.getexternalstoragedirectory ();
Statfs statfs = new Statfs (Sdcarddir.getpath ());
Size of block
File Sdcarddir = Environment.getexternalstoragedirectory ();
Statfs statfs = new Statfs (Sdcarddir.getpath ());
Long blockSize = Statfs.getblocksize ();
Total Block number
File Sdcarddir = Environment.getexternalstoragedirectory ();
Statfs statfs = new Statfs (Sdcarddir.getpath ());
Long totalblocks = Statfs.getblockcount ();
Number of blocks used
File Sdcarddir = Environment.getexternalstoragedirectory ();
Statfs statfs = new Statfs (Sdcarddir.getpath ());
Long availableblocks = Statfs.getavailableblocks ();
"Control Android's soft keyboard"
Copy Code code as follows:
Inputmethodmanager inputmethodmanager= (Inputmethodmanager) Getsystemservice (Context.input_method_service);
Inputmethodmanager.togglesoftinput (0, inputmethodmanager.hide_not_always);
"Get your cell phone number."
Remember to add permissions in manifest file
Copy Code code as follows:
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
Create a phone management connection with a mobile phone
Telephonymanager TM = (Telephonymanager) activity.getsystemservice (Context.telephony_service);
Get cell phone number
String Phoneid = Tm.getline1number ();