3

For hardware reasons (My menu key doesn't work) I can not add an APN via settings. I read here about using sqlite and here about using code. But I need a more convenient way to do it. I need to do it using adb.

0

2 Answers 2

10

You Should

  • 1. Be Root
  • 2. Know APN fileds such as MCC and MNC of your service provider [e.g EthioTelecom is mcc=636 mnc=01]

Steps

  • Open adb shell
    $ adb shell
    $ su
  1. Check if your carrier is listed in the default list of carriers. [] means optional
# content query --uri content://telephony/carriers [--where "name=''"]
  1. If your carrier is not listed, you have to add it to the list, Add other fields as required. NOTE the following is for Internet, for MMS, change the fileds to what is required
    # content insert --uri content://telephony/carriers --bind name:s:"<Carrier Name>" --bind numeric:s:"<mcc><mnc>" --bind type:s:"default,sulp" --bind mcc:i:<mcc> --bind mnc:s:<mnc>--bind apn:s:<apn>  --bind user:s:"<User> --bind password:s:"<Password>"
  1. Then check the listing again like Step 1

  2. Note the _id, replace insert by update if this is not the first time you are setting the prefered apn

# content insert --uri content://telephony/carriers/preferapn --bind apn_id:i:<_id>
  1. Try disabling and enabling your internet connection, if no change, restart your phone. if it is still not working, Keep Going

  2. Change permission of settings file

# chmod 666 /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml
# exit
$ exit
  1. After you exit adb shell, in your terminal/comand prompt
$ adb pull /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml ~/
  1. Add The following line before the last line that says </map>

    <long name="apn_id" value="<id>"/>

  2. then save it and run

$ adb push ~/com.android.settings_preferences.xml /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml

Hopefully, You should now see your apn in the access points screen in settings, and it should also work.

7
  • Thanks for this. After doining steps 1-4 I can see the APN and it is selected. However, when I reboot, the two records I created are no longer there. Jan 26, 2018 at 15:26
  • @user2233706 It's been a while, but one issue I had was wrong mnc and mcc values. Make sure you refer to your provider's numbers. Jan 27, 2018 at 3:34
  • I have a phone where the same records persist on reboot, but another phone where it does not. The phones are supposed to be the same. Jan 27, 2018 at 15:21
  • @user2233706 I'm sorry, I couldn't help buddy! Jan 28, 2018 at 11:31
  • 1
    The file /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml does not exist in modern versions of android. Any idea where to apply the change listed in step 8 these days?
    – Fopedush
    Nov 14, 2018 at 1:52
1

On a terminal (e.g. CMD prompt on Windows), type the following lines:

  1. adb shell
    su
    content query --uri content://telephony/carriers --where "name='mtnirancell'"
    
  2. content insert --uri content://telephony/carriers --bind name:s:"name" --bind numeric:s:"<mcc><mnc>" --bind type:s:"default,sulp" --bind mcc:i:<mcc> --bind mnc:s:<mnc> --bind apn:s:<name>"
    
    • Sample:
      content insert --uri content://telephony/carriers --bind name:s:"mtnirancell" --bind numeric:s:"43211" --bind type:s:"default,sulp" --bind mcc:i:432 --bind mnc:s:11 --bind apn:s:mtnirancell"
      
  3. content insert --uri content://telephony/carriers/preferapn --bind apn_id:i:<_id>
    
    • Sample:
      content insert --uri content://telephony/carriers/preferapn --bind apn_id:i:1500
      
  4. chmod 666 /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml
    exit   # for exit su
    exit   # for exit shell
    
  5. adb pull /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml ~\com.android.settings_preferences.xml
    
  6. Add the following line before the last line that says </map>, then save the file

    <long name="apn_id" value="1500"/>
    
  7. adb push ~\com.android.settings_preferences.xml /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml
    
1
  • Hi! Thank you for your answer, it would be wonderful if you mention which version of Android you tested with. May 12, 2020 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .