How to Restore/Change Android ID in Android 6.0 Marshmallow

Search This thread

piit79

Senior Member
Nov 7, 2011
327
320
Prague
I haven't found this posted anywhere so figured it might be useful to others as well.

When you reinstall Android it is set up as a new device with a new unique Android ID. This ID is often used by apps to identify the device - for example all my internet banking apps use it to register the device with the service. To avoid having to re-register after reinstall the ID can be changed to what it was previously.

The Android ID backup/restore function is included in Titanium Backup. However, the Settings Storage (com.android.providers.settings) doesn't seem to be backed by a traditional SQLite database in Android 6.0 Marshmallow - /data/data/com.android.providers.settings/databases/settings.db is empty (0 bytes) on my device. Therefore the Android ID cannot be restored/changed by the usual tools (including Titanium Backup).

I have found a way to query/update the settings database via adb though as follows:
Get current Android ID:
Code:
adb shell content query --uri content://settings/secure --where "name=\'android_id\'"
Normally, you would update the value as follows:
Code:
adb shell content update --uri content://settings/secure --bind value:s:<new_android_id> --where "name=\'android_id\'"
However, this wasn't working for me - I kept getting the same ID when querying after update. So, I tried removing the current record and re-inserting it with the new ID:
Code:
adb shell content delete --uri content://settings/secure --where "name=\'android_id\'"
adb shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:<new_android_id>
Which worked just fine :)
 

Alarbus

Senior Member
Aug 27, 2010
69
29
Vermont
Any idea if this works going from CM to Stock or the reverse? Or does it only work stock to stock?

I ask because my two factor auth token for work is on my CM, but if I restore it on stock using Titanium Backup, it works oddly. I wonder if changing the ID would make it work better on stock
 

mavaddat

Member
Dec 20, 2014
15
4
Vancouver
For Windows, exclude escape characters

Simply perfect. I was worried when Titanium Backup couldn't restore old ID, but this worked like a beauty.
The only hitch was that the cmd.exe doesn't need escape characters for apostrophes.
So the code for me was just
Code:
adb shell content delete --uri content://settings/secure --where "name='android_id'"
adb.exe shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:<newID>
 
Last edited:

nyreyn

Senior Member
May 22, 2010
146
23
edit: installing adbwireless and using that solved the problem. not sure why adb from my computer won't work though.

I have the latest SDK installed, have root, and have allowd adb shell root privileges and everytime i run a command I get:

tmp-mksh: adb: not found

Can anyone help me out? I'm using a Nexus 6.

edit: seems like no matter what command i type i get adb : not found. I get a response from the command adb devices when I don't have a shell open. running the abobe commands outside of a shell returns an error, and when i go into a shell no commands work. I always get the adb: not found response.
 
Last edited:

mavaddat

Member
Dec 20, 2014
15
4
Vancouver
edit: installing adbwireless and using that solved the problem. not sure why adb from my computer won't work though.

I have the latest SDK installed, have root, and have allowd adb shell root privileges and everytime i run a command I get:

tmp-mksh: adb: not found

Can anyone help me out? I'm using a Nexus 6.

edit: seems like no matter what command i type i get adb : not found. I get a response from the command adb devices when I don't have a shell open. running the abobe :confused: :eek: commands outside of a shell returns an error, and when i go into a shell no commands work. I always get the adb: not found response.

Of course! This is a simple problem arising from the absence of the adb.exe executable from the system path being read by your shell or terminal program. You can either add your adb.exe to your system path or else navigate to the platform-tools directory and use the adb.exe from there:
  1. Verify that adb.exe resides in %LOCALAPPDATA%\Android\sdk\platform-tools\
  2. Set the path and restart the cmd or PowerShell and then try again.
 

Asitaka

Senior Member
Aug 5, 2012
313
30
I tried doing this, but my adb shell doesn't seem to have content in its sbin.
Nevermind.. it works now.
 
Last edited:

destbr

Member
Jul 10, 2012
5
2
I haven't found this posted anywhere so figured it might be useful to others as well.

