As an important indicator of application-activation, it is necessary to upload the physical identity of the phone to the server each time it is started. Let me briefly summarize the information that needs to be uploaded.
1. Get
Activation information mainly includes:
1. AppId: The company has a variety of applications, indicating the type of the application.
2. Platform: Platform Android or iOS.
3. Systemversion: On Android, represents the Android version number.
4. Version: This app has a revision number.
5. appversion: The server Interface version number for this application.
6. IMEI (International Mobile Equipment Identity): International mobile device identification, mobile identity.
7. DeviceId: The device is marked, usually the IMEI, or it can be a MAC address.
8. Mac:wifi's MAC address.
9. SecureID: The first boot randomly generated by the device to obtain the device life indirectly.
Installid: Application installation time.
Model: Device model
Manufacturer: Equipment production plant.
The DeviceID need permission to get the READ_PHONE_STATE
MAC address: ACCESS_WIFI_STATE
/** * Get mobile signage for activating information, need permission * read_phone_state and Access_wifi_state * <p/> * Created by Wangchenlong on 15/12/11. * * Public class activeinfo { @SuppressWarnings("Unused")Private Static FinalString TAG ="DEBUG-WCL:"+ ActiveInfo.class.getSimpleName ();@SuppressWarnings("All")Private Static FinalString Stat_info_str ="app=%s&platform=android&systemver=%s&version=%s&app_ver=%s&imei=%s"+"&device_id=%s&mac=%s&secureid=%s&installid=%s&phonetype=%s_by_%s&vendor=";Private Static FinalString app_id =" the";Private Static FinalString VENDOR ="Pedometerlibrary";Private Static Final intHTTP_OK = $;//Request succeeded Private Static Final intTime_out =5* +;//Connection time-out Private StaticActiveinfo sinstance;Private FinalContext Mcontext;Private FinalSharedpreferences mprefs;Private FinalTelephonymanager Mtelephonymanager;Private FinalWifimanager Mwifimanager;Private Activeinfo() {mcontext = Pedometermanager.getinstance (). GetContext (); Mprefs = Preferencemanager.getdefaultsharedpreferences (Mcontext); Mtelephonymanager = (Telephonymanager) mcontext. Getsystemservice (Context.telephony_service); Mwifimanager = (Wifimanager) (Mcontext.getsystemservice (Context.wifi_service)); } Public StaticActiveinfogetinstance() {if(Sinstance = =NULL) {sinstance =NewActiveinfo (); }returnSinstance; }//Get signature information PrivateStringgetphonesignature() {String signature;//Mobile signageSignature = String.Format (Stat_info_str, geturlstring (app_id),//App IDGeturlstring (Android.os.Build.VERSION.RELEASE),//System version numberGeturlstring (Buildconfig.version_name),//SDK version numberGeturlstring (Buildconfig.version_name),//Server version numberGeturlstring (Getdeviceid ()),//IMEIGeturlstring (Getdeviceid ()),//Device IDGeturlstring (Getmac ()),//MAC addressGeturlstring (Getsecureid ()),//Security IDGeturlstring (Getinstallid ()),//Installation timeGeturlstring (Android.os.Build.MODEL),//device modelGeturlstring (Android.os.Build.MANUFACTURER));//Equipment FactorySignature + = VENDOR;returnSignature }PrivateStringgeturlstring(String s) {//noinspection Deprecation returnUrlencoder.encode (s); }//Get device ID, need permission read_phone_state PrivateStringGetdeviceid() {if(Mprefs.contains (Prefsconsts.phone_info_device_id_prefs)) {returnMprefs.getstring (Prefsconsts.phone_info_device_id_prefs,""); }Else{Mprefs.edit (). putstring (Prefsconsts.phone_info_device_id_prefs, Mtelep Honymanager.getdeviceid ()). apply ();returnMprefs.getstring (Prefsconsts.phone_info_device_id_prefs,""); } }//Get MAC address, need permission access_wifi_state PrivateStringGetmac() {if(Mprefs.contains (Prefsconsts.phone_info_mac_address_prefs)) {returnMprefs.getstring (Prefsconsts.phone_info_mac_address_prefs,""); }Else{Mprefs.edit (). putstring (Prefsconsts.phone_info_mac_address_prefs, mwif Imanager.getconnectioninfo (). getmacaddress ()). apply ();returnMprefs.getstring (Prefsconsts.phone_info_mac_address_prefs,""); } }//Get security ID PrivateStringGetsecureid() {if(Mprefs.contains (Prefsconsts.phone_info_secure_id_prefs)) {returnMprefs.getstring (Prefsconsts.phone_info_secure_id_prefs,""); }Else{Mprefs.edit (). putstring (Prefsconsts.phone_info_secure_id_prefs, Settin Gs. Secure.getstring (Mcontext.getcontentresolver (), Settings.Secure.ANDROID_ID)) . apply ();returnMprefs.getstring (Prefsconsts.phone_info_secure_id_prefs,""); } }//Get the system time at installation PrivateStringGetinstallid() {if(Mprefs.contains (Prefsconsts.phone_info_install_id_prefs)) {returnMprefs.getstring (Prefsconsts.phone_info_install_id_prefs,""); }Else{Mprefs.edit (). putstring (Prefsconsts.phone_info_install_id_prefs, Strin G.format ("%d", System.currenttimemillis ())). Apply ();returnMprefs.getstring (Prefsconsts.phone_info_install_id_prefs,""); } }//Send activation information Public void Postactiveinfo() {String path ="http://api.chunyu.me/api/launch_request/?"; Path + = Getphonesignature (); LOG.D (TAG,"URL:"+ path);Try{URL url =NewURL (path); HttpURLConnection connection = (httpurlconnection) url.openconnection (); Connection.setconnecttimeout (time_out);//Connection TimeoutConnection.connect ();if(Connection.getresponsecode () = = HTTP_OK) {LOG.D (TAG,"Send activation message succeeded"); }Else{LOG.E (TAG,"Sending activation information failed:"+ Connection.getresponsecode ()); } connection.disconnect (); }Catch(IOException e) {E.printstacktrace (); } }}
To reduce the price of a substitute, you can store some key values into your preferences.
2. Upload
The network request must use the asynchronous thread, we simply upload the activation, do not care about the return value, is simpler.
new// 发送激活信息
//send Activation task thread private class postactivetask extends asynctask <void , Void , void > { @Override protected void Doinbackground (void ... params) {activeinfo.getinstance (). Postactiveinfo (); return null ; } @Override protected void Onpostexec Ute (Void result) {}}
Returns are null values, which need to be doInBackground
noted return null
.
OK, Enjoy It.
Send a mobile phone physical identity request