How to enable curl, on Ubuntu LAMP installation

By: Kevin | September 9, 2014

So you installed LAMP but you’re missing the cURL library. I had the same problem. By default cURL is not included with the basic installation of LAMP on Ubuntu Server 14.04. To add the cURL library simply execute this command

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

Once the installation is complete be sure to restart Apache2.

sudo /etc/init.d/apache2 restart

OR

sudo service apache2 restart

Cheers!

Android – major version 51 is newer than 50, the highest major version supported by this compiler

By: Kevin | August 21, 2014

If you have ever seen this warning while trying to build an Android project and wasn’t sure what to do to fix it, let me save you some time.

“Major version” means Java version. Java 7 = 51 and Java 6 = 50. The code is written for Java 7, and that is something that Android’s dex supports.

 

The simple fix takes you into your project setting and change the version of Java you’re compiling against.

 

Change from Java 1.6 to 1.7

 

Of course you need to have Java 7 installed. If you don’t just do a quick google search and install and try the above again.

 

Cheers!

Android colors.xml with transparency

By: Kevin | July 8, 2014

While working on a project I found the need to use transparency in my colors.xml resource file. To add transparency just throw the below Hex value in front of your normal color.

ie. For 50% white you’d use #80FFFFFF. This way the Alpha channel is utilized and you get the desired transparency.

  • 100% — FF
  • 95% — F2
  • 90% — E6
  • 85% — D9
  • 80% — CC
  • 75% — BF
  • 70% — B3
  • 65% — A6
  • 60% — 99
  • 55% — 8C
  • 50% — 80
  • 45% — 73
  • 40% — 66
  • 35% — 59
  • 30% — 4D
  • 25% — 40
  • 20% — 33
  • 15% — 26
  • 10% — 1A
  • 5% — 0D
  • 0% — 00

 

Cheers!

Converting an immutable bitmap to be mutable in Android

By: Kevin | June 11, 2014

I ran into this error while I was working with a custom view that allowed users to draw on a image using their finger.

java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

I found the quick fix is to just make a copy of the original bitmap and pass a true boolean which is the flag to make the copy mutable.

Bitmap immutableBitmap = coming from where ever your source is....
Bitmap mutableBitmap = immutableBitmap.copy(Bitmap.Config.ARGB_8888, true);//<--true makes copy mutable 
Canvas canvas = new Canvas(mutableBitmap);

Easy peasy!

 

Documentation here.

How to load php_curl.dll module in Apache – fixing Unable to load dynamic library

By: Kevin | June 9, 2014

While setting up my development environment I ran into a situation where I needed to use the php_curl.dll module to make http requests. However I kept getting the following error message from Apache in the error.log:

 

PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\\PHP\\ext\\php_curl.dll’ – The specified module could not be found.\r\n in Unknown on line 0

 

My Environment:

Windows 7 64-bit

Apache 2.2.2

PHP 5.3.25

 

A Google search revealed that curl is dependent on two other files. Requires: libeay32.dllssleay32.dll (bundled) Source here. OK great, I need those two files, but the documentation doesn’t say anything else. The Bundled only hinted that I already have these files, and I did. So I looked in the root of my installation location of PHP and voila. However, obviously this still wasn’t doing the trick. This is what I did to get php_curl.dll module loaded in Apache.

 

1. Uncomment php_curl.dll in your php.ini file.

2. Copy  libeay32.dll and ssleay32.dll from the root of your PHP folder then paste them into the bin subdirectory in Apache

3. Restart Apache services.

4. Call phpinfo() and make sure cUrl was loaded properly.

Presto! You should be hooked up! Happy cUrling!

How to set time zone in PHP ini file

By: Kevin | June 4, 2014

If you ever use the date() function in php you’ve likely ran into an error message like this:

Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘-5.0/DST’ instead

As the error/warning message suggests you can set

date_default_timezone_set()

at the top of your php script however that gets to be very repetitive and unnecessary. You could also just silence the warning with the @, however again this doesn’t really solve the problem. To get to the heart of the issue you need to edit the php.ini file. Go ahead and open the php.ini with a notepad editor. *NOTE* On Windows you need to first right click and “Run as Administrator” the on the text editor your choice otherwise sometimes it will not let you save. Add the following to  line to the file then restart Apache for the changes to take affect. A full list of time zones can be found at https://php.net/manual/en/timezones.php

Set time zone in php.ini file

 

How to pass PHP array via POST

By: Kevin | May 5, 2014

I was working on a site which had two databases and different domain names. My problem was I needed to pass information from one database (domain) to another. I wasn’t sure the best way to approach this but finally came to this conclusion. So here it is.

//Select your data from the source
$sql = "Select * from orders where Id='$orderid'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);//$row is an array

