Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Allow end-users to override yielded number logic - #156

Open
hhff wants to merge 3 commits into
klinker41:masterfrom
sanctuarycomputer:feature/allow-yielded-own-number
Open

Allow end-users to override yielded number logic#156
hhff wants to merge 3 commits into
klinker41:masterfrom
sanctuarycomputer:feature/allow-yielded-own-number

Conversation

@hhff

@hhff hhff commented Jun 2, 2019

Copy link
Copy Markdown

In order to override how the lib finds the device's phone number, this PR allows end users to do this:

com.klinker.android.send_message.Utils.setOwnNumberOverride(new com.klinker.android.send_message.OwnNumber() {
   @Override
   public String onYield(Context context) {
       return myCustomResolveNumberLogic();
   }
});

Method method = telephonyManager.getClass().getMethod("getLine1NumberForSubscriber", int.class);
return (String) method.invoke(telephonyManager, subId);
String number = (String) method.invoke(telephonyManager, subId);
return number;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only part I was a little sketchy on. In this implementation, the lib will still call getLine1NumberForSubscriber rather than Utils.getMyPhoneNumber

How do you think we should handle this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for dual SIM devices, and we don't want to lose this functionality. I would probably make some kind of condition here

  1. If the user has more than one SIM card, then use this original reflection. You can find how many sim cards the user has, by querying this method and getting the length of the array: https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoList()
  2. If the user has not provided a custom override, then use this original reflection.

So, only use the new Utils.getMyPhoneNumber(context) if the user has one SIM card and the implementing app has actually provided an override.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Luke! will look to find some time this weekend to finish it off 🙂

@kangnaclub9

Copy link
Copy Markdown

coply

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants