Skip to content

Solved: contacts storage using up too much space on Android

I’ve been slowly falling out of love with my Android HTC Desire over the past few months. It’s been slowing down and frequently running out of space. The contacts storage on the device kept growing and growing – eventually reaching 40Mb – and because it could only be stored on internally and not on the SD card, it was killing everything else.

I tried a number of options – turning off sync on my Exchange account, turning off sync on my Gmail account, removing the Facebook and Twitter apps – none of them made a difference. Contacts storage kept on growing, to the point that I had to keep removing apps that I like just to keep the phone running. Eventually it stopped receiving email and there were no more apps to remove.

I started to wish I’d bought an iPhone – I pretty much only use my phone, contacts, calendar, email, Spotify, Chicmi and Twitter, all of which are available on both platforms.

But then I took some drastic action, and came up with a procedure to fix the issue. Here’s a step by step guide:

Step 1 – Turn off sync

Firstly, turn off sync. Go to Settings > Accounts & Sync and go through each of your accounts, stopping them from syncing with your contacts.

Step 2 – Backup your contacts

The following actions will not delete your contacts from your Gmail or Exchange accounts, but it’s always best to be sure in case something in your settings means that they do get deleted. It’s a small chance, but better safe than sorry.

In Outlook on your computer (I’m using Outlook for Mac), go to File > Export, select only Contacts and export them to a file on disk.

In Gmail on your computer go to Contacts then in the More Actions menu select Export and save all of your contacts to a Google CSV file.

Step 3 – Backup your phone contacts

Just in case you’ve got contacts that are only saved to your phone and not saved in Exchange or Google, go to People in your phone, press Menu, select Import/Export > Export to SD Card, and select to export your Phone contacts. In my case it told me there was nothing to save.

Step 4 – Delete your contacts storage

Now the big step. What we’re going to do is wipe your entire contacts database – settings, contacts, everything. Providing you’re like me and sync all of your contacts with Exchange or Gmail, then this should be no issue – as soon as you resync your contacts will return exactly as they are now. But if you’ve got contacts that you store locally only on your phone, then these will be wiped.

But don’t worry about that too much – you’ve backed all of those up hopefully in step three! So just need to restore them if you can’t find someone.

So go to Settings > Applications > Manage Applications and find Contacts Storage in the All tab. Press Clear Data and confirm that you want to clear. Your contacts storage will go from many MBs to zero.

Step 5 – Turn on sync again

This was the step that made me nervous. When you turn on sync, does it wipe all of your remote contacts, or does it reimport your remote contacts? Thankfully, it just reimports them all. Go to Settings > Accounts & Sync and re-enable sync for all of your mail accounts. It might take a few minutes, but your phone will reimport all of your contacts in the background.

That’s it!

That’s all I had to do. My contacts storage has gone from 40MB to 400KB and my phone is significantly faster and more responsive. And while I’m sure it will start to build back up again over time, at least I know how to fix it again in future. And let’s hope before then HTC or Google fix the issue.

Thankfully I don’t need to join the cult of iPhone quite yet…

Update: This post remains popular over a year after it was published so it’s obvious that lots of people have been having similar issues. I recently upgraded to a Samsung Galaxy S3 and haven’t had any similar issues since, so it seems that the latest versions of Android do make the problem go away. So if you’re consistently having problems still, maybe an upgrade will help!

Advertisements

Simple Tweeting from Perl using Net::Twitter

The following is a simple Perl script that Tweets using the CPAN Net::Twitter API to an OAuth’ed Twitter account:

my $tweet = 'I\'m tweeting from an OAuth PERL app everybody!';

my $twitterconsumer = $yourconsumerkey;
my $twitterconsumersecret = $yourconsumersecret;
my $twitteraccesstoken = $youraccesstoken;
my $twitteraccesstokensecret = $youraccesstokensecret;

my $nt = Net::Twitter->new(
	traits          => ['API::REST', 'OAuth'],
	consumer_key    => $twitterconsumer,
	consumer_secret => $twitterconsumersecret,
);

if ($twitteraccesstoken && $twitteraccesstokensecret) {
	$nt->access_token($twitteraccesstoken);
	$nt->access_token_secret($twitteraccesstokensecret);
}

unless ( $nt->authorized ) {
	print "Authorize this app at ", $nt->get_authorization_url, " and enter the PIN#\n";
	
	my $pin = ; # wait for input
	chomp $pin;
	
	my($access_token, $access_token_secret, $user_id, $screen_name) = $nt->request_access_token(verifier => $pin);
	print 'Access token: '.$access_token."\r\n".'Access Token Secret: '.$access_token_secret."\r\n";

	exit();

}

$nt->update({ status => $tweet });

