我读了很多文章并尝试了许多解决方案,但是所有文章的共同点是它们都已过时,至少我找不到能在较新版本的Android上运行的解决方案。
发布1,结果:
intent.getExtras().getInt("simId", -1)
总是返回-1
发布2,结果:intent.getExtras().getInt("slot", -1)
总是返回-1
发表3,结果:
String[] array = new String[]{
"extra_asus_dial_use_dualsim",
"com.android.phone.extra.slot",
"slot",
"simslot",
"sim_slot",
"subscription",
"Subscription",
"phone",
"com.android.phone.DialingMode",
"simSlot",
"slot_id",
"simId",
"simnum",
"phone_type",
"slotId",
"slotIdx"
};
for (String item :
array) {
Log.i(TAG, "Sim Card - " + item + " -----> " + intent.getExtras().getInt(item));
}
日志:
PhoneCallReceiver: Sim Card - extra_asus_dial_use_dualsim -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.extra.slot -----> 0
PhoneCallReceiver: Sim Card - slot -----> 0
PhoneCallReceiver: Sim Card - simslot -----> 0
PhoneCallReceiver: Sim Card - sim_slot -----> 0
PhoneCallReceiver: Sim Card - subscription -----> 0
PhoneCallReceiver: Sim Card - Subscription -----> 0
PhoneCallReceiver: Sim Card - phone -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.DialingMode -----> 0
PhoneCallReceiver: Sim Card - simSlot -----> 0
PhoneCallReceiver: Sim Card - slot_id -----> 0
PhoneCallReceiver: Sim Card - simId -----> 0
PhoneCallReceiver: Sim Card - simnum -----> 0
PhoneCallReceiver: Sim Card - phone_type -----> 0
PhoneCallReceiver: Sim Card - slotId -----> 0
PhoneCallReceiver: Sim Card - slotIdx -----> 0
对于第一个SimCard和第二个SimCard,将显示相同的日志,且其值均为0。
我也尝试过其他类似的帖子。没有适用于新版本的android!
在较新版本的Android(7.0或更高版本)上,还有其他解决方案吗?
此外,你有没有试过打印所有的意图演员确实包含,看是否有在命名相比,你承担什么区别?
—
迈克尔
无论是带有“ item”还是带有item,它总是返回0。
—
Alireza Noorali
好吧,
—
迈克尔
"item"
在这种情况下几乎可以肯定是不正确的。就像我说的,尝试打印您所拥有的而不是期望的。尽管整个解决方案看起来有些破烂,但是您发现的任何可用密钥在某些设备上可能仍然无法使用。
intent.getExtras().getInt("item")
<-您不是要使用item
而不是"item"
吗?