Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow end-users to override yielded number logic #156

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hhff
Copy link

@hhff hhff commented Jun 2, 2019

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();
   }
});

} else {
try {
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
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
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
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

coply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants