[Top] Android Drip 2

Source: Internet
Author: User
Tags certificate fingerprint md5 file permissions
How to make drawable revolve around the center.
Animation a = new Rotateanimation (0.0f, 360.0f,
animation.relative_to_self, 0.5f, animation.relative_to_self,0.5f );
A.setrepeatcount ( -1);
A.setduration (1000);


How to control the color of the Android LED light.
Many Android phones are equipped with LED lights, such as HTC's phone charging, new text messages, and so will have a response to the instructions, in fact very simple this is notificationmanager some of the parameters, Below Android123 to everyone to say how to control the flashing of LED lights through code, because some models do not have LED lights or color types less, the need for real machine observation.
final int id_led=19871103; 
Notificationmanager nm= (Notificationmanager) Getsystemservice (notification_service);
Notification Notification = new Notification (); 
Notification.ledargb = 0xFFFFFF;  Here is the color, we can try to change, theoretically 0xff0000 is red, 0x00ff00 is green
notification.ledonms =; 
NOTIFICATION.LEDOFFMS = m; 
Notification.flags = notification.flag_show_lights; 
Nm.notify (id_led, notification); 
Nm.cancel (id_led);


How to get the APK file installation time.
Many Android developers want to design a APK management program to get the installation date of apk files. Many netizens don't quite understand. The method used in the early Android123 is to return an ApplicationInfo array through the Getinstalledapplications method of the Packagemanager class. SourceDir in the ApplicationInfo class can obtain the APK file path, which is achieved by using the file class to read the last modified time of the files. But this can lead to:
1. Unable to get the original creation time, it may have been created very early, and then replaced.
2. If the APK is in a private location, such as the App-private directory, using market paid-for-purchase application in this location, if no root Android phone is not authorized to read, it also causes the acquisition time to fail.
In the Android 2.3 API level 9, the ApplicationInfo class new Firstinstalltime and LastUpdateTime fields can be directly obtained to APK's creation or last modified time. Even the paid software can get it properly.

How to distinguish between units PX and DP and SP.
PX (pixels) pixels--Generally we HVGA represent 320x480 pixels, which is much more.
Dip or DP (device independent pixels) device independent pixels-this is related to device hardware, which is generally recommended for WVGA, HVGA, and QVGA CWJ, and does not rely on pixels.
The SP (scaled pixels-best for text size) zooms in on the pixel--mainly the size of the font.
The following few are not commonly used, we also know that here android123 no longer too much to repeat.
In (inches) inches
MM (millimeters) mm
PT (points) point


How to dynamically change the ImageView size.
Many netizens may find that the absolute size of the ImageView is defined in the Layout.xml file and cannot be dynamically modified after the size display, in fact, the Android platform in the design of UI controls to consider this problem, in order to adapt to different drawable can be in the XML related ImageView to add a Ndroid:scaletype= "Fitxy" can be done, but because scaling may cause the current UI to deform. The premise of using is to limit the layer in which ImageView resides, and you can use an inline method to restrict the display.

How do I play an animated GIF in the simplest way on Android?
The principle of GIF animation is to play by frame, in the Android provides a animationdrawable class can be implemented, some netizens wrote gif89a decoding method in the past J2ME platform can also be transplanted to the Android platform, in fact, in Google Android to develop the current firmware support after 2.2 In addition to Flash Player, a better compatibility method is to use the Universal WebKit Browser, we directly in the project embedded in a webview,html as long as a similar img src= "http ://android123.com.cn/cwj.gif "This is OK, of course, you can change the path to local, for browsers to use the local resource URL for the file://start." But WebView resource consumption is also not small, open a WebView object may occupy at least 8MB Ram bar, conservative estimate, of course, more depends on the plug-in and HTML complexity of the decision.

