telephonymanager - Android signal strength -


is there method signal strength on both sim cards. search lot couldn't find solution. maybe there method register receiver on second sim card ? i'm working on android 5.0 , know on version android officially not support dual sim solutions. found fits me: check whether phone dual sim android dual sim signal strength

second link presents way cannot use because method telephonymanager.listengemini not available

any ?

please note: following specific android 5.0 devices. uses hidden interface in android 5.0, , not work in earlier and later versions. in particular, subscription id changed long int when api exposed in api 22 (for should use official api anyway).

for android 5.0 on htc m8, may try following signal strength of both sim cards:

overriding phonestatelistener , protected internal variable long msubid. since protected variable hidden need use reflection.

public class multisimlistener extends phonestatelistener {      private field subidfield;     private long subid = -1;      public multisimlistener (long subid) {         super();                     try {             // protected field msubid of phonestatelistener , set              subidfield = this.getclass().getsuperclass().getdeclaredfield("msubid");             subscriptionfield.setaccessible(true);             subscriptionfield.set(this, subid);             this.subid = subid;          } catch (nosuchfieldexception e) {          } catch (illegalaccessexception e) {          } catch (illegalargumentexception e) {          }     }      @override     public void onsignalstrengthschanged(signalstrength signalstrength) {         // handle event here, subid indicates subscription id if > 0     }  } 

you need list of active subscription ids subscriptionmanager instantiating class. again subscriptionmanager hidden in 5.0.

final class<?> tmclasssm = class.forname("android.telephony.subscriptionmanager"); // static method return list of active subids method methodgetsubidlist = tmclasssm.getdeclaredmethod("getactivesubidlist"); long[] subidlist = (long[])methodgetsubidlist.invoke(null); 

then can iterate through subidlist create instances of multisimlistener. e.g.

multisimlistener listener[subidlist[i]] = new multisimlistener(subidlist[i]); 

you can call telephonymanager.listen usual, each of listeners.

you need add error , android version / device check code, works on specific devices / version.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -