Android's own app analysis: SMS App

Source: Internet
Author: User

The Android operating system itself is a huge open source repository, familiar to both the design framework of the Android system and the efficient way to write applications. This article analyzes the source code from Google's official AOSP source 4.0.1_r1, the Android version of the mobile phone is cm 4.2.2. For the Android system analysis, the operating system version of the mobile phone and the source version of some inconsistencies will not have much impact, but if you need to install the source code changes to the inside of the phone, the most difficult way is to keep the system version of the phone and the source version of the complete agreement.

1. Procedure Entrance Discovery

Each application should have its own portal, and an Android application written using Java is no exception. Confirming the application's entry is the first step in confirming the application to the source code in the system, as well as the first step in application analysis. My approach is to run the SMS app that needs to be analyzed and get the name of the activity that currently occupies the main interface with the Android tool.

The answer in StackOverflow http://stackoverflow.com/questions/13193592/ Adb-android-getting-the-name-of-the-current-activity gives three solutions to this problem:

1) Dozen Hierarchy view (Window->open perspective->other->hierarchy view), The current occupy screen activity and package are shown in bold in the Windows bar, as shown in the following figure. Where Com.android.mms is the package name of the application, Com.adnroid.mms.ui.ConversationList is the specific activity name.

2) You can also open the Windows bar directly to view. (Window->show view->others->windows), the results are consistent with the above figure.

3 Use dumpsys command: adb shell "Dumpsys window Windows | Grep-e ' Mcurrentfocus|mfocusedapp ', the results are as follows:

Dumpsys use method See: Http://stackoverflow.com/questions/11201659/whats-android-adb-shell-dumpsys-tool-and-its-benefits

2. Program function analysis

After confirming the application of SMS app and the main activity, you can search by software (here is everything) to determine the location of the SMS app in the source code is Packages\apps\mms\src\com\android\mms\ui, And the start activity of SMS app is inherited from Listactivity conversationlist.

1) Construction of Actionbar

Load the menu item in the Oncreateoptionsmenu function by importing Conversation_list_menu.

public boolean Oncreateoptionsmenu (Menu menu) {   
    getmenuinflater (). Inflate (R.menu.conversation_list_menu, menu);
Conversation_list_menu.xml set: Send, search, set, delete all 5 buttons.
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:id= "@+id/action_c"
        Ompose_new "android:title=" @string/new_message "android:icon=" @drawable/ic_menu_msg_compose_holo_dark " android:showasaction= "Always|withtext"/> <item android:id= "@+id/search" android:titl E= "@string/menu_search" android:icon= "@drawable/ic_menu_search_holo_dark" android:showasaction= "Ifroom |collapseactionview "android:actionviewclass=" Android.widget.SearchView "/> <item android: Id= "@+id/action_settings" android:title= "@string/menu_preferences" android:icon= "@android:d Rawable/ic_menu _preferences "/> <item android:id=" @+id/action_delete_all "android:title=" @string/menu_delet E_all "android:icon=" @drawable/ic_menu_trash_holo_dark "/> <item android:id=" @+id/action_deb Ug_dump "Android: title= "@string/menu_debug_dump"/> </menu> 

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.