How to call the phone system dialing page.
/* Bring up the Contact interface * *
Intent Intent = new Intent ();
Intent.setaction (Intent.action_view);
Intent.setdata (ContactsContract.Contacts.CONTENT_URI);//android2. X
startactivity (intent);

/* Call to dial the screen * *
Intent myintentdial = new Intent ("Android.intent.action.CALL_BUTTON");
StartActivity (myintentdial);

Add Permission:
<uses-permission android:name= "Android.permission.CALL_PHONE"/>

How to obtain the number of GPS satellites.
Locationmanager manager = (Locationmanager) getsystemservice (context.location_service);
Iterator<gpssatellite> iterator = Manager.getgpsstatus (null). Getsatellites (). iterator ();
int count = 0;
while (Iterator.hasnext ()) {
        count++
}
return count; 


How to tell if a mobile phone has no network?
Connectivitymanager Cwjmanager = (connectivitymanager) getsystemservice (context.connectivity_service);
		if (cwjmanager.getactivenetworkinfo ()!= null) {
			if (Cwjmanager.getactivenetworkinfo (). IsAvailable ()) {
				String type = Cwjmanager.getactivenetworkinfo (). Gettypename ();
				System.out.println ("_____________________-" + type);
			}
			;
		} else {
			System.out.println ("_____________________-" + cwjmanager.getactivenetworkinfo ());
		}

If you want to develop a network application program, first consider whether to access the network, in the Android phone to determine whether networking can be through the Connectivitymanager class IsAvailable () method to determine, first of all, to obtain the network communication class instance, Use Cwjmanager.getactivenetworkinfo (). isavailable (); To return valid, if true means that the current Android phone is networked, may be WiFi or GPRS, HSDPA, etc., specific through the Connectivitymanager class Getactivenetworkinfo () Methods to judge the detailed access mode, it should be noted that the relevant calls need to join <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" ></ Uses-permission> this permission, in the real machine market and browser programs have used this method to determine whether to continue, while some network timeout can also check the existence of network connections, so as not to waste the phone on the power resources.

How to get the version of your own program.
 Private String mversion;   
Public String longversion () {  
        if (mversion = = null) {  
            Packagemanager pm = Getpackagemanager ();  
            PackageInfo Pi;  
            try {  
                pi = Pm.getpackageinfo (getpackagename (), 0);  
                Mversion = Pi.versionname;  
                System.out.println ("Mversion----------------->" +mversion);  
            } catch (Namenotfoundexception e) {  
                mversion = ""; Failed, ignored  
            }  
        } return  
        mversion;  
  


The difference between drawable-hdpi, drawable-mdpi and drawable-ldpi:
In the previous release, there was only one drawable, while the 2.1 version had drawable-mdpi, drawable-ldpi, drawable-hdpi Three, and the three were mainly to support multiresolution.
(1) drawable-hdpi contains high-resolution pictures, such as WVGA (480x800), FWVGA (480x854)
(2) drawable-mdpi inside the medium resolution of the picture, such as HVGA (320x480)
(3) drawable-ldpi inside the low resolution of the picture, such as QVGA (240x320)
The system will be based on the resolution of the machine to each of these folders to find the corresponding picture. To be compatible with different screens for different platforms when developing programs, it is recommended that the respective folders store different versions of the picture according to the requirements.

How to understand the context.
Contextual literal meaning context.
is located in the framework Package in the Android.content.Context, in fact, the class is long, similar to the handle handle in Win32, many methods need to pass the context to identify the caller's instance, for example, the first parameter of toast is the context, generally in the Activi Ty we use this directly instead, on behalf of the caller's instance for the activity, and to a button of the onclick (view view) and other methods, we use this when the error, So we might use activityname.this to solve the problem, mainly because the classes that implement the context mainly have several Android-specific models, activity, service, and Broadcastreceiver.
The general need for context instances of the method is mainly a variety of service implementations of the class, such as Sensormanager in the instantiation of the need for Getsystemservice (String) method must be executed by the instance of the context, There are also some proprietary file system I/O such as openfileinput and commonly used toast maketext methods.

How to apply for Apikey for Android Mapview.
1. First get your debug KeyStore location:
Open the eclipse--->windows--->preferences--->android--->build
View the default debug KeyStore location, mine is C:\Documents and Settings\android123\.android\debug.keystore
2. Executing in cmd:
Keytool-list-alias Androiddebugkey-keystore "C:\Documents and Settings\android123\.android\debug.keystore"- Storepass Android-keypass Android
Double quotes for your keystore position
Execution results:
Androiddebugkey, May 4, 2009, Privatekeyentry,
Certificate fingerprint (MD5): XX:XX:XX:XX:XX:XX:XX:XX ......
Here's the XX:XX:XX:XX:XX:XX:XX:XX ...... That's your certified fingerprint.
3. Open http://code.google.com/intl/zh-CN/android/maps-api-signup.html
Fill in your Certified fingerprint (MD5) to obtain the Apikey, the results show as follows:
Your key is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
4. Use of Apikey: Add Mapview in Layout
<com.google.android.maps.mapview
Android:id= "@+id/mapview"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:apikey= "Xxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>

How to understand the inheritance of onintercepttouchevent () event-handling clicks.
The mechanism of Onintercepttouchevent ():
1. The down event is first passed to the Onintercepttouchevent () method
2. If the ViewGroup onintercepttouchevent () return false after receiving the down event processing,
Subsequent moves, up, and so on will continue to be passed to the viewgroup before being passed to the
Ontouchevent () processing of the final target view
3. If the ViewGroup onintercepttouchevent () return true after receiving the down event processing,
Subsequent moves, up, and so on, will no longer be passed to Onintercepttouchevent (), but the same as the down event
Passed to the ViewGroup ontouchevent () processing, noting that the target view will not receive any events.
4. If the Ontouchevent () of the view that ultimately needs to handle the event returns false, the event is passed to the previous
Ontouchevent () Processing of Hierarchy view
5. If the ontouchevent () of the view that ultimately needs to handle the event returns true, subsequent events can continue to pass
Ontouchevent () processing for the view

How to completely shut down the Android app (Back button).
In the development of Android applications, often by pressing the return key (that is, keycode = = Keyevent.keycode_back) can close the program, in fact, most of the application is still running in the task, in fact, this is not the result we want.
We can do this, when the user clicks the Custom exit button or returns the key (needs to capture the action), we forcibly exits the application in the OnDestroy (), or kills the process directly, the concrete operation code is as follows:
@Override Public
	boolean onKeyDown (int keycode, keyevent event) {
		
		//press the return button on the keyboard
		if (keycode = = Keyevent.keycode_back) {
						finish ();
			return true;
		} else{return		
			Super.onkeydown (KeyCode, event);
		}
	}
	@Override
	protected void OnDestroy () {
		Super.ondestroy ();
		
		System.exit (0);
		Or the following way
		//android.os.process.killprocess (Android.os.Process.myPid ()); 
	}


How to get all the Activty interface to remove the title bar completely.
Modify the Androidmanifest.xml and add it to the Application tab.
Android:theme= "@android: Style/theme.notitlebar"

When multiple ImageView together use the same resource file for example: Demo.png, if we use code to control one of the ImageView states, such as Alpha, it also affects other imageview states, This time we can avoid this by doing the following:
Res_ico is a picture resource file ID r.drawable.***
drawable ico = Getresources (). getdrawable (Res_ico);
ImageView IV = new ImageView (this);
Iv.setbackgrounddrawable (ICO);
Iv.setclickable (false);
Iv.setadjustviewbounds (true);
Ico.mutate (). Setalpha (20);


How to determine whether the GPS is open and jump to set the GPS interface.
Check whether the GPS is open
locationmanager.isproviderenabled ("GPs"); 

Go to the GPS settings interface
startactivity (new Intent ("Android.settings.LOCATION_SOURCE_SETTINGS"));


How to get a mobile phone version of information.
Get the phone SDK version and version number
System.out.println ("version->" +android.os.build.version.sdk);
System.out.println ("version->" +android.os.build.version.release);	
Get product model
System.out.println ("version->" +android.os.build.model);


How to simulate the impact of the home key on Android development.
 Intent i= New Intent (intent.action_main);
 I.setflags (intent.flag_activity_new_task); 
In the case of a service call, the new task identifier
 i.addcategory (intent.category_home) must be added;


How to kill the process.
A new API in Android 2.2 can help us kill background processes, but the API level of the call is minimal to 8. Killbackgroundprocesses is a Android.app.ActivityManager class method that must be added to the Androidmanifest.xml file when used Kill_background_ Processes this permission.
The method's prototype public void Killbackgroundprocesses (String packagename) has only one argument for package Name, which is simpler to use:
 Activitymanager am = (activitymanager) getsystemservice (activity_service); 
Am.killbackgroundprocesses ("CN.COM.ANDROID123.CWJ");   
API level is at least 8 to use


How to manipulate interface elements through handler in child threads.
Android.os.Handler hander = new Android.os.Handler ();					Hander.postdelayed (New Runnable ()
{public
void run ()
{
  Ad.dismiss ();
}
}, 5 * 1000);

How to clear the desktop wallpaper.
Clearwallpaper ();


But we need to set the wallpaper Change permission:
<uses-permission android:name= "Android.permission.SET_WALLPAPER"/>


How to request permission to access the SDcard.
 <!--Create and delete file permissions in SDcard--> <uses-permission android:name= "android.permission.MOUNT_ Unmount_filesystems "/> <!--Write data permissions to SDcard--> <uses-permission android:name=" android.permission.WRITE_ External_storage "/> 
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.