1. Picture rotation
Bitmap bitmaporg = Bitmapfactory.decoderesource (This.getcontext (). Getresources (), R.drawable.moon); Matrix matrix = new Matrix (); Matrix.postrotate (-90);//rotation angle Bitmap Resizedbitmap = Bitmap.createbitmap (bitmaporg, 0, 0,< C0/>bitmaporg.getwidth (), Bitmaporg.getheight (), Matrix, True); Bitmapdrawable BMD = new bitmapdrawable (RESIZEDBITMAP);
2. Get mobile phone number
Create phone Management Telephonymanager TM = (telephonymanager)//Connect with phone Activity.getsystemservice (context.telephony_service);// Get the phone number string Phoneid = Tm.getline1number ();//Remember to add <uses-permissionandroid:name= in manifest file " Android.permission.READ_PHONE_STATE "/>//program cannot be implemented on the simulator, must be connected to the phone
3. Formatting strings in the String.xml
In Strings.xml.. <string name= "My_text" >thanks for visiting%s. You are%d!</string> //And in the Java Code:String.format (getString (R.string.my_text), "Oschina", 33);
4, Android Settings full screen method A. Set in Java code
/** full screen settings, hide windows all decorations */requestwindowfeature (window.feature_no_title); GetWindow (). SetFlags ( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
B. Configure in Androidmanifest.xml
<activity android:name= ". Login.netedit " android:label=" @string/label_net_edit " android:screenorientation=" Portrait "Android: Theme= "@android: Style/theme.black.notitlebar.fullscreen" ><intent-filter><action android:name= " Android.intent.Net_Edit "/><category android:name=" Android.intent.category.DEFAULT "/></intent-filter ></activity>
5, set the activity as dialog form
Configuring the Activity node in Androidmanifest.xml is the configuration theme as follows:
Android:theme= "@android: Style/theme.dialog"
6, check whether the current network is connected
Connectivitymanager con= (Connectivitymanager) Getsystemservice (activity.connectivity_service); Boolean Wifi=con.getnetworkinfo (Connectivitymanager.type_wifi). isconnectedorconnecting ();
To increase permissions in Androidmanifest.xml:
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
7. Detect if a intent is valid
public static Boolean isintentavailable (context context, String action) { final Packagemanager Packagemanager = Conte Xt.getpackagemanager (); Final Intent Intent = new Intent (action); list<resolveinfo> list = packagemanager.queryintentactivities (Intent, Packagemanager.match_default _only); return list.size () > 0;}
8. Android Phone Call
try { Intent Intent = new Intent (intent.action_call); Intent.setdata (Uri.parse ("tel:+110")); StartActivity (intent);} catch (Exception e) { log.e ("SampleApp", "Failed to invoke", E);}
9. Send email in Android
Intent i = new Intent (intent.action_send); I.settype ("Text/plain"); Simulator please use this line i.settype ("message/rfc822"); On the real machine use this line I.putextra (Intent.extra_email, New string[]{"[email protected]", "[email protected]}); I.putextra (Intent.extra_subject, "SUBJECT goes Here"); I.putextra (Intent.extra_text, "body goes Here"); StartActivity (Intent.createchooser (i, "select Email application."));
10. Open browser in Android
Intent viewintent = new Intent ("Android.intent.action.VIEW", Uri.parse ("http://vaiyanzi.cnblogs.com")); StartActivity (viewintent);
11, Android acquisition device unique identification code
String android_id = secure.getstring (GetContext (). Getcontentresolver (), secure.android_id);
12. Get IP address in Android
Public String getlocalipaddress () { try {for (enumeration<networkinterface> en = Networkinterface.getnetworkinterfaces (); En.hasmoreelements ();) { NetworkInterface intf = En.nextelement (); for (enumeration<inetaddress> enumipaddr = intf.getinetaddresses (); enumipaddr.hasmoreelements ();) { InetAddress inetaddress = Enumipaddr.nextelement (); if (!inetaddress.isloopbackaddress ()) { return inetaddress.gethostaddress (). toString ();}}} catch (SocketException ex) { log.e (Log_tag, ex.tostring ()); } return null;}
13. Get the memory card path and usage of Android
Add new contacts to Android
Private Uri insertcontact (context context, string name, String phone) { contentvalues values = new Contentvalues ();
values.put (People.name, NAME); Uri uri = Getcontentresolver (). Insert (People.content_uri, values); Uri Numberuri = Uri.withappendedpath (URI, People.Phones.CONTENT_DIRECTORY); Values.clear (); Values.put (Contacts.Phones.TYPE, People.Phones.TYPE_MOBILE); Values.put (People.number, phone); Getcontentresolver (). Insert (Numberuri, values); return URI;}
15. View Battery Usage
Intent intentbatteryusage = new Intent (intent.action_power_usage_summary); StartActivity (Intentbatteryusage);
Android Common Code