Comparison between the Android SDK version and version name and a programming tips

Source: Internet
Author: User

A few days ago, in order to solve a problem, we reversed a small tool software. I have found some useful things in this process. I would like to share with you here. First, declare a few points: 1. The reverse Code requires a lot of manual analysis. I only read a little bit. 2. The Code will not be made public. Please do not ask me for the code, I am afraid of trouble ~~~ Alas, I am sorry for this bad thing ~~~ ~~~ Ah!

1. Implement the GPS switch through programming

On the Android mobile phone and simulator, there is a configuration interface for managing the GPS switch, as shown below:

Through this management interface, we can manage GPS to implement our mobile phone positioning function. I used to collect information on the Internet, hope to find the source code for GPS management through code, and I did find a piece of code (I will attach the code later ), however, this code cannot run in SDK 2.3 or later versions. As a result, an evil idea is generated ~

After analyzing the tool mentioned above, we found its function module for GPS management. After a simple analysis, we found that when the Android SDK version is different, the GPS control code is also different. First, the GPS control code in version 2.2 and earlier is attached:

/**
* A gps switch is implemented. If the current switch is disabled, the switch is enabled. If the current switch is enabled, the switch is disabled.
* Applicable version:
* 1.6/2.1/2.2
*
* The enumerated values of Number 3 in Uri. parse () parameter "custom: 3" are as follows:
* Private static final int BUTTON_BLUETOOTH = 4;
* Private static final int BUTTON_BRIGHTNESS = 1;
* Private static final int BUTTON_GPS = 3;
* Private static final int BUTTON_SYNC = 2;
* Private static final int BUTTON_WIFI = 0;
*
*/
Private VoidToggleGPS (){
//When the SDK version is earlier than 2.3
If(Build. VERSION. SDK_INT<Build. VERSION_CODES.GINGERBREAD ){
Intent gpsIntent= NewIntent ();
GpsIntent. setClassName ("Com. android. settings",
"Com. android. settings. widget. SettingsAppWidgetProvider");
GpsIntent. addCategory ("Android. intent. category. ALTERNATIVE");
GpsIntent. setData (Uri. parse ("Custom: 3"));
Try{
PendingIntent. getBroadcast (This,0, GpsIntent,0). Send ();
}Catch(CanceledException e ){
E. printStackTrace ();
}
}
}

The above Code uses the Widget plug-in provided by the Android platform to manage various switches. A gps switch is implemented. If the current GPS is off, turn it on; if the GPS is on, turn it off.

You may have noticed that the first line in the function body comments "when the SDK version is 2.3 or lower". We have made a judgment on the SDK version here. This judgment is also the content that we will focus on in the next section. We will put it aside for the time being. Don't be biased in this section.

In SDK 2.3 and later versions, the tool uses a static method of Settings. Secure in the SDK class:

Public static final voidSetLocationProviderEnabled (ContentResolver cr, String provider, boolean enabled)

Since: API Level 8

Thread-safe method for enabling or disabling a single location provider.

Parameters

Cr

The content resolver to use

Provider

The location provider to enable or disable

Enabled

True if the provider shocould be enabled

This method is provided from API Level 8. the SDK version corresponding to API Level 8 is 2.2, OK! Normally, this function should support SDK2.3. Write a function. (This code is relatively simple, so I will not post the code again.) The result is surprising, but the user is not assigned the permission "android. permission. WRITE_SETTINGS "; well, add the permission, and prompt that the permission" android. permission. WRITE_SECURE_SETTINGS. Next, we will see the sad reminder that we do not have the permission to "android. permission. WRITE_SECURE_SETTINGS. Why do I still prompt if I already have permissions added. Finally, I also searched for materials in various forums, saying that Google had completely locked this permission in Version 2.3. Well, it's a tragedy, unless you change the Android code yourself, otherwise, there will be no other way.

So, at the end of section 1, I would like to remind you that if you want to manage GPS in SDK2.3, you should use your Intent to open the system's default GPS-managed Activity.

Ii. SDK version Comparison

In order to download the android SDK source code, I looked for a link everywhere and found that there was something similar to the English name behind the file name?

Indeed, beginners like me do not know what this English word means. However, in the process of inverse code, we found that the Android API provided such a class android. OS. build: This class defines the version number, version name, and other information of each Android SDK version. If you are interested, go to the development documentation.

The English word here is the version name of each SDK version.

VERSION_CODES

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.