Professional Documents
Culture Documents
DATE:
AIM:
To Implement an application that writes data to the SD card.
ALGORITHM:
1)Open eclipse or android studio and select new android project
2)Give project name and select next
3) Choose the android version.Choose the lowest android version(Android 2.2) and select next
4) Enter the package name.package name must be two word separated by comma and click finish
5)Go to package explorer in the left hand side.select our project.
6)Go to res folder and select layout.Double click the main.xml file. Add the code below
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
android:id=”@+id/widget28”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#ff0000ff”
android:orientation=”vertical”
xmlns:android=”http://schemas.android.com/apk/res/android”
>
<EditText
android:id=”@+id/txtData”
android:layout_width=”fill_parent”
android:layout_height=”180px”
android:textSize=”18sp” />
<Button
android:id=”@+id/btnWriteSDFile”
android:layout_width=”143px”
android:layout_height=”44px”
android:text=”1. Write SD File” />
<Button
android:id=”@+id/btnClearScreen”
android:layout_width=”141px”
android:layout_height=”42px”
android:text=”2. Clear Screen” />
<Button
android:id=”@+id/btnReadSDFile”
android:layout_width=”140px”
android:layout_height=”42px”
android:text=”3. Read SD File” />
<Button
android:id=”@+id/btnClose”
android:layout_width=”141px”
android:layout_height=”43px”
android:text=”4. Close” />
</LinearLayout>
7) Now select FileDemo2.java file and type the following code.
Package com.javasamples;
import java.io.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// bind GUI elements with local controls
txtData = (EditText) findViewById(R.id.txtData);
txtData.setHint(“Enter some lines of data here…”);
}// onCreate
}// AndSDcard
8)Next step is to set permission to write data in sd card.So go to AndroidManifest.xml file. Copy and
paste the following coding.The code should come before <application> tab.
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
9)Now go to main.xml and right click .select run as option and select run configuration
10) Android output is present in the android emulator as shown in below.
OUTPUT
RESULT:
Thus the application that writes data to the SD card was executed successfully.