Project Source Download
Https://github.com/Wang-Jun-Chao/AndroidProjects
Directory structure for Android projects
Activity: The interface that is displayed when the application is opened
SRC: Project Code
R.java: Resource IDs for all resource files in the project
Android.jar:Android jar Package, import this package to use the Android API
Libs: Importing third party jar packages
Assets: Store resource files, such as MP3, video files
Bin: Store the compiled and packaged files
Res: Store resource files, all resource files stored in this folder will generate resource IDs
Drawable: Storing picture resources
Layout: Store the layout file, assign the layout file to the activity through the resource ID, and the interface will show the layout of the layout file definition
Menu: Define style for menus
Strings.xml: Storing string resources, each resource will have a resource ID
Android configuration file (manifest file)
Specify the package name for the application
package="com.itheima.helloworld"
Data/data/com.itheima.helloworld (the package name specified in the code above)
Application generated files are stored under this path
Android's four components need to be configured in the manifest file before use
The configuration is effective for the entire application
The configuration is in effect for the activity
DDMS
Dalvik Debug Monitor Service
Dalvik Debugging and Monitoring service
The common ADB directive
Android Debug Bridge: Android Debugging Bridges
ADB start-server: Start adb process
ADB kill-server: Killing the ADB process
ADB devices: View the device that is currently connected to the development environment, and this command can also start the ADB process
ADB install xxx.apk: Installing APK to Simulator
ADB Uninstall Package Name: Removing the application in the simulator
ADB shell: Go to linux command line
PS: View the running process
LS: View the file structure under the current directory
Netstat-ano: View the process of seizing ports
Phone Dialer
Function: The user enters a number, clicks the call button, starts the system to call the application to dial out the number
1. Define Layout
The component must be set to a wide height, otherwise it cannot be compiled
android:layout_width="wrap_content"
android:layout_height="wrap_content"
If you want to manipulate a component in Java code, the component needs to set the ID so that you can get the component by ID in your code
android:id="@+id/et_phone"
2. Set click on the button to listen
Set the button to listen
// Get the button object by id
Button bt_call = (Button) findViewById (R.id.bt_call);
// Set the button to click
bt_call.setOnClickListener (new MyListener ());
3. Get the number entered by the user
//Get the number entered by the user, first get the input box component
EditText et_phone = (EditText) findViewById(R.id.et_phone);
String phone = et_phone.getText().toString();
4. Call the number out.
Android system based on the action mechanism to invoke the application of the system, you tell the system what you want to do, the system will be able to do this action application to you, without this application, will throw the exception
Set the action to inform the system by intent
//Dial out the number
// First create an intent object
Intent intent = new Intent ();
// Set the action and call
intent.setAction (Intent.ACTION_CALL);
intent.setData (Uri.parse ("tel:" + phone));
// tell the system
startActivity(intent);
Add permissions
<uses-permission android:name="android.permission.CALL_PHONE"/>
Four ways to spell the Click event
First Kind
Define a MyListener implementation Onclicklistener interface
Button bt1 = (Button) findViewById(R.id.bt1);
bt1.setOnClickListener(new MyListener());
Second Kind
Define an anonymous inner class to implement the Onclicklistener interface
Button bt2 = (Button) findViewById(R.id.bt2);
bt2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("第二种");
}
});
Third Kind
Let the current activity implement the Onclicklistener interface
Button bt3 = (Button) findViewById(R.id.bt3);
bt3.setOnClickListener(this);
Fourth Kind
Set the OnClick property to the button node.
android:onClick="click"
Then define a method in the activity with the same name as the property value
public void click(View v){
System.out.println("第四种");
}
SMS Transmitter
Function: User input number and SMS content, click send button, call SMS API to send SMS to the specified number
1. Define Layout
Tips for entering boxes
android:hint="please input the number"
2. Complete the Click event
Set the OnClick property for the button component first
onclick= "Send"
Define this method in the activity
public void Send (View v) {}
3. Get the number and content entered by the user
EditText et_phone = (EditText) findViewById(R.id.et_phone);
EditText et_content = (EditText) findViewById(R.id.et_content);
String phone = et_phone.getText().toString();
String content = et_content.getText().toString();
4. Invoke API to send SMS
// Call the API for sending SMS
SmsManager sm = SmsManager.getDefault ();
//send messages sm.sendTextMessage(phone, null, content, null, null);
* Add Permissions
<uses-permission android:name="android.permission.SEND_SMS"/>
* If the message is too long, you need to split
List<String> smss = sm.divideMessage(content);
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/