[Webview loads local html, html in this apk and remote URL]
Copy the codeThe code is as follows:
// Open the file in the asset directory in this package
("file:///android_asset/ ");
// Open the file in the local SD card
("content:///sdcard/");
// Open the html file of the specified URL
("");
【Get screen resolution】
Copy the codeThe code is as follows:
// Get it through WindowManager
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
("heigth : " + );
("width : " + );
// Get through Resources
DisplayMetrics dm2 = getResources().getDisplayMetrics();
("heigth2 : " + );
("width2 : " + );
// Get the default resolution of the screen
Display display = getWindowManager().getDefaultDisplay();
("width-display :" + ());
("heigth-display :" + ());
// Get it through WindowManager
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
("heigth : " + );
("width : " + );
// Get it through Resources
DisplayMetrics dm2 = getResources().getDisplayMetrics();
("heigth2 : " + );
("width2 : " + );
// Get the default resolution of the screen
Display display = getWindowManager().getDefaultDisplay();
("width-display :" + ());
("heigth-display :" + ());
【Remove the screen title and full screen display】
Copy the codeThe code is as follows:
// Remove the title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set full screen
getWindow().setFlags(.FLAG_FULLSCREEN, .FLAG_FULLSCREEN);
// Remove the title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set full screen
getWindow().setFlags(.FLAG_FULLSCREEN, .FLAG_FULLSCREEN);
【Set the direction of the screen】
Configure the properties of the Activity in the file
Copy the codeThe code is as follows:
<activity android:name=".AnimateActivity" android:label="@string/app_name"
android:screenOrientation="landscape"><!-- landscape portrait vertical screen -->
<intent-filter>
<action android:name="" />
<category android:name="" />
</intent-filter>
</activity>
Control in the program, it is generally controlled in the onCreate and onDestroy methods in the Activity, because when the screen direction changes, the system will restart the Activity. Therefore, you need to save the relevant data before the Activity is destroyed, so that it can be reloaded in the next onCreate method and update the screen layout
Copy the codeThe code is as follows:
public void onCreate(Bundle savedInstanceState) {
//Forced horizontal screen
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// TODO updates the screen layout
}
public void onDestroy() {
if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
// Save data
}else if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
// Save data
}
}
【Get the memory card path and space usage】
Copy the codeThe code is as follows:
// Get the memory card path
File sdcardDir = ();
// StatFs depends on file system space usage
File sdcardDir = ();
StatFs statFs = new StatFs(());
// Block's size
File sdcardDir = ();
StatFs statFs = new StatFs(());
Long blockSize = ();
// Total Block Number
File sdcardDir = ();
StatFs statFs = new StatFs(());
Long totalBlocks = ();
// Number of blocks used
File sdcardDir = ();
StatFs statFs = new StatFs(());
Long availableBlocks = ();
【Soft Keyboard for Android】
Copy the codeThe code is as follows:
InputMethodManager inputMethodManager=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
(0, InputMethodManager.HIDE_NOT_ALWAYS);
【Get mobile phone number】
Remember to add permissions in the manifest file
Copy the codeThe code is as follows:
<uses-permission android:name=".READ_PHONE_STATE" />
// Create phone management to establish connection with your phone
TelephonyManager tm = (TelephonyManager)(Context.TELEPHONY_SERVICE);
// Get mobile phone number
String phoneId = tm.getLine1Number();