When you reinstall Android it is set up as a new device with a new unique Android ID. This ID is often used by apps to identify the device - for example all my internet banking apps use it to register the device with the service. To avoid having to re-register after reinstall the ID can be changed to what it was previously.

The Android ID backup/restore function is included in Titanium Backup. However, the Settings Storage (com.android.providers.settings) doesn't seem to be backed by a traditional SQLite database in Android 6.0 Marshmallow - /data/data/com.android.providers.settings/databases/settings.db is empty (0 bytes) on my device. Therefore the Android ID cannot be restored/changed by the usual tools (including Titanium Backup).

I have found a way to query/update the settings database via adb though as follows:
Get current Android ID:
Code:
adb shell content query --uri content://settings/secure --where "name=\'android_id\'"
Normally, you would update the value as follows:
Code:
adb shell content update --uri content://settings/secure --bind value:s:<new_android_id> --where "name=\'android_id\'"
However, this wasn't working for me - I kept getting the same ID when querying after update. So, I tried removing the current record and re-inserting it with the new ID:
Code:
adb shell content delete --uri content://settings/secure --where "name=\'android_id\'"
adb shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:<new_android_id>
Which worked just fine :)

Thanks! Thanks! Thanks! Thanks! Thanks! Thanks! Thanks!
 

merouleau

Member
Aug 27, 2013
42
14
I'm already on Marshmallow, so I'm guessing that the "settings get secure android_id" will just tell me my current, new, unwanted android_id. Correct, or am I confused? Is there an easy way to find out what my previous android_id was so that I know what to restore it to? Perhaps Titanium Backup has it squirreled away somewhere?

Or do I need to follow this process?

1. Make nandroid of current Marshmallow setup.
2. Restore nandroid of prior Lollipop setup.
3. From terminal window, "settings get secure android_id" and write down the ID (e.g. "abcdef0123456789")
4. Restore Marshmallow nandroid
5. From terminal window, "settings put secure android_id abcdef0123456789"
 

mattyb65

Member
Oct 29, 2010
44
16
Franklin, Ma
There has to be a way to change the device ID for GMail but I haven't figure it out yet. There was an module on Xposed that claimed it could do it but I'm on 6.0 so that doesn't do me any good. Any one have ideas?
 

MSKS

Member
Oct 23, 2013
5
1
Athens
Hi!

I am trying adb shell settings but I get:
"/system/bin/sh: /system/bin/settings: /bin/sh: No such file or directory"
In other words the settings command is not found.

Am I missing something?

Thanks for the help!

Hi,

another way is :


to read Android ID:
Code:
adb shell settings get secure android_id
To write Android ID:
Code:
adb shell settings put secure android_id <new_android_id>

Tested on Android 6.0 Marshmallow.
 

piit79

Senior Member
Nov 7, 2011
327
320
Prague
Hi!

I am trying adb shell settings but I get:
"/system/bin/sh: /system/bin/settings: /bin/sh: No such file or directory"
In other words the settings command is not found.

Am I missing something?

Thanks for the help!

Seems I'm not watching my own thread! Duh :) Lots of useful info here.

I was getting the same error message. The /system/bin/settings script is there but it's missing the "shebang" line at the beginning to specify what interpreter to use (e.g. #!/bin/bash). For some reason the system defaults to /bin/sh - which is not there.

You can get around it by running the scripts like so:
Code:
sh /system/bin/settings ...

Hope that helps.
 

MSKS

Member
Oct 23, 2013
5
1
Athens
Thanks a lot man! Appreciated.

Seems I'm not watching my own thread! Duh :) Lots of useful info here.

I was getting the same error message. The /system/bin/settings script is there but it's missing the "shebang" line at the beginning to specify what interpreter to use (e.g. #!/bin/bash). For some reason the system defaults to /bin/sh - which is not there.

You can get around it by running the scripts like so:
Code:
sh /system/bin/settings ...

Hope that helps.
 

thedodus

Senior Member
Mar 5, 2011
81
13
I'm already on Marshmallow, so I'm guessing that the "settings get secure android_id" will just tell me my current, new, unwanted android_id. Correct, or am I confused? Is there an easy way to find out what my previous android_id was so that I know what to restore it to? Perhaps Titanium Backup has it squirreled away somewhere?

