• Advertisement

GCM server Side php

Here is the server side programming for GCM (GOOGLE CLOUD MESSAGING) I have not tried this yet but I found it here: https://github.com/mattg888/GCM-PHP-Server-Push-Message

setDevices($devices);
$response = $an->send($message);
———————–

$apiKey Your GCM api key
$devices An array or string of registered device tokens
$message The mesasge you want to push out

@author Matt Grundy

Adapted from the code available at:
http://stackoverflow.com/questions/11242743/gcm-with-php-google-cloud-messaging

*/
class GCMPushMessage {

var $url = ‘https://android.googleapis.com/gcm/send’;
var $serverApiKey = “”;
var $devices = array();

function GCMPushMessage($apiKeyIn){
$this->serverApiKey = $apiKeyIn;
}

function setDevices($deviceIds){

if(is_array($deviceIds)){
$this->devices = $deviceIds;
} else {
$this->devices = array($deviceIds);
}

}

function send($message){

if(!is_array($this->devices) || count($this->devices) == 0){
$this->error(“No devices set”);
}

if(strlen($this->serverApiKey) error(“Server API Key not set”);
}

$fields = array(
‘registration_ids’ => $this->devices,
‘data’ => array( “message” => $message ),
);

$headers = array(
‘Authorization: key=’ . $this->serverApiKey,
‘Content-Type: application/json’
);

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $this->url );

curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);

return $result;
}

function error($msg){
echo “Android send notification failed with error:”;
echo “\t” . $msg;
exit(1);
}
}

?>

Data type for Storing A large number in java

To Use Large number like 123456789.3423 in java we can use the following Data Types

BigDecimal,

BigInt

BigFloat

 

How To Use:

BigDecimal bd = new BigDecimal(12345667777.343423423);

 

Android ListView with multiple String arrays using Simple Adapter

Here is a Simple and very Easy tutorial if you want to show more than two lines in a single list item.

Steps:

  1. Create 2 layouts in res/layout folder. “main.xml” and   “list_item.xml”
  2. Create a listview in main.xml                (code given below)
  3. Create two textview in list_item.xml      (code given below)
  4. Create MainActivity and set main.xml as its layout. (code given below)
  5. Run the application.

source belowSource code:

Continue reading

ArrayAdapter Example Android with Source Code

//Pending

ArrayAdapter Example Android with Source Code

//Pending

ArrayAdapter Example Android with Source Code

Android Listview with Images Example with Source Code

//Pending

Android Async Task Example with Source Code

Android Simple Listview Example with Source Code

// Pending

Simple Database Example Android with Source Code

Pending