Wednesday, 12 April 2017

Send Push Notification With Cordova And Webapi

No comments
Cordova Plugin

https://github.com/phonegap/phonegap-plugin-push

Push Plugin


var push = PushNotification.init({
           android: {
               senderID: "628523812525"
           },
           browser: {
               pushServiceURL: 'your url'
           },
           ios: {
               alert: "true",
               badge: "true",
               sound: "true"
           },
           windows: {}
       });
       PushNotification.hasPermission(function (permissionResult) {
          if (permissionResult.isEnabled) {           
            push.on('registration'function (data) {
              alert(data.registrationId,data.registrationId);          
            });
 
            push.on('notification'function (data) {
              alert(JSON.stringify(data));
            });
 
            push.on('error'function (e) {      
              alert("e.message: " + e.message);
            });
          }
        });
      

WebAPI

//RegisterId you got from Android Developer.
string deviceId = "APA91bExfJOpM0vmKW8q200RSPs5iSPugD1mKf4PSYaFaz5TyZP2QYwmYUCDVHdNV7";
 
string message = "Demo Notification";
string tickerText = "Patient Registration";
string contentTitle = "Titlesss";
string postData =
"{ \"registration_ids\": [ \"" + deviceId + "\" ], " +
  "\"data\": {\"tickerText\":\"" + tickerText + "\", " +
             "\"contentTitle\":\"" + contentTitle + "\", " +
             "\"message\": \"" + message + "\"}}";
 
//  
//  MESSAGE CONTENT  
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
 
//  
//  CREATE REQUEST  
HttpWebRequest Requests = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
Requests.Method = "POST";
//  Request.KeepAlive = false;  
 
Requests.ContentType = "application/json";
Requests.Headers.Add(string.Format("Authorization: key={0}""AIzaSyBKz7u6jeat1p09cO1"));
Requests.ContentLength = byteArray.Length;
 
Stream dataStream = Requests.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
 
//  
//  SEND MESSAGE  
 
WebResponse Response = Requests.GetResponse();
 
HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
{
    var text = "Unauthorized - need new token";
}
else if (!ResponseCode.Equals(HttpStatusCode.OK))
{
    var text = "Response from web service isn't OK";
}
 
StreamReader Reader = new StreamReader(Response.GetResponseStream());
string responseLine = Reader.ReadToEnd();
Reader.Close();
 
 
read more

Saturday, 8 April 2017

show image and text side by side in middle

No comments
<div class="game-menu" style="margin-top:10%">
           <img src="img/play.png" class="iconMenu" />
           <span class="iconSpan iconHeadFont">Play Again</span>
       </div>

<style type="text/css">
           .iconMenu {
               font-size50px;
               colorgreen;
               displayinline-block;
               vertical-alignmiddle;
               margin-top10px;
           }
 
           .iconSpan {
               displayinline-block;
               vertical-alignmiddle;
               color:white;
               font-size:40px;
               font-weight:bold;
           }
       </style>
read more