Android初学习 - 遍历Bundle的内容

127 篇文章 0 订阅

使用keySet()方法获取Bundle中的全部key,然后根据key依次遍历Bundle中的value。

代码如下:

public static void showBundleData(Bundle bundle) {
    if (bundle == null) {
        return null;
    }
    String string = "Bundle{";
    for (String key : bundle.keySet()) {
        string += " " + key + " => " + bundle.get(key) + ";";
    }
    string += " }Bundle";
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!针对您的问题,我可以提供以下代码示例: ```java // 获取指定日期的时间戳 String dateString = "2023-05-01"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(dateString); long startTimeStamp = date.getTime(); // 获取当前时间的时间戳 long endTimeStamp = System.currentTimeMillis(); // 构建查询条件 String selection = MediaStore.Images.Media.DATE_TAKEN + " BETWEEN ? AND ?"; String[] selectionArgs = new String[]{ String.valueOf(startTimeStamp), String.valueOf(endTimeStamp) }; // 查询相册中符合条件的图片 Uri queryUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] projection = new String[]{ MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(queryUri, projection, selection, selectionArgs, null); // 将查询结果保存到 BundleBundle bundle = new Bundle(); if (cursor != null) { ArrayList<String> imagePaths = new ArrayList<>(); while (cursor.moveToNext()) { String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); imagePaths.add(imagePath); } bundle.putStringArrayList("image_paths", imagePaths); cursor.close(); } ``` 以上代码中,我们先通过 SimpleDateFormat 将指定日期转换成时间戳,然后获取当前时间的时间戳,构建查询条件,使用 ContentResolver.query() 方法查询相册中符合条件的图片。最后将查询结果保存到 Bundle 中,其中 image_paths 键对应的值为一个字符串列表,包含符合条件的图片路径。 需要注意的是,以上代码仅供参考,具体实现方式可能因为 Android 版本和设备型号的不同而有所差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值