Android 8. Use of intentobject and .apkdecompilation, .intent.apk
Intentobject decompilation using .apkJiangdg_VIPhttp: // blog.csdn.net/u012637501 the first three sections mainly learn the functions, attributes, and values passing between different activities of the Intent object. This section focuses on the usage of the Intent object. In my speech recognition project, you can use Inteng objects to start in-app components, system applications, and third-party applications (such as QQ and so on ).I. Intent object Development MethodFirst, we should first learn the methods for starting the Intent object component (Application:1. Use the Component Attribute of the Intent objectBefore using this method, you must know the package name and Class Name of the component or third-party application to start the components and third-party applications in the application. The Component Attribute of Intent must accept a ComponentName object. A basic ComponentName must specify the package name and class name, which uniquely identifies a Component class. Basic Format: ComponentName comp = new ComponentName (package name, class name); intent. setComponent (comp); The ComponentName object includes the following constructors:. componentName (String pkg, String cls): Create the component corresponding to the cls class under the package of pkg (String form) B. componentName (Context pkg, String cls): Creates the c. componentName (Context pkg, Class <?> Cls): Example of creating a component (context) application corresponding to the cls class under the package where pkg is located:(1) intent starts its own components
Intent intent = new Intent (); ComponentName comp = new ComponentName (PocketSphinxDemo. this, help. class); // use the third constructor intent. setComponent (comp); startActivity (intent );
Note: Here PocketSphinxDemo. this specifies the package of our application, and help. class is the component class to be started in the package.
(2) intent starts third-party applications
Intent intent=new Intent();intent.setClassName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.SplashActivity");startActivity(intent);
Note: The Handler obtains AndroidManifest. the "package" attribute of the xml file and the "android: name" attribute declared as the MAIN constant by action will be detailed in the following article. (3) When intent starts the system program, I think the <intent-filter> method may be better.
2. Use setClass to start the componentBefore using this method, you must know the package name and Class Name of the component or third-party application to start the components and third-party applications in the application. SetClass * is a member method of the Intent class. The function is the same as that of the Component Attribute of the Intent object. All components to be started are specified through the intent. There are also three forms: a. setClass (Context packageContext, Class <?> Cls): sets the Class B of the component to be started by the Intent. setClassName (Context packageContext, String className): Set the Class Name of the component to be started by the Intent c. setClassName (String packageName, String className): Set the class name of the group to be started for this Intent. The Context of the Android Application represents the interface for accessing the environment information of the application, the package name of the Android application is the unique identifier of the application, that is, the Context object has a one-to-one correspondence with the package name of the application. The setClass method specifies the package name and component implementation class. Application Example: (1) intent starts its own component
Intent intent = new Intent (); intent. setClassName (PocketSphinxDemo. this, help. class); // use the third constructor startActivity (intent );
Note: Here PocketSphinxDemo. this specifies the package of our application, and help. class is the component class that has been implemented in the package to be started (2) intent starts a third-party Application
Intent intent=new Intent();intent.setClassName("com.tencent.mobileqq","com.tencent.mobileqq.activity.SplashActivity");startActivity(intent);
Note: The Handler obtains AndroidManifest. the "package" attribute of the xml file and the "android: name" attribute declared as the MAIN constant by action will be detailed in the following article.
3. Use intent-filter to configure (five attributes of the Intent object)The Action and Category attributes of Intent are common strings. The basic idea is to call the Intent member method in the component that sends an "Intent" to set some features of the component to be started, then, the AndroidManifest of the "intent" component is received. whether the <intent-filter> configuration in the xml file meets the "intent" requirement to determine whether it can be started. The Action attribute represents an abstract "Action" to be completed by the Intent. The Category attribute is used to add additional Category information to the Action. The Data attribute is used to provide operation Data to the Action attribute, it accepts the Type attribute of a Uri object to specify the MIME Type corresponding to the Uri specified by the Data. This MIME Type can be any custom MIME Type, as long as the string conforms to the abc/xyz format, the Extras attribute is used for data exchange between multiple actions, that is, value transfer, the Flags attribute is usually used for data transfer and exchange between different activities to add some additional control flag for the Intent. The Intent can call addFlags () method to add control flag for the Intent.
(1) Use intent-filter configuration to start the system programBecause the <intent-filter> attribute setting of the system program in the Android mobile phone can be said to be generic, this method is more convenient and reliable than the previous method. The sample code is as follows:
Enable System camera Intent intent = new Intent (); intent. setAction (MediaStore. INTENT_ACTION_STILL_IMAGE_CAMERA); // start the camera appstartActivity (intent); start the browser Uri uri = Uri. parse ("http://blog.csdn.net/u012637501"); Intent intent = new Intent (); intent. setAction (Intent. ACTION_VIEW); intent. setData (uri); startActivity (intent );
(2) Use intent-filter to start the application componentsA. Create an Intent object and set the attributes of the custom string to the intent.
Intent intent = new Intent (); // create an Intent object String data = "lee: // www.fkjava.org: 8888/mypath"; // custom String Uri uri = Uri. parse (data); // converts a string to Uriintent. setAction (Intent. ACTION_VIEW); intent. setData (uri); // set the Data attribute of the Intent object startActivity (intent); or Intent intent = new Intent (); intent. setAction (Intent. ACTION_VIEW); intent. setData (Uri. parse ("lee: // www.fkjava.org: 8888/mypath"); startActivity (intent); <span style = "background-color: inherit; font-family: 'times New Roman '; "> </span>
B. implement one or more components to be started (such as SecondaryActivity) c. in AndroidManifest. add an <Activity> element for the component (such as Activity) in xml and set <data .. /> related content in the element
<Data android: mimeType = "lee" android: host = "www.fkjava.org" android: port = "8888" android: path = "/mypath" android: pathPrefix = "" android: pathPattern = ""/> can be set to All or selected.
After the above settings, the intent will list a series of components that meet the intent conditions in sequence based on the matching items in the <data.../> element of other components.
Ii. Start third-party applications with Intent objectsIn addition to the application components and system applications, Intent objects can also start third-party applications, such as QQ and file manager. Because the <intent-filter.../> attribute of a third-party application is customized by each application developer, the predefined attribute constants of Intent cannot be called. To successfully start a third-party application, we can use the Component Attribute of the Intent object or call the setClassName method of the Intent class to start the application by specifying the package name and class name of the third-party application. Decompilation.
1. Build the decompilation Environment(1) Win7 x86 (2) Fedora14 or cygwin, that is, the linux compiling environment. Here, I directly use cygwin, which is equivalent to the Linux environment in Windows. The specific installation configuration method configuration, see my blog: http://blog.csdn.net/u012637501/article/details/40480823 (3) decompilation tool: http://download.csdn.net/detail/u012637501/8166977
2.apk decompile and generate the XML configuration, image, language, and other resource files of the program.
(1) Download The Decompilation toolkit and open the apktool1.4.1 folder under the apk2java directory, which contains three files: aapt.exe, apktool. bat, apktool. jar
Note: apktool_bk.jar is the old backup version. It is best to use the latest apktool. jar
(2) switch to the apktool1.4.1 folder and use the apktool. bat tool for decompilation.
A. Switch command:
B. Compile the command:
Apktool. bat command line explanation: apktool. bat d-f [apk file] [Output Folder]
C. decompilation results in the result Folder:
3. Repackage it into an apk.
Re-package the decompiled file into an apk. It is easy to enter apktool. bat B abc123 (the folder you compiled). The command is as follows:
The package apk file is in the directory C: \ HelloAndroid and two folders are generated:
Build
Dist
In this example, package the generated helloandroid.apk under the above dist folder.
4.apk decompile to get the Java source code
Download the decompilation toolkit, open the dex2jar-0.0.9.9 folder under the apk2java directory, contains apk decompilation into java source code tools, as well as source code viewing tools.
Dex2ja: rapk decompilation tool, which is used to convert the classes. dex in the apk into a jar file.
Jdgui: the source code check tool. It is a decompilation tool. You can directly view the source code of the decompilation jar package.
Dex2jar and jdgui are downloaded in the latest version. For details, see google code:
Dex2jar (google code)
For the latest version of jdgui (google code), see the official website
(1) Change the suffix of the apk file to zip and decompress it to obtain the classes. dex, which is compiled by a java file and then packaged by the dx tool. copy dex to dex2jar. the dex2jar-0.0.9.9 folder in the directory where bat is located.
(2) locate the directory dex2jar. bat in the command line and run dex2jar. bat classes. dex to generate classes_dex2jar.jar.
(3rd, double-click jd-gui.exe in the jdguifolder, open the jar package classes_dex2jar.jar generated above, and you will see the source code, such:
The following is a comparison of the HelloAndroid source code before and after decompilation:
After completing the preceding steps, we can decompile the apk installation package and obtain the source code. In fact, if we only need to decompile it to enable Intent to start a third-party application, we only need to perform the second step to obtain the AndroidManifest. xml project file of the installation package. Such as inten .apk
1. decompile ". apk" and view the AndroidManifest. xml project file to obtain the package name and main Activity class name.
2. intent settings
Intent intent=new Intent();intent.setClassName("com.tencent.mm","com.tencent.mm.app.MMApplication");startActivity(intent);