Create and use an android SD card

Source: Internet
Author: User

How to create an SD card and create a full solution for uploading materials and folders in the android Simulator

Recently I am working on an application to create an SD card on the android simulator and put some files in it. Write some of your own experiences:

There are two methods. There are many search methods on Baidu, almost one version:

Use the CMD command to create an SD card. This method is intuitive and easy to understand:

1. Create an image file

Run cmd to enter the tools directory of the android SDK and run mksdcard to create the SDK.

For example, my tools directory is: e: \ Skyland \ android-sdk-windows-1.0_r2 \ tools>

Then: e: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> mksdcard 128 M sdcard. img

The first parameter is the size of the sdcard to be created (determined by the size), and the second parameter is the name of the sdcard.

2. Start the android simulator with sdcard

In the DOS interface just now, E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> emulator-sdcard. img

In this way, a folder named sdcard. IMG. Lock is generated dynamically under the tools directory, and disappears when the simulator is disabled.

Note: Do not close this DOS window. Otherwise, the simulator will be closed and the subsequent step cannot be executed.

3. Add a file to sdcard

In addition, to open a DOS window (CMD), you still need to CD it to the tools directory of the android SDK, and use the ADB push command to add

E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> ADB push new. jpg/sdcard

The first parameter is the full name of the image (mp3) to be added. If there is a space in the name, enclose it with double quotation marks.

For example: e: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> ADB push "first startcard"/sdcard

The second parameter is the newly created sdcard.

4. view the added file

In this step, you may need to restart the android simulator with sdcard to view the resource file you just added. That is, you must first turn off the simulator,

Then E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> emulator-sdcard. img

After the simulator is started, click the arrow --> Dev tools --> raw image Viewer on the menu to display the slides.

See the newly added

Image file, and then control the Image Browsing by following the following left and right

Some people say that the arrow --> Dev tools --> media plugin on the menu can be used to view the added MP3 file.

Yes. If any, leave a message...

My method is: the arrow --> music --> songs on the menu shows the added MP3 file. Click enjoy.

The first English name was originally used, but I don't know why it was garbled. The name of the file I added is different from the name of the display song.

============ Using sdcard in myeclipse ================

If the. imgfile is not created, go back to the beginning and do step 2.

Note: If you do not start the simulator in step 1 but do the following, an error will be reported saying that sdcard is a read-only file,

Failed to add

1. Start mueclipse and choose Window> perspective> Other> ddms.

Select the sdcard and click push to add the image resources to the sdcard.

2. Use sdcard resources to compile Android scripts

If you need to use sdcard resources when compiling Android applications

Right-click Run as --> open run dialog --> Target

Add the startup parameter to the aditional emulator command line options of the target tag.

-Sdcard E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools \ sdcard

Note: it is an absolute path.

If the simulator is not started in step 2, the corresponding sdcard In the permissions column will be "---------"

++ ++

Android SDK + eclipse provides the SD card simulation method. The usage is as follows:

1. Create an SD card image file.

Open CMD and enter the following command:

Mksdcard 1024 M sdcard. img

This command will generate an sdcard. imgfile in the current directory, which is the SD card image file of the android simulator.

1024 MB indicates 1024 MB, that is, the SD card has 1 GB capacity, and K can also be used as the unit (1 m = K). K and m must be capitalized.

Android currently supports 8 m ~ Gb sd card.

2. Run the simulator with an SD card

You have created an SD card image file, but you have created a file that cannot be directly used in the simulator. You can see the SD card in the simulator in either of the following ways:

◆ In cmd, the command is as follows:

Emulator-sdcard E: sdcard. img

◆ In eclipse, enter the startup parameters in the target tab in the "run-> RUN configurations..." menu, for example:

3. Export files to the SD card

◆ In cmd, the command is as follows:

In this case, the test.txt file under the current directory will be admitted to the sdcard, and the file name will not change. The first test.txt is the path of the local file, and sdcard is the name of the target sdcard image (remove the suffix ).

◆ In eclipse, perform the following operations:

After setting the run command parameters, run an application and use the file explorer tool of ddms to import and export files.

Open the ddms tool: Open the ddms tool in the eclipse window-> open perspective-> other.

On the "file Explorer" tab of ddms, select the sdcard directory to import and export files, for example:

4. Use the files in the SD card in the simulator

After the file is imported, if you want to access it in the simulator, you also need to scan the media file in Dev tools of the simulator.

****************************************

The above describes how to create and import files, but the ADB command is required to create a folder in the image SD card and delete uploaded files. Below are some comprehensive ADB commands:

Common android ADB shell commands

I learned some tips about the ADB tool, which is recorded here. The operating system is for Windows.

