`

Android一些知识点

阅读更多
1、缓存用户的设置,记住用户的选择
 
	/**
	  * 方法:将用户的相册皮肤SD卡里存在的路径存入Preferences
	  */
   public void saveSkinPath(String path){
   	SharedPreferences ssp = getPreferences(MODE_WORLD_WRITEABLE);
	//获得Preferences
   	SharedPreferences.Editor editor = ssp.edit();			//获得Editor
   	editor.putString("skinPath", path);							//将改动后的皮肤存入Preferences
   	changePath = path;
   	System.out.println("saveSkinPath()---> " + changePath);
   	editor.commit();
   }
 
 
    /**
    * 方法:从Preferences中读取用户设置的相册皮肤路径
    * 只针对此Activity设置背景图片
    */
   public String getSkinPath(){
	   SharedPreferences ssp = getPreferences(MODE_WORLD_WRITEABLE);	//获得Preferences
	   String path = ssp.getString("skinPath", null);
	   if(path != null){
		  changePath = path;
		  return path;
	   }
	   return QuickAccessActivity.getPath();
   }

2、调用系统照相机设置
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
this.startActivityForResult(intent, 111111);

if(resultCode == 111111){
if(data!=null) { 					             Intent takePictureIntent = new Intent(this,PhotoHandle.class);
Bitmap bmp = (Bitmap)(data.getExtras().get("data")); 
byte[] dataBytes = BitmapUtils.getBytes(bmp); 
takePictureIntent.putExtra("data", dataBytes);	//将图片数据设置为Extra
startActivity(takePictureIntent);		//启动保存图片Activity
					}

3、将字节数组转化为图片格式并保存指定路径下
Bitmap bmp = BitmapFactory.decodeByteArray(photoData,0,photoData.length);
File f = new File(Config_constant.CAPTURE_PATH + "/" + albumsList.get(position) + "//" + photoName + ".jpg");
try {
	BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
	bmp.compress(Bitmap.CompressFormat.JPEG, 80, bos);
	bos.flush();
} catch (FileNotFoundException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}


4、简单的行式布局ListView的用法
<?xml version="1.0" encoding="utf-8"?>
<!-- 列表展示布局文件 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
			android:layout_width="fill_parent" 
			android:layout_height="fill_parent"
        	android:orientation="vertical"
        	android:id="@+id/listPath">

        <ListView
    	    android:id="@+id/android:list" 
        	android:layout_width="fill_parent"
        	android:layout_height="wrap_content"
        	android:drawSelectorOnTop="false"
        	android:scrollbars="vertical"
        	android:divider="@color/listDivider"
			android:dividerHeight="5dp"
        	/>
</LinearLayout>

下面的是具体的代码
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listName); // listName是一个字符串数组
this.setListAdapter(listAdapter);

5、将图片转换为字节数组
        /**
	 * 将图片转换为字节数组
	 * @param bmp	图片
	 * @return	字节数组
	 */
	public static byte[] getBytes(Bitmap bmp){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);  
		byte[] dataBytes = baos.toByteArray(); 
		return dataBytes;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics