The role of the Splash interface
Open the app splash interface to connect to the network check version.
Get the Package Manager and get version information from the package Manager
1 //Get your own version information2Packagemanager pm =Getpackagemanager ();3 Try {4PackageInfo PackageInfo = Pm.getpackageinfo (Getpackagename (), 0);//obtain this application information5 //Version number6Versioncode =Packageinfo.versioncode;7 //Version name8Versionname =Packageinfo.versionname;9 Ten //Set TextView One Tv_versionname.settext (versionname); A}Catch(namenotfoundexception e) { - //can not reach use API get application This exception does not occur -}
Install the App
1 protected voidinstallapk () {2 /*3 * <intent-filter> <action android:name= "Android.intent.action.VIEW"/>4 * <category android:name= "Android.intent.category.DEFAULT"/> <data5 * android:scheme= "content"/> <data android:scheme= "file"/> <data6 * android:mimetype= "application/vnd.android.package-archive"/>7 * </intent-filter>8 */9Intent Intent =NewIntent ("Android.intent.action.VIEW");TenIntent.addcategory ("Android.intent.category.DEFAULT"); OneString type = "Application/vnd.android.package-archive"; AUri data = Uri.fromfile (NewFile ("/mnt/sdcard/xx.apk")); - intent.setdataandtype (data, type); -Startactivityforresult (Intent, 0); the -}
Gesture recognizer
1 Private voidinitgesture () {2 //Initialize gesture recognizer, bind Ontouch event for gesture recognizer to take effect3GD =NewGesturedetector (NewOngesturelistener () {4 5 //Override this method to complete the toggle effect of the gesture6 /**7 * E1, press the DOT8 * E2 Loosen the point of the screen9 * Velocityx speed in X-axis directionTen * Velocityy speed in Y-axis direction One */ A @Override - Public BooleanOnfling (motionevent E1, motionevent E2,floatVelocityx, - floatvelocityy) { the //TODO auto-generated Method Stub - //whether the speed of the x-axis meets the conditions of transverse sliding pix/s - if(Velocityx > 200) {//speed greater than 400 pixels per second - //can complete sliding + floatDX = E2.getx ()-E1.getx ();//the distance between the x-axis direction sliding - if(Math.Abs (DX) < 100) { + return true;//If the spacing does not conform directly to invalid A } at if(DX < 0) {//swipe from right to left -NextNULL);//event calls that are not components -}Else{//swipe from left to right -PrevNULL); - } - } in return true; - } to...... There's a lot of other ways.
SIM card Bindings
1 Telephonymanager TM = (Telephonymanager) Getsystemservice (context.telephony_service); 2 // SIM card Information 3 String Simserialnumber = Tm.getsimserialnumber ();
Assets Asset Catalog Database copy
Private voidCopydb (FinalString DbName) { NewThread () { Public voidrun () {//determine if the file exists, if there is no need to copyFile File =NewFile ("/data/data/" +Getpackagename ()+ "/files/" +dbName); if(File.exists ()) {//File exists return; } //copy of File Try{filecopy (dbName); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } }; }.start (); }
Determine if the service is running
Public Static Booleanisservicerunning (Context context,string serviceName) {BooleanIsRunning =false; //determine the state of service in operation, ActivitymanagerActivitymanager am =(Activitymanager) Context.getsystemservice (Context.activity_service); //get all the services running on your Android phonelist<runningserviceinfo> runningservices = am.getrunningservices (50); for(Runningserviceinfo runningserviceinfo:runningservices) {//System.out.println (RunningServiceInfo.service.getClassName ()); //determine if the name of the service contains the service name that we specified if(RunningServiceInfo.service.getClassName (). Equals (ServiceName)) {//name has been, the service is runningIsRunning =true; //The exit loop has been found Break; } } returnisrunning; }
Start receiving broadcasts
Broadcast Registration
<receiver android:name= "Com.itheima62.mobileguard.receiver.BootReceiver" > <intent-filter> <action android:name= "Android.intent.action.BOOT_COMPLETED" > </action> </intent-filter > </receiver>
Android Basic app Development API Summary 1