1. display all android platforms in the system:
Android list targets
2. Display All AVD (simulators) in the system ):
Android list AVD
3. Create an AVD (simulator ):
Android create AVD -- name -- Target Platform ID
4. Start the simulator:
Emulator-AVD name-sdcard ~ /Name. IMG (-skin 1280x800)
5. Delete AVD (simulator ):
Android Delete AVD -- name
6. Create an sdcard:
Mksdcard 1024 M ~ /Name. img
7. AVD (simulator) Location:
Linux (~ /. Android/AVD) Windows (C: \ Documents ents and Settings \ Administrator \. Android \ AVD)
8. Start ddms:
Ddms
9. display all currently running simulators:
ADB Devices
10. Run the following command on a simulator:
Abd-s simulator serial number command
11. Install the application:
ADB install-R application .apk
12. Get the files in the simulator:
ADB pull <remote> <local>
13. Write a file to the simulator:
ADB push <local> <remote>
14. Enter the shell mode of the simulator:
ADB Shell
15. Start the SDK, documentation, and instance Download Manager:
Android
16. Upload the APK package:
ADB Shell
CD Data/APP
Rm APK package
Exit
ADB uninstall APK package MAIN package name
ADB install-r APK package
17. view the ADB Command help information:
ADB help
18. view log information in the command line:
ADB logcat-s label name
19. The commands followed by the ADB shell mainly come from:
Source code \ System \ core \ toolbox directory and source code \ frameworks \ base \ cmds directory.
20. delete system applications:
ADB remount (re-mount the system partition to make the system partition writable ).
ADB Shell
CD system/APP
RM *. APK
21. Get administrator permissions:
ADB Root
22. Start activity:
ADB shell am start-N package name/package name + class name (-N class name,-A action,-d date,-M mime-type,-C category, -E ).
23. Release Port:
You can set any port number as the request port from the host to the simulator or device. For example:
ADB forward TCP: 5555 TCP: 8000
24. copy a file:
You can copy files to or from a device,
Copy a file or directory to the device or simulator:
ADB push <source> <destination> </source>
Example: ADB push test.txt/tmp/test.txt
Copy a file or directory from a device or simulator:
ADB pull <source> <destination> </source>
For example, ADB pull/addroid/lib/libwebcore. So.
25. Search for simulator/device instances:
Obtain the list of running Simulators/devices and the status of each instance:
ADB Devices
26. view the bug report:
ADB bugreport
27. Record wireless communication logs:
In general, there are a lot of wireless communication logs and there is no need to record them during operation, but we can still set the record through the command:
ADB Shell
Logcat-B radio
28. Obtain the device ID and serial number:
ADB get-Product
ADB get-serialno
29. Access the database sqlite3
ADB Shell
Sqlite3

# Cd system/SD/Data // enter the specified folder in the system
# Ls // the contents of the current folder are displayed in the list
# Rm-r XXX // delete a folder named XXX and all its files
# Rm XXX // delete file xxx
# Rmdir XXX // Delete the xxx folder

# Non-blocking logcat
The-D parameter can be used to return results after reading all logs without waiting for them. It is useful in automation. For example:
ADB logcat-d-s XXX> XXX. Log // obtain the log whose filter is XXX, store it in XXX. log, and return.
# Use grep to filter logs
Windows does not matter. grep has a Windows version. In fact, after cygwin is installed, it carries grep.
ADB logcat | grep XXX // filter logs with xxx characters
# Execute commands in the ADB shell locally
We often need ADB shell to execute some commands on the device. In fact, you can directly execute commands on the device and output the commands to the local device without entering the shell. For example:
ADB shell "am start-N com. AAA. BBB/COM. AAA. BBB. Activity" // start a program
# Use top to view CPU usage
You can use top in the ADB shell to view CPU and memory usage. The-M parameter can only display the first few items, and the-n parameter can only be refreshed several times, and then return, it is no longer blocked and useful in automation. For example:
ADB shell "Top-N 1" | grep COM. AAA. bbb // if you do not enter the shell, execute the TOP command locally only once and filter out com. AAA. the row of BBB. Through the output, you can get the CPU usage of the program, or determine whether the program has exited.
# Use ADB devices to check whether a connected device exists
ADB devices can be used to list all connected devices with online/offline signs. Based on the analysis output, you can determine whether devices are available and which devices are available.
# Batch upload/download files to devices
ADB push and ADB pull can only upload one file at a time. The for command can be used for batch processing:
ADB shell "mkdir/sdcard/YUV" // create/sdcard/YUV directory on the device
For % I in (*. YUV) Do ADB push % I/sdcard/YUV // upload all files with the YUV extension in the current directory to the/sdcard/YUV/directory.

