列出 Intent 的所有附加项 [英] Listing all extras of an Intent

查看:23
本文介绍了列出 Intent 的所有附加项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于调试的原因,我想列出一个 Intent 的所有附加项(及其值).现在,拿到钥匙不是问题

For debugging reasons I want to list all extras (and their values) of an Intent. Now, getting the keys isn't a problem

Set<String> keys = intent.getExtras().keySet();

但是获取键的值对我来说是一个,因为有些值是字符串,有些是布尔值......我怎么能在循环中获取值(遍历键)并将值写入日志文件?感谢您的任何提示!

but getting the values of the keys is one for me, because some values are strings, some are boolean... How could I get the values in a loop (looping through the keys) and write the values to a logfile? Thanks for any hint!

推荐答案

以下是我用来获取有关未记录(第 3 方)意图的信息的方法:

Here's what I used to get information on an undocumented (3rd-party) intent:

Bundle bundle = intent.getExtras();
if (bundle != null) {
    for (String key : bundle.keySet()) {
        Log.e(TAG, key + " : " + (bundle.get(key) != null ? bundle.get(key) : "NULL"));
    }
}

确保在循环之前检查 bundle 是否为空.

Make sure to check if bundle is null before the loop.

这篇关于列出 Intent 的所有附加项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