{"id":78,"date":"2011-11-01T21:51:15","date_gmt":"2011-11-01T20:51:15","guid":{"rendered":"http:\/\/www.sigterm.ch\/?p=78"},"modified":"2011-11-01T21:51:15","modified_gmt":"2011-11-01T20:51:15","slug":"android-gallery-app-camera-pictures-not-in-correct-order","status":"publish","type":"post","link":"https:\/\/sigterm.ch\/?p=78","title":{"rendered":"Android Gallery app &#8211; Pictures order"},"content":{"rendered":"<p>A few weeks ago I bought a new Android phone, the Samsung Galaxy S2 to be precise. On my old cell I took a lot of pictures and I wanted to transfer them to the new phone. In order to do so, I backed up the camera folder \/mnt\/sdcard\/DCIM\/Camera to my computer and afterwards I copied it to the new phone. So far so good.<br \/>\nHowever, as soon as I looked at the pictures in the Gallery app it occurred to me that they were not chronologically ordered anymore. I found out that the Gallery app is sorting the pictures by the time stamps of the files. During the copy process all the timestamps of the photos have been lost.<!--more--><br \/>\nThe pictures are named as IMG_YYYYMMDD_HHmmSS.jpg and the videos are stored as VID_YYYYMMDD_HHmmSS.m4v. To solve the problem I have written a shell script which is &#8220;touching&#8221; the files depending on the file names to correct the time stamps.<\/p>\n<pre class=\"brush:shell\">#!\/system\/bin\/sh\n#\n# 31.10.2011\n#\n# This script gets all pictures and 'touchs' them so the order of file\n# creation is correct!\n# The Android Gallery App orders the pictures by file creation time!\n#\n#################################################################\nDIR=\"\/mnt\/sdcard\/DCIM\/Camera\"\nAWK=\"busybox awk\"\nSORT=\"busybox sort\"\ntouch_files()\n{\n    if ! ( test -d $1 )\n        then echo $1; return;\n    fi\n    cd $1\n    echo; echo `pwd`: \t\t# Display Directory name\n    FILES=`ls | $AWK '{print substr($0,4,length($0))}' | $SORT`\n    for i in $FILES\n    do\n        echo $i; \t\t# Display File name\n        touch *$i; \t\t# Touch for new date\n        sleep 5; \t\t# Wait...\n    done\n}\ntouch_files $DIR<\/pre>\n<p>You can download the full script <a title=\"reorderImages.sh\" href=\"http:\/\/www.sigterm.ch\/stuff\/reorderImages.sh\">here<\/a>. You need busybox installed to use this script. To install busybox you need to root your phone. Also you can not execute a script from the sdcard, so you have to copy it to an folder where you have executive rights, as \/data\/local\/tmp\/.<\/p>\n<pre class=\"brush:shell\">adb push reorderImages.sh \/data\/local\/tmp\nadb shell chmod 777 \/data\/local\/tmp\/reorderImages.sh\nadb shell\ncd \/data\/local\/tmp\n.\/reorderImages.sh<\/pre>\n<p>After executing the script you may have to reboot the phone. Afterwards your Gallery app should show the pictures in the correct order!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I bought a new Android phone, the Samsung Galaxy S2 to be precise. On my old cell I took a lot of pictures and I wanted to transfer them to the new phone. In order to &hellip; <a href=\"https:\/\/sigterm.ch\/?p=78\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[11,14,33,34,35,49,50,136,141,145,146,147,154],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-android-camera","tag-busybox","tag-camera-pictures","tag-camera-sort-pictures","tag-galaxy-s2","tag-gallery-app","tag-samsung-i9100","tag-shell-script","tag-sort-order","tag-sort-pictures","tag-sort-pictures-by-timestamp","tag-timestamp"],"_links":{"self":[{"href":"https:\/\/sigterm.ch\/index.php?rest_route=\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sigterm.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sigterm.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sigterm.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sigterm.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":0,"href":"https:\/\/sigterm.ch\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"wp:attachment":[{"href":"https:\/\/sigterm.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sigterm.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sigterm.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}