Confucius said: Learning and time to learn, not to mention is ah, learning to often study to do, especially remember the freshman year when he fell in love with programming; At that time I bought an ASP dynamic website programming, still remember spent 5 yuan. The next day I turned the book almost into a picture, and then combined with the teacher's HTML syntax, I slowly worked on a class website out, think of the heart is still very excited. After such a long time, VBScript's knowledge was almost forgotten, and a chance to see it later. This is written to record some of the first problems or doubts I have encountered in a recent project I took over. Due to the project is not finished, so continue to update ...========================================================
Qiujuer
Blog: Blog.csdn.net/qiujuer
Website: www.qiujuer.net
Open Source Library: genius-android
Reprint Please specify Source: http://blog.csdn.net/qiujuer/article/details/41849241
========================================================
Read Browser history
<uses-permission android:name= "Com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>{ string string = null; Contentresolver contentresolver = Getcontentresolver (); cursor cursor = contentresolver.query (Uri.parse ("Content://browser/bookmarks"), new string[]{"url"}, NULL, NULL, NULL) ; while (cursor! = NULL && cursor.movetonext ()) { string = cursor.getstring (cursor.getcolumnindex ("url")); LOG.D ("Debug", String = = null?) "NULL": string);}
Analog Return key function 1.java.lang.runtime
Runtime runtime = Runtime.getruntime (); Runtime.exec ("Input keyevent" + keyevent.keycode_back);
2.android.app.instrumentation
Instrumentation inst = new Instrumentation (); Inst.sendkeydownupsync (Keyevent.keycode_back);
Monitor boot start broadcast
public class Bootreceiver extends Broadcastreceiver { @Override public void OnReceive (context context, Intent Intent) { if (intent.getaction (). Equals (intent.action_boot_completed)) {Do ...}} }
<receiver android:name= ". Bootreceiver "> <intent-filter> <action android:name=" Android.intent.action.BOOT_COMPLETED "/ > </intent-filter> </receiver>
<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>
Determine the type of mobile network
/** * Determine the type of mobile network * * @param networktype telephonymanager.getnetworktype () * @return Network type */Stati c int getmobilenetworktype (int networktype) {/* GPRS 2G (2.5) General Packet Radia Service 114kbps EDGE 2G (2.75G) Enhanced Data rate for GSM Evolution 384kbps UMTS 3G WCDMA unicom 3G Universal Mobile Tele Communication System Complete 3G Mobile communication technology standard CDMA 2G Telecom Code Division multiple Access Code Division multiple Address Evdo_0 3G (EVDO full CD MA2000 1xev-do) evolution-data only (Data Optimized) 153.6kps-2.4mbps belongs to 3G evdo_a 3G 1.8mbps-3.1mbps belongs to the 3G transition, 3.5G 1xRTT 2G CDMA2000 1xRTT (RTT-radio transmission technology) 144kbps 2G transition, HSDPA 3.5G high-speed downlink packet access 3.5G WCDMA H IgH speed downlink Packet access 14.4mbps HSUPA 3.5G high speeds uplink Packet access fast uplink packet Access 1.4-5.8 Mbps HSPA 3G (min hsdpa,hsupa) high speed Packet Access IDEN 2G Integrated Dispatch Enhanced Networks integrated Digital increase Strong network (2G, from Wikipedia) Evdo_b 3G ev-do rev.b 14.7Mbps downlink 3.5G LTE 4G Long term Evolution fdd-lte and Tdd-lte, 3G transition, upgraded LTE Advance D is 4G EHRPD 3G CDMA2000 LTE 4G Intermediate product evolved high rate Packet Data HRPD upgrade Hspap 3G HSPAP faster than HSDPA */switch (networktype) {case TelephonyManager.NETWORK_TYPE_GPRS:case telephonymanager.ne Twork_type_edge:case TelephonyManager.NETWORK_TYPE_CDMA:case Telephonymanager.network_type_1xrtt: Case TelephonyManager.NETWORK_TYPE_IDEN:return note.network_type_2g; Case TelephonyManager.NETWORK_TYPE_UMTS:case TelephonyManager.NETWORK_TYPE_EVDO_0:case Telephonyma Nager. Network_type_evdo_a:case TelephonyManager.NETWORK_TYPE_HSDPA:case TELEPHONYMANAGER.NETWORK_TYPE_HS Upa:case TelephonyManager.NETWORK_TYPE_HSPA:case Telephonymanager.network_type_evdo_b: Case Telephonymanager.network_typE_ehrpd:case TelephonyManager.NETWORK_TYPE_HSPAP:return note.network_type_3g; Case TelephonyManager.NETWORK_TYPE_LTE:return note.network_type_4g; Default:return Note.network_type_unknown; } }Read Call history
Final cursor cursor = cr.query (CallLog.Calls.CONTENT_URI, new string[] {CallLog.Calls.NUMBER, CallLog.Calls.CACHED_ Name,calllog.calls.type, CallLog.Calls.DATE}, NULL, Null,calllog.calls.default_sort_order); final cursor cursor = Cr.query (database table name, obtained data array (inside contains field name), condition, parameter group, sort etc information)//This is equivalent to a SQL statement//Get all call information here is a little bit more complicated for (int i = 0; i < Cursor.getcount (); i++) {cursor.movetoposition (i); str = cursor.getstring (0); Type = Cursor.getint (2); if (type = = 3) {tel = str; Break }}//Get the value final cursor cursor = cr.query (CallLog.Calls.CONTENT_URI, new string[] {CallLog.Calls.NUMBER}, "type=3", NULL, "D Ate desc LIMIT 1 ");//This is the phone number of the most recent missed call that was received. if (Cursor.movetofirst ()) {tel = cursor.getstring (0);} This value is the same as the top value. CallLog.Calls.CONTENT_URI (call log database) CallLog.Calls.NUMBER (call number) CallLog.Calls.CACHED_NAME (caller name) CallLog.Calls.TYPE (call type) There are three types of call records: Caller: CallLog.Calls.INCOMING_TYPE (constant value: 1) dialed: CallLog.Calls.OUTGOING_TYPE (constant value: 2) not answered: Calllog . Calls.missed_type (constant value: 3) actuallyThere is also a type-reject system that does not give a constant. But after testing, the conclusion is 4. CallLog.Calls.DATE (Talk Time) CallLog.Calls.CONTENT_URI: equivalent to: Uri.parse ("Content://call_log/calls");
//filter missed calls Call Duration 0-11 sec//Time: Start Bell ~ end time String wherestr = CallLog.Calls.TYPE + "!=3 and" + calllog.cal Ls. DURATION + ">0 and" + CallLog.Calls.DURATION + "<11 and" + CallLog.Calls.DATE + ">" + startTime + "and" + Cal LLog.Calls.DATE + "<" + endTime; Flashback and query cursor cursor = context.getcontentresolver (). Query (CallLog.Calls.CONTENT_URI, new String[]{calllog.call S.number}, WHERESTR, NULL, NULL); Bflag = Cursor.getcount () > 0; Cursor.close ();
Permission to be declared added <uses-permission android:name= "Android.permission.READ_CONTACTS"/> Read record in Androidmanifest.xml <uses-permission android:name= "Android.permission.WRITE_CONTACTS"/> Write records these two are similar to the <application> node If you want to join the call permissions, also add <uses-permission android:name= "Android.permission.CALL_PHONE"/> also send SMS permission < Uses-permission android:name= "Android.permission.SEND_SMS"/> also has Internet access <uses-permission android:name= " Android.permission.INTERNET "/>
Click the Back button again to exit the program
The replication returns event public boolean onKeyDown (int keycode, keyevent event) { if (keycode = = keyevent.keycode_back) { if ( (System.currenttimemillis ()-Mexittime) >) { toast.maketext (this, R.string.label_press_main, Toast.length_short). Show (); Mexittime = System.currenttimemillis (); } else { finish (); } return true; } else return Super.onkeydown (KeyCode, event); }
Activeandroid and Gson conflict
Problem Description: Activeandroid model cannot be instantiated by Gson, because Activeandroid model contains fields that cannot be converted by Gson;
Solution:To filter the specified class in the Activeandroid Model:
Import Com.google.gson.exclusionstrategy;import com.google.gson.fieldattributes;/** * Created by QiuJu * on 2014/9/16. */public class Specificclassexclusionstrategy implements Exclusionstrategy {private final class<?> Excludedthisc Lass Private final class<?> Excludedthisclassfields; /** * Filter Initialization * * @param excludedthisclass the class and object instances that inherit from the class will be ignored * @param excludedthisclassfields properties of the class will not Serialized */Public Specificclassexclusionstrategy (class<?> excludedthisclass, class<?> ExcludedThisClassFie lds) {this.excludedthisclass = Excludedthisclass; This.excludedthisclassfields = Excludedthisclassfields; } @Override public boolean shouldskipclass (class<?> clazz) {return clazz! = null && (clazz.equ ALS (excludedthisclass) | | Shouldskipclass (Clazz.getsuperclass ())); } @Override public Boolean Shouldskipfield (FieldAttributes f) {return F.getdeclaringclass (). Equals (Excludedt HisclassfieLDS); }}
Gsonbuilder Gsonbuilder = new Gsonbuilder (); Gsonbuilder.setexclusionstrategies (new Specificclassexclusionstrategy (null, Model.class)); Gsonbuilder.setdateformat ("Yyyy-mm-dd HH:mm:ss. SSS "); Gson Gson = Gsonbuilder.create (); Noteputmodel model = new Noteputmodel (); Model.setphoneid (Settings.getphoneid ()); Model.setphonemark (Settings.getphonemark ()); Model.setnotes (Note.getall (false)); Jsonobject jsonobject = null; try { jsonobject = new Jsonobject (Gson.tojson (model)), } catch (Jsonexception e) { e.printstacktrace (); }
Get Base Station information
public static string Getcellpos (Telephonymanager mtelephonymanager) {string result = NULL; try {//return value MCC + MNC String operator = Mtelephonymanager.getnetworkoperator (); if (operator! = null && operator.length () > 0) {int MCC = Integer.parseint (operator.substring (0 , 3)); int MNC = Integer.parseint (operator.substring (3)); The way gsmcelllocation location = (gsmcelllocation) mtelephonymanager.getcelllocation () of the LAC and CID obtained by China Mobile and Chinese unicom; int lac = Location.getlac (); int cellid = Location.getcid (); result = "MCC =" + MCC + "\ t MNC =" + MNC + "\ t lac =" + Lac + "\ t CID =" + cellid; China Telecom acquires LAC, CID way/*cdmacelllocation location1 = (cdmacelllocation) mtelephonymanager.getcelllocation (); Lac = Location1.getnetworkid (); Cellid = Location1.getbasestationid (); Cellid/= 16;*///Get Neighborhood base station information list<neighboringcellinfo> Infos = Mtelephonymanager.get Neighboringcellinfo (); StringBuilder sb = new StringBuilder ("Size:" + infos.size () + "\ n"); for (Neighboringcellinfo Info1:infos) {//Loop Sb.append ("LAC:") based on the total number of neighbors. Append (Info1.getlac ()); Remove the Lac sb.append ("CID:") from the current neighborhood. Append (Info1.getcid ()); Remove the CID sb.append ("BSSS:") from the current neighborhood. Append ( -113 + 2 * INFO1.GETRSSI ()). Append ("\ n"); Get the neighborhood base station signal Strength} result + = "Neighbor:" + sb.tostring (); }} catch (Exception e) {e.printstacktrace (); } return result; }Java Android Date Gson Json parsing string time contains T error problem:Problem Description:The time string contains a "T" character and cannot be formatted as appropriate. Appears: parseexception:unparseable date
Interface Scheme:To set the format string:"Yyyy-mm-dd ' T ' HH:mm:ss"
public static Gson Getnotereplygson () { Gsonbuilder gsonbuilder = new Gsonbuilder (); Gsonbuilder.setexclusionstrategies (new Specificclassexclusionstrategy (null, Model.class)); Gsonbuilder.setdateformat ("Yyyy-mm-dd ' T ' HH:mm:ss. SSS "); return Gsonbuilder.create (); }
Baidu positioning problemProblem Description:when using Baidu to locate the time, call Locationclient.start () return False and, do not return to the function, but on a mobile phone can be used normally.
Workaround:The defaultJNI (Armeabi)file, copy for full platform.
attach a package to get Baidu map:
Class Locationbuilder implements Bdlocationlistener {Countdownlatch mlatch; Locationclient mclient; Location mlocation; Public Locationbuilder (Final context context) {This.mlatch = new Countdownlatch (1); this.mlocation = new location (); Toolkit.runonmainthreadsync (New Runnable () {@Override public void run () {mclient = BuildLocation (context); Mclient.registerlocationlistener (Locationbuilder.this); Mclient.start (); } }); try {this.mLatch.await (timeunit.seconds); } catch (Interruptedexception e) {e.printstacktrace (); This.stop (); }} getLocation () {Location location = mlocation; Mlocation = null; return location; } private void Stop () {try {mclient.unregisterlocationlistener (this); Mclient.stop (); } catch (Exception e) { E.printstacktrace (); }} Private Locationclient BuildLocation (context context) {Locationclient locationclient = new Locationclien T (context); DECLARE locationclient class locationclientoption option = new Locationclientoption (); Option.setlocationmode (LocationClientOption.LocationMode.Hight_Accuracy);//Set positioning mode Option.setcoortype ("Bd09ll") ;//Returns the positioning result is Baidu latitude and longitude, the default value gcj02 option.setscanspan (1000);//Set the time interval for initiating a location request to 1000ms option.setisneedaddress (true); locationclient.setlocoption (option); return locationclient; } @Override public void Onreceivelocation (bdlocation) {this.stop (); try {if (Mlatch! = null) {int[] codes = new int[]{61, 65, 66, 68, 161}; if (Arrays.binarysearch (codes, Location.getloctype ()) >= 0) {mlocation.setlongitude (Location.getlon Gitude ()); Mlocation.setlatitude (Location.getlatitude ()); Mlocation.setradius (Location.getradius ()); Mlocation.setaddress (Location.getaddrstr ()); Mlocation.setaltitude (Location.getaltitude ()); } mlatch.countdown (); }} catch (Exception e) {e.printstacktrace (); } }}IIS server download apk file 404 errorfile path is all right, can be prompted 404 error, the last problem is on the mime of IIS, the following method can be resolved.
- In IIS Manager, right-click the Web site or site directory for which you want to add a MIME type, and click Properties.
- Click the HTTP Headers tab.
- Click MIME type.
- Click New.
- In the Extension box, type the file name extension:. apk
- In the MIME type box, type Application/octet-stream
- Click OK.
========================================================
Qiujuer
Blog: blog.csdn.net/qiujuer
Website: www.qiujuer.net
Open Source Library: genius-android
Reprint Please specify Source: http://blog.csdn.net/qiujuer/article/details/41849241
========================================================
[Android] Developing a piece of software what do I know?