Summary of trivial knowledge points in Android programming (4)

Source: Internet
Author: User

1. Get contact information from SMS

Java code
  1. Contactitem getcontactbyaddr (context, final smsitem SMS ){
  2. Uri personuri = URI. withappendedpath (
  3. Contactscontract. phonelookup. content_filter_uri, SMS. maddress );
  4. Cursor cur = context. getcontentresolver (). Query (personuri,
  5. New String [] {phonelookup. display_name },
  6. Null, null, null );
  7. If (cur. movetofirst ()){
  8. Int nameidx = cur. getcolumnindex (phonelookup. display_name );
  9. Contactitem item = new contactitem ();
  10. Item. mname = cur. getstring (nameidx );
  11. Cur. Close ();
  12. Return item;
  13. }
  14. Return NULL;
  15. }

 

2. Retrieve and display images from gallery

Java code
  1. Protected void onactivityresult (INT requestcode, int resultcode, intent imagereturnedintent ){
  2. Super. onactivityresult (requestcode, resultcode, imagereturnedintent );
  3. Switch (requestcode ){
  4. Case req_code_pick_image:
  5. If (resultcode = result_ OK ){
  6. Uri selectedimage = imagereturnedintent. getdata ();
  7. String [] filepathcolumn = {mediastore. Images. Media. Data };
  8. Cursor cursor = getcontentresolver (). Query (selectedimage, filepathcolumn, null );
  9. Cursor. movetofirst ();
  10. Int columnindex = cursor. getcolumnindex (filepathcolumn [0]);
  11. String filepath = cursor. getstring (columnindex );
  12. Cursor. Close ();
  13. Bitmap yourselectedimage = bitmapfactory. decodefile (filepath );
  14. }
  15. }
  16. }

 

3. Use toast in the service

Java code
  1. Public class connectionservice extends Service {
  2. Private handler = new handler ();
  3. Public void restartconnection (){
  4. Int sleeptime = reconnectcounter * min_recon_wait;
  5. If (sleeptime> max_recon_wait ){
  6. Sleeptime = max_recon_wait;
  7. }
  8. String MSG = "the connection has been lost. Restart attempt will start in:" + sleeptime/1000 + "seconds ";
  9. (New timer (). Schedule (
  10. New timertask (){
  11. Public void run (){
  12. Handler. Post (New runnable (){
  13. Public void run (){
  14. Toast. maketext (getapplicationcontext (), "MSG", Toast. length_long). Show ();
  15. Reconnectcounter ++;
  16. This. startconnectionthread ()
  17. }
  18. });
  19. }
  20. }, Sleeptime );
  21. } // End restartconnection
  22. } // End connectionservice

 

4. Disable webview zoom-in and out

XML Code
  1. <Meta content = 'width = device-width; initial-scale = 1.0; maximum-scale = 1.0; User-scalable = 0; 'name = 'viewport'/>
  2. <Meta name = "viewport" content = "width = device-width"/>

 

5. Use the margin code to realize the empty outbound distance around the view

Java code
  1. Extview TV = (textview) findviewbyid (R. Id. my_text_view );
  2. Linearlayout. layoutparams Params = (linearlayout. layoutparams) TV. getlayoutparams ();
  3. Params. setmargins (0, 0, 10, 0); TV. setlayoutparams (Params );

 

6. Use of internal classes

XML Code
  1. <View class = "com. Android. notepad. noteeditor $ myedittext"
  2. Id = "@ + ID/Note"
  3. Android: layout_width = "fill_parent"
  4. Android: layout_height = "fill_parent"
  5. Android: Background = "@ Android: drawable/empty"
  6. Android: padding = "10dip"
  7. Android: scrollbars = "vertical"
  8. Android: fadingedge = "vertical"/>

 

7. Note:

Java code
  1. On the simulator, replace 127.0.0.1 and localhost with 10.0.2.2.
  2. In the LAN environment, you can use 192.168.0.x or 192.168.1.x (depending on the specific configuration) to connect to the local machine.

 

8. decompile the files in the APK or generate the APK:

Java code
  1. Declare in advance that relevant tools must be used
  2. Decompile XML into a format that we can understand
  3. Java-jar axmlprinter2.jar ***. xml> ***. txt
  4. Compile classes. Dex to the classout of the current directory.
  5. Java-jar baksmali. jar-O classout/classes. Dex
  6. The file for compiling classout is classes. Dex.
  7. Java-jar smali. Jar classout/-O classes. Dex
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.