How to create an SD card and create a full solution for uploading materials and folders in the android Simulator

Recently I am working on an application to create an SD card on the android simulator and put some files in it. Write some of your own experiences:

There are two methods. There are many search methods on Baidu, almost one version:

Use the CMD command to create an SD card. This method is intuitive and easy to understand:

1. Create an image file

Run cmd to enter the tools directory of the android SDK and run mksdcard to create the SDK.

For example, my tools directory is: e: \ Skyland \ android-sdk-windows-1.0_r2 \ tools>

Then: e: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> mksdcard 128 M sdcard. img

The first parameter is the size of the sdcard to be created (determined by the size), and the second parameter is the name of the sdcard.

2. Start the android simulator with sdcard

In the DOS interface just now, E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> emulator-sdcard. img

In this way, a folder named sdcard. IMG. Lock is generated dynamically under the tools directory, and disappears when the simulator is disabled.

Note: Do not close this DOS window. Otherwise, the simulator will be closed and the subsequent step cannot be executed.

3. Add a file to sdcard

In addition, to open a DOS window (CMD), you still need to CD it to the tools directory of the android SDK, and use the ADB push command to add

E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> ADB push new. jpg/sdcard

The first parameter is the full name of the image (mp3) to be added. If there is a space in the name, enclose it with double quotation marks.

For example: e: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> ADB push "first startcard"/sdcard

The second parameter is the newly created sdcard.

4. view the added file

In this step, you may need to restart the android simulator with sdcard to view the resource file you just added. That is, you must first turn off the simulator,

Then E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools> emulator-sdcard. img

After the simulator is started, click the arrow --> Dev tools --> raw image Viewer on the menu to display the slides.

See the newly added

Image file, and then control the Image Browsing by following the following left and right

Some people say that the arrow --> Dev tools --> media plugin on the menu can be used to view the added MP3 file.

Yes. If any, leave a message...

My method is: the arrow --> music --> songs on the menu shows the added MP3 file. Click enjoy.

The first English name was originally used, but I don't know why it was garbled. The name of the file I added is different from the name of the display song.

============ Using sdcard in myeclipse ================

If the. imgfile is not created, go back to the beginning and do step 2.

Note: If you do not start the simulator in step 1 but do the following, an error will be reported saying that sdcard is a read-only file,

Failed to add

1. Start mueclipse and choose Window> perspective> Other> ddms.

Select the sdcard and click push to add the image resources to the sdcard.

2. Use sdcard resources to compile Android scripts

If you need to use sdcard resources when compiling Android applications

Right-click Run as --> open run dialog --> Target

Add the startup parameter to the aditional emulator command line options of the target tag.

-Sdcard E: \ Skyland \ android-sdk-windows-1.0_r2 \ tools \ sdcard

Note: it is an absolute path.

If the simulator is not started in step 2, the corresponding sdcard In the permissions column will be "---------"

++ ++

Android SDK + eclipse provides the SD card simulation method. The usage is as follows:

1. Create an SD card image file.

Open CMD and enter the following command:

Mksdcard 1024 M sdcard. img

This command will generate an sdcard. imgfile in the current directory, which is the SD card image file of the android simulator.

1024 MB indicates 1024 MB, that is, the SD card has 1 GB capacity, and K can also be used as the unit (1 m = K). K and m must be capitalized.

Android currently supports 8 m ~ Gb sd card.

2. Run the simulator with an SD card

You have created an SD card image file, but you have created a file that cannot be directly used in the simulator. You can see the SD card in the simulator in either of the following ways:

◆ In cmd, the command is as follows:

Emulator-sdcard E: sdcard. img

◆ In eclipse, enter the startup parameters in the target tab in the "run-> RUN configurations..." menu, for example:

3. Export files to the SD card

◆ In cmd, the command is as follows:

In this case, the test.txt file under the current directory will be admitted to the sdcard, and the file name will not change. The first test.txt is the path of the local file, and sdcard is the name of the target sdcard image (remove the suffix ).

◆ In eclipse, perform the following operations:

After setting the run command parameters, run an application and use the file explorer tool of ddms to import and export files.

Open the ddms tool: Open the ddms tool in the eclipse window-> open perspective-> other.

On the "file Explorer" tab of ddms, select the sdcard directory to import and export files, for example:

4. Use the files in the SD card in the simulator

After the file is imported, if you want to access it in the simulator, you also need to scan the media file in Dev tools of the simulator.

****************************************

The above describes how to create and import files, but the ADB command is required to create a folder in the image SD card and delete uploaded files. Below are some comprehensive ADB commands:

Common android ADB shell commands

I learned some tips about the ADB tool, which is recorded here. The operating system is for Windows.