Or do I need to follow this process?

1. Make nandroid of current Marshmallow setup.
2. Restore nandroid of prior Lollipop setup.
3. From terminal window, "settings get secure android_id" and write down the ID (e.g. "abcdef0123456789")
4. Restore Marshmallow nandroid
5. From terminal window, "settings put secure android_id abcdef0123456789"

Did you try this and did it turn out? I'm about to do the same thing because it makes sense.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 44
    I haven't found this posted anywhere so figured it might be useful to others as well.

    When you reinstall Android it is set up as a new device with a new unique Android ID. This ID is often used by apps to identify the device - for example all my internet banking apps use it to register the device with the service. To avoid having to re-register after reinstall the ID can be changed to what it was previously.

    The Android ID backup/restore function is included in Titanium Backup. However, the Settings Storage (com.android.providers.settings) doesn't seem to be backed by a traditional SQLite database in Android 6.0 Marshmallow - /data/data/com.android.providers.settings/databases/settings.db is empty (0 bytes) on my device. Therefore the Android ID cannot be restored/changed by the usual tools (including Titanium Backup).

    I have found a way to query/update the settings database via adb though as follows:
    Get current Android ID:
    Code:
    adb shell content query --uri content://settings/secure --where "name=\'android_id\'"
    Normally, you would update the value as follows:
    Code:
    adb shell content update --uri content://settings/secure --bind value:s:<new_android_id> --where "name=\'android_id\'"
    However, this wasn't working for me - I kept getting the same ID when querying after update. So, I tried removing the current record and re-inserting it with the new ID:
    Code:
    adb shell content delete --uri content://settings/secure --where "name=\'android_id\'"
    adb shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:<new_android_id>
    Which worked just fine :)
    22
    Hi,

    another way is :


    to read Android ID:
    Code:
    adb shell settings get secure android_id
    To write Android ID:
    Code:
    adb shell settings put secure android_id <new_android_id>

    Tested on Android 6.0 Marshmallow.
    7
    Any way to get this done without pc access?
    Sure. Just open Terminal Emulator as root and use the same commands as above but without "adb shell":
    Code:
    su
    settings get secure android_id
    settings put secure android_id <new_android_id>
    I used it in my Nexus 5 (Marshmallow).
    4
    For Windows, exclude escape characters

    Simply perfect. I was worried when Titanium Backup couldn't restore old ID, but this worked like a beauty.
    The only hitch was that the cmd.exe doesn't need escape characters for apostrophes.
    So the code for me was just
    Code:
    adb shell content delete --uri content://settings/secure --where "name='android_id'"
    adb.exe shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:<newID>
    2
    I haven't found this posted anywhere so figured it might be useful to others as well.

    When you reinstall Android it is set up as a new device with a new unique Android ID. This ID is often used by apps to identify the device - for example all my internet banking apps use it to register the device with the service. To avoid having to re-register after reinstall the ID can be changed to what it was previously.

    The Android ID backup/restore function is included in Titanium Backup. However, the Settings Storage (com.android.providers.settings) doesn't seem to be backed by a traditional SQLite database in Android 6.0 Marshmallow - /data/data/com.android.providers.settings/databases/settings.db is empty (0 bytes) on my device. Therefore the Android ID cannot be restored/changed by the usual tools (including Titanium Backup).

    I have found a way to query/update the settings database via adb though as follows:
    Get current Android ID:
    Code:
    adb shell content query --uri content://settings/secure --where "name=\'android_id\'"
    Normally, you would update the value as follows:
    Code:
    adb shell content update --uri content://settings/secure --bind value:s:<new_android_id> --where "name=\'android_id\'"
    However, this wasn't working for me - I kept getting the same ID when querying after update. So, I tried removing the current record and re-inserting it with the new ID:
    Code:
    adb shell content delete --uri content://settings/secure --where "name=\'android_id\'"
    adb shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:<new_android_id>
    Which worked just fine :)

    Thanks! Thanks! Thanks! Thanks! Thanks! Thanks! Thanks!