Start from API Level 8 (Android 2.2),
android.os.Environment class provide
getExternalStoragePublicDirectory(String type) method, to get a top-level public external storage directory for placing files of a particular type. This is where the user will typically place and manage their own files, so you should be careful about what you put here to ensure you don't erase their files or get in the way of their own organization.
package com.AndroidExternalStoragePublicDirectory;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
public class AndroidExternalStoragePublicDirectory extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textDIRECTORY_MUSIC = (TextView)findViewById(R.id.textDIRECTORY_MUSIC);
TextView textDIRECTORY_PODCASTS = (TextView)findViewById(R.id.textDIRECTORY_PODCASTS);
TextView textDIRECTORY_RINGTONES = (TextView)findViewById(R.id.textDIRECTORY_RINGTONES);
TextView textDIRECTORY_ALARMS = (TextView)findViewById(R.id.textDIRECTORY_ALARMS);
TextView textDIRECTORY_NOTIFICATIONS = (TextView)findViewById(R.id.textDIRECTORY_NOTIFICATIONS);
TextView textDIRECTORY_PICTURES = (TextView)findViewById(R.id.textDIRECTORY_PICTURES);
TextView textDIRECTORY_MOVIES = (TextView)findViewById(R.id.textDIRECTORY_MOVIES);
TextView textDIRECTORY_DOWNLOADS = (TextView)findViewById(R.id.textDIRECTORY_DOWNLOADS);
TextView textDIRECTORY_DCIM = (TextView)findViewById(R.id.textDIRECTORY_DCIM);
textDIRECTORY_MUSIC.setText(
"DIRECTORY_MUSIC: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
.getPath());
textDIRECTORY_PODCASTS.setText(
"DIRECTORY_PODCASTS: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
.getPath());
textDIRECTORY_RINGTONES.setText(
"DIRECTORY_RINGTONES: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
.getPath());
textDIRECTORY_ALARMS.setText(
"DIRECTORY_ALARMS: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS)
.getPath());
textDIRECTORY_NOTIFICATIONS.setText(
"DIRECTORY_NOTIFICATIONS: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS)
.getPath());
textDIRECTORY_PICTURES.setText(
"DIRECTORY_PICTURES: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
.getPath());
textDIRECTORY_MOVIES.setText(
"DIRECTORY_MOVIES: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
.getPath());
textDIRECTORY_DOWNLOADS.setText(
"DIRECTORY_DOWNLOADS: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.getPath());
textDIRECTORY_DCIM.setText(
"DIRECTORY_DCIM: " +
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
.getPath());
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/textDIRECTORY_MUSIC"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_PODCASTS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_RINGTONES"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_ALARMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_NOTIFICATIONS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_PICTURES"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_MOVIES"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_DOWNLOADS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textDIRECTORY_DCIM"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
No comments:
Post a Comment