So now we have our data in $row.

Next we will use the PHP function serialize. This function takes our array and turns it into a string representation of the data, or a bit stream. More on the serialize function here.

This doesn’t quit get us there. By using the serialize function we caused another problem. Our array is now a string with a lot of quotes (“) in it. The quotes don’t mesh well within a form and prevent a large amount from being passed to the other page.

To remove the quotes I use another php function called urlencode. urlencode is a straight forward function, it takes a string and replaces the quotes with html safe characters. More on urlencode here.

<form action="somepage.php" method="post">
//I have nested my calls to urlencode and serialize
//in the value below
<input name="row" value="<?=urlencode(serialize($row))?>" />
<input type="submit" value="Save">
</form>

After this form is submitted, we do the opposite to get our original array back. Be sure to do this in reverse order.

//unserialsize data coming from previous page
$row = unserialize(urldecode($_POST['row']));

Ta-Da! Now you have the original array and the data from the previous database.

How to enable / disable word wrap in Dreamweaver

By: Kevin | May 1, 2014

The longer I work with Dreamweaver the more I find out things it can do. A simple yet annoying thing I came across recently was code that was wrapping. I program in PHP a lot and found that word wrapping makes things look more confusing than it has to. My first thought to turn this feature on or off was to head over to “Preferences” however I found out it is located in a not so obvious place.  Go to View -> Code View Options -> Word Wrap”

How to change word wrap in Dreamweaver

ImageButton not displaying drawable correctly – Android 4.4.2

By: Kevin | March 29, 2014

While working on a project running 4.4.2 I ran into a strange behavior from ImageButtons. I was using standard images from the Android Icon Pack and found that, what appeared random, some images would not display with the correct colors when running on my Moto X. I was developing on my Mac using IntelliJ’s Community Edition 13.0.3 and the images would render with the correct colors from the IDE however when ran on my device I got this.

android icon greyscaled - McGilln.com

I found this really strange. I double and tripple checked that I had put the correct images in the drawable folders. I cleaned the IDE, restarted, deleted the images and re-inserted, nothing worked. Giving up for the weekend I came back to the issue and found what is a very simple fix. I noticed that all images in the Android Icon Pack have the naming convention “ic_some_action.png”. I changed the names of all my images to single words, all lowercase, with no underscores (“_”). So, “ic_new_image.png” became “newimage.png” and “ic_camera.png” turned into just “camera.png”. For some reason this did the trick, the next time I ran on my device I got this.

android icon greyscaled - McGilln.com

I still don’t know why this happens however I now rename all my images to single words before putting them in there respective drawable folders.

Cheers!

Android Tablet – Google Play – your device isn’t compatible with this version

By: Kevin | March 11, 2014

After a year of having my Android app, on the Google Play Store I decided it was time to up the anti and redesign the app to make use of new API’s and in particular tablet optimization.

After all the coding was finished it was time for the easy part, publishing to Google Play. I had developed and tested the app on a Samsung Galaxy Tab 7.7 (SCH-I815) I went ahead and published to the store. Once active I opened the store and noticed I could not find my app while on the tablet but I could on a phone. I opened a direct link and found the message “Your device isn’t compatibly with this version”.

This obviously is wrong. I developed all the tablet specific features on the same tablet, clearly it has worked. After Google’n my heart away I finally came across a section in the developer console talking about optimization and that I should develop my app for tablets. This struck me since I thought I had already done this. I was directed to which goes over hardware requirements. Then this line hit me with light bulb status.

…here’s the proper way to declare a dependency on android.hardware.telephony, such that you can still distribute the app broadly, even to devices that don’t offer telephony:

<uses-feature android:name="android.hardware.telephony" android:required="false" />

BINGO!! YOU NEED TO EXPLICITLY STATE IN THE MANIFEST YOUR APP DOESN’T NEED TELEPHONY TO OPERATE CORRECTLY I already had been using the below and thought that covered my bases however you need to explicitly say phone operation is not needed.

<uses-permission android:name="android.permission.CALL_PHONE" android:required="false" />

Keep in mind that and are different! I thought by setting my CALL_PHONE to false I was done. Really this is asking “Can I have permission to place a phone call” where as the option is saying “It doesn’t if this device has phone hardware because I won’t need it anyway”.

So why could I test and develop the app without having the in the manifest this whole time. Because the Android system doesn’t look at these tags at all. These tags are put in there for filtration purposes to be used with Google Play and other distribution stores. By adding

<uses-feature android:name="android.hardware.telephony" android:required="false" />

to my manifest simply told Google Play it was ok to let devices without phone hardware to download this app. A bit long winded but now my app is available to tablets on the play store!

Next Page »