一、接收一个广播,onReceive(Context context, Intent intent),然后想获取intent里面包含的所有key的值。用intent.getStringExtra的方式得知道key的名称,但又不知道key值是多少。bundle.keySet()方法可以返回一个key,就用循环返回所有的key,每个key里面的内容都取出来。
二、实现代码
1、方式一
public void showBundleData(Bundle bundle) {String string = "Bundle{";for (String key : bundle.keySet()) {string += " " + key + "=" + bundle.get(key) + ";";}string += " }Bundle";Log.d("FUCKCCP",string);// Toast.makeText(main_wechat.this,string, Toast.LENGTH_SHORT).show();}
2、方式二
Set<String> keySet = bundle.keySet();for(String key : keySet) {Object value = bundle.get(key);...}
三、测试代码,Bundle bundle = intent.getExtras(); 接收一个广播后解析里面的所有key。
1、接收广播,解析出intent里面的所有key。
2、发送广播
四、参考文章
Android 获取Intent里面所有内容_左手平凡他baba的博客-CSDN博客_android 获取intent
Bundle的遍历方法_lzqcode_51CTO博客