To get it working you just need to do the following:

  1. Register your app at dev.twitter.com/apps to get your Consumer Key and Consumer Secret. Populate them in the script.
  2. Make sure you have Net::Twitter installed – type cpan at the command prompt and then install Net::Twitter to install it or check for updates.
  3. Run the Perl script once – it will give you a URL to go and ask you for a PIN. Go to the URL and get your PIN, and then enter the PIN and the script will return the Access Token and Access Token Secret. Put those in the script variables.
  4. The script will now Tweet whatever is in the $tweet variable

Solved: Can’t find SSL when installing Crypt::SSLeay

If you’re getting the following error when installing Crypt::SSLeay using Perl’s CPAN:

No installed SSL libraries found in any of the following places.
    /local
    /local/ssl
    /opt/ssl
    /usr
    /usr/local
    /usr/local/ssl
    /usr/local/openssl
You will have to either specify a directory location at the following
prompt, or rerun the Makefile.PL program and use the --lib switch
to specify the path. If the path in question is considered standard
on your platform, please consider filing a bug report in order to
have it taken into account in a subsequent version of Crypt::SSLeay.

Which SSL install path do you want to use?

Then you need to install the SSL development libraries. So on SUSE:

zypper install openssl-devel

And on Ubuntu or Debian:

sudo apt-get install libssl-dev

Once you’ve done that the CPAN installer will automatically work out where your SSL libraries are and will prompt you to confirm that it’s correct – just accept the default and the installation will work.

Simple logging in PHP and Perl

I recently wrote a couple of scripts in PHP and Perl which both needed some basic monitoring, so I opted to log out some simple messages to a text file. These are the two simple log functions:

In PHP:

	function logthis($message) {
		$logfh = fopen('/my/php/logfile.txt', 'a');
		fwrite($logfh, date('Y-m-d H:i:s').' - '.$message."\n");
		fclose($logfh);
	}

In Perl:

	sub log {
		open (LOGFILE, ">>/my/perl/logfile.txt");
		print LOGFILE time2str("%H:%M:%S", time)." @_\r\n";
		close (LOGFILE);
	}

Getting and parsing Twitter search results in PHP

This simple snippet uses PHP’s DOM object to get the Twitter search results for your chosen search term, parse them and then loop through them.

$doc = new DOMDocument();
$doc->load('http://search.twitter.com/search.atom?lang=en&q=%22'.urlencode($yoursearchterm).'%22');

foreach ($doc->getElementsByTagName('entry') as $node) {
	$tweet = trim(strip_tags(html_entity_decode($node->getElementsByTagName('title')->item(0)->nodeValue)));
	$tweetdate = trim(strip_tags(html_entity_decode($node->getElementsByTagName('published')->item(0)->nodeValue)));
	$authornode = $node->getElementsByTagName('author')->item(0);
	$tweetuser = trim(strip_tags(html_entity_decode($nodeauthor->getElementsByTagName('name')->item(0)->nodeValue)));
	$tweetuserurl = trim(strip_tags(html_entity_decode($nodeauthor->getElementsByTagName('uri')->item(0)->nodeValue)));

	// Do something with the tweet here

}

Simple Domain Format Verification Regex

I was looking around for a good regex for simple domain name verification, and I was surprised to see that there wasn’t much out there. There were some complicated ones which do more than I need, but none that just checked that the format was correct. So I created one of my own:

/^((([a-z]|[0-9]|\-)+)\.)+([a-z])+$/i

Now I hate posting regular expressions online, because someone always proudly exclaims that they’ve found an exception, or that they can write it more efficiently, but I’ve run this past thousands of domains and it seems to work pretty consistently – which is all I need. It also rejects IP addresses, which is again what I wanted.

However, if you can make it better, do your worst!

Solved: John the Ripper crypt error during make

If you’re getting this nasty error while running make on John the Ripper:

XSHA_fmt.c:7:25: error: openssl/sha.h: No such file or directory
XSHA_fmt.c:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ctx’
XSHA_fmt.c: In function ‘crypt_all’:
XSHA_fmt.c:147: warning: implicit declaration of function ‘SHA1_Init’
XSHA_fmt.c:147: error: ‘ctx’ undeclared (first use in this function)
XSHA_fmt.c:147: error: (Each undeclared identifier is reported only once
XSHA_fmt.c:147: error: for each function it appears in.)
XSHA_fmt.c:148: warning: implicit declaration of function ‘SHA1_Update’
XSHA_fmt.c:150: warning: implicit declaration of function ‘SHA1_Final’
make[1]: *** [XSHA_fmt.o] Error 1
make[1]: Leaving directory `/home/carl/Downloads/john-1.7.6/src'
make: *** [linux-x86-any] Error 2

… then you need to install libssl-dev:

sudo apt-get install libssl-dev

JtR should then build fine…