1. display all android platforms in the system:
Android list targets
2. Display All AVD (simulators) in the system ):
Android list AVD
3. Create an AVD (simulator ):
Android create AVD -- name -- Target Platform ID
4. Start the simulator:
Emulator-AVD name-sdcard ~ /Name. IMG (-skin 1280x800)
5. Delete AVD (simulator ):
Android Delete AVD -- name
6. Create an sdcard:
Mksdcard 1024 M ~ /Name. img
7. AVD (simulator) Location:
Linux (~ /. Android/AVD) Windows (C: \ Documents ents and Settings \ Administrator \. Android \ AVD)
8. Start ddms:
Ddms
9. display all currently running simulators:
ADB Devices
10. Run the following command on a simulator:
Abd-s simulator serial number command
11. Install the application:
ADB install-R application .apk
12. Get the files in the simulator:
ADB pull <remote> <local>
13. Write a file to the simulator:
ADB push <local> <remote>
14. Enter the shell mode of the simulator:
ADB Shell
15. Start the SDK, documentation, and instance Download Manager:
Android
16. Upload the APK package:
ADB Shell
CD Data/APP
Rm APK package
Exit
ADB uninstall APK package MAIN package name
ADB install-r APK package
17. view the ADB Command help information:
ADB help
18. view log information in the command line:
ADB logcat-s label name
19. The commands followed by the ADB shell mainly come from:
Source code \ System \ core \ toolbox directory and source code \ frameworks \ base \ cmds directory.
20. delete system applications:
ADB remount (re-mount the system partition to make the system partition writable ).
ADB Shell
CD system/APP
RM *. APK
21. Get administrator permissions:
ADB Root
22. Start activity:
ADB shell am start-N package name/package name + class name (-N class name,-A action,-d date,-M mime-type,-C category, -E ).
23. Release Port:
You can set any port number as the request port from the host to the simulator or device. For example:
ADB forward TCP: 5555 TCP: 8000
24. copy a file:
You can copy files to or from a device,
Copy a file or directory to the device or simulator:
ADB push <source> <destination> </source>
Example: ADB push test.txt/tmp/test.txt
Copy a file or directory from a device or simulator:
ADB pull <source> <destination> </source>
For example, ADB pull/addroid/lib/libwebcore. So.
25. Search for simulator/device instances:
Obtain the list of running Simulators/devices and the status of each instance:
ADB Devices
26. view the bug report:
ADB bugreport
27. Record wireless communication logs:
In general, there are a lot of wireless communication logs and there is no need to record them during operation, but we can still set the record through the command:
ADB Shell
Logcat-B radio
28. Obtain the device ID and serial number:
ADB get-Product
ADB get-serialno
29. Access the database sqlite3
ADB Shell
Sqlite3

# Cd system/SD/Data // enter the specified folder in the system
# Ls // the contents of the current folder are displayed in the list
# Rm-r XXX // delete a folder named XXX and all its files
# Rm XXX // delete file xxx
# Rmdir XXX // Delete the xxx folder

# Non-blocking logcat
The-D parameter can be used to return results after reading all logs without waiting for them. It is useful in automation. For example:
ADB logcat-d-s XXX> XXX. Log // obtain the log whose filter is XXX, store it in XXX. log, and return.
# Use grep to filter logs
Windows does not matter. grep has a Windows version. In fact, after cygwin is installed, it carries grep.
ADB logcat | grep XXX // filter logs with xxx characters
# Execute commands in the ADB shell locally
We often need ADB shell to execute some commands on the device. In fact, you can directly execute commands on the device and output the commands to the local device without entering the shell. For example:
ADB shell "am start-N com. AAA. BBB/COM. AAA. BBB. Activity" // start a program
# Use top to view CPU usage
You can use top in the ADB shell to view CPU and memory usage. The-M parameter can only display the first few items, and the-n parameter can only be refreshed several times, and then return, it is no longer blocked and useful in automation. For example:
ADB shell "Top-N 1" | grep COM. AAA. bbb // if you do not enter the shell, execute the TOP command locally only once and filter out com. AAA. the row of BBB. Through the output, you can get the CPU usage of the program, or determine whether the program has exited.
# Use ADB devices to check whether a connected device exists
ADB devices can be used to list all connected devices with online/offline signs. Based on the analysis output, you can determine whether devices are available and which devices are available.
# Batch upload/download files to devices
ADB push and ADB pull can only upload one file at a time. The for command can be used for batch processing:
ADB shell "mkdir/sdcard/YUV" // create/sdcard/YUV directory on the device
For % I in (*. YUV) Do ADB push % I/sdcard/YUV // upload all files with the YUV extension in the current directory to the/sdcard/YUV/directory.

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.