ReadAsset.JAVA
SEE:
try {
InputStream is = getAssets().open("read_asset.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String text = new String(buffer);
} catch (IOException e) {
// Should never happen!
throw new RuntimeException(e);
}
SO:
仿照着写吧

ResourcesSample.java

SEE:
<string name="styled_text">Plain, <b>bold</b>, <i>italic</i>, <b><i>bold-italic</i></b></string>
1.
CharSequence cs;
tv.setText(cs);
2.
String str;
tv.setText(str);
3.
Resources res = context.getResources();
cs = res.getText(R.string.styled_text);
SO:
1.
设置TextView带格式
2.
string设置 不带格式
3.
在某些地方可以这么获得字符串

StyledText.java

写在layout里的也可以显示格式


ExternalStorage.java


SEE:
1.
ViewGroup mLayout;
mLayout = (ViewGroup)findViewById(R.id.layout);
2.
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
Item item = new Item();
item.mRoot = inflater.inflate(R.layout.external_storage_item, null);
TextView tv = (TextView)item.mRoot.findViewById(R.id.label);
tv.setText(label);
if (path != null) {
tv = (TextView)item.mRoot.findViewById(R.id.path);
tv.setText(path.toString());
}
item.mCreate = (Button)item.mRoot.findViewById(R.id.create);
item.mCreate.setOnClickListener(createClick);
item.mDelete = (Button)item.mRoot.findViewById(R.id.delete);
item.mDelete.setOnClickListener(deleteClick);
return item;
3.
mLayout.addView(mExternalStoragePublicPicture.mRoot);
SO:
1.各种layout通用的ViewGroup,如果只是往里面加东西的话
2.创建布局的过程。View.findViewById()
3.添加view


SEE:
1.
void startWatchingExternalStorage() {
mExternalStorageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("test", "Storage: " + intent.getData());
updateExternalStorageState();
}
};
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
registerReceiver(mExternalStorageReceiver, filter);
updateExternalStorageState();
}
2.
void stopWatchingExternalStorage() {
unregisterReceiver(mExternalStorageReceiver);
}


SO:
1.broadcastReceiver注册
2.取消注册
3.

SEE:
1.
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
} else {
mExternalStorageAvailable = mExternalStorageWriteable = false;
}
handleExternalStorageState(mExternalStorageAvailable,
mExternalStorageWriteable);
2.
void handleExternalStorageState(boolean available, boolean writeable) {
boolean has = hasExternalStoragePublicPicture();
mExternalStoragePublicPicture.mCreate.setEnabled(writeable && !has);
mExternalStoragePublicPicture.mDelete.setEnabled(writeable && has);
has = hasExternalStoragePrivatePicture();
mExternalStoragePrivatePicture.mCreate.setEnabled(writeable && !has);
mExternalStoragePrivatePicture.mDelete.setEnabled(writeable && has);
has = hasExternalStoragePrivateFile();
mExternalStoragePrivateFile.mCreate.setEnabled(writeable && !has);
mExternalStoragePrivateFile.mDelete.setEnabled(writeable && has);
}


SO:
1.存取状态获取
2.更新组件状态。

SEE:
1.
boolean hasExternalStoragePublicPicture() {
// Create a path where we will place our picture in the user's
// public pictures directory and check if the file exists. If
// external storage is not currently mounted this will think the
// picture doesn't exist.
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
return file.exists();
}
2.
boolean hasExternalStoragePrivatePicture() {
// Create a path where we will place our picture in the user's
// public pictures directory and check if the file exists. If
// external storage is not currently mounted this will think the
// picture doesn't exist.
File path = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
if (path != null) {
File file = new File(path, "DemoPicture.jpg");
return file.exists();
}
return false;
}
3.
boolean hasExternalStoragePrivateFile() {
// Get path for the file on external storage. If external
// storage is not currently mounted this will fail.
File file = new File(getExternalFilesDir(null), "DemoFile.jpg");
if (file != null) {
return file.exists();
}
return false;
}

SO:
1.公共的图片文件夹 Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) sdcard/picture
2.程序私有的文件夹目录下的图片文件夹 getExternalFilesDir(Environment.DIRECTORY_PICTURES) sdcard/android/data/pacagename/file/picture
3.程序私有的文件夹 getExternalFilesDir(null) sdcard/android/data/pacagename/file
4.都靠 file.exists()。。。

SEE:
1.
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
path.mkdirs();
2.
InputStream is = getResources().openRawResource(R.drawable.balloons);
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
3.
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
4.
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
file.delete();
5.
File file = new File(getExternalFilesDir(null), "DemoFile.jpg");
if (file != null) {
file.delete();
}
SO:
1.
获得路径,并创建。
2.
图片资源读取
文件的读写。
3.
通知多媒体扫描收集器。
4.
文件删除工作。
5.
文件夹删除。


=====================================content END




















更多相关文章

  1. android,实现圆形循环进度条,不带百分比进度显示
  2. Android(安卓)Studio使用.so库的方式(科大飞讯为例)
  3. android 杂项-备忘
  4. android中获取网络图片并显示以及去掉标题
  5. 如何搭建android环境---windows系统环境里。
  6. android客户端从服务器端获取json数据并解析
  7. Drawable、Bitmap、byte[]之间的转换 Bitmap转换成InputStream。
  8. ReactNative项目打包(Android(安卓)&& IOS)
  9. Android(安卓)DOM 解析 xml

随机推荐

  1. Android动态加载入门 简单加载模式
  2. 深入浅出 - Android系统移植与平台开发(七
  3. android android屏幕禁止休眠和锁屏的方
  4. android中的recovery模式
  5. Android Drawable Resource学习(一)、Drawa
  6. Application Fundamentals
  7. Android共享动画兼容实现
  8. android自制的软件如何添加到打开方式
  9. android关机充电流程及关机充电时的画面
  10. android布局---android:layout_weight