Hello everyone,
i am using this code when two users are doing to chat lwith wach other. and it is...
var gcm = require('com.activate.gcm');
// var gcm = require('net.iamyellow.gcmjs');
// alert(gcm);
var pendingData = gcm.data;
if (pendingData && pendingData !== null) {
Ti.API.info('******* data (started) ' + JSON.stringify(pendingData));
}
Ti.API.info('module gcm is => ' + gcm);
Ti.API.info('Registering...');
gcm.registerC2dm({
success:function(e)
{
Ti.API.info('JS registration success event: ' + e.registrationId);
//alert('JS registration success event: ' + e.registrationId);
Ti.API.info('Sender ID:' + gcm.getSenderId());
//saveAndroidDeviceToken(e.registrationId);
},
error:function(e)
{
Ti.API.error("Error during registration : " + e.error);
var message;
if(e.error == "ACCOUNT_MISSING")
{
message = "No Google account found; you will need to add on in order to activate notifications";
}
Titanium.UI.createAlertDialog({
title:'Push Notification Setup',
message:message,
buttonNames:['OK']
}).show();
},
///------------when the app is foreground-------------////
callback:function(e)
{
Ti.API.info("push notification received"+JSON.stringify(e.data));
//alert("push notification received"+JSON.stringify(e.data));
Titanium.Media.vibrate();
var user_message =e.data.message;
var deviceid=e.data.from;
var wholedata=user_message+' '+deviceid;
var msgArr =user_message.split("::::");
// alert(msgArr[0]);
// alert(msgArr[1]);
if(msgArr[1] == "friend_request"){
}
else{
var thisRow = Ti.UI.createTableViewRow();
thisRow.selectedColor ='transparent';
var user_pic =Titanium.App.Properties.getString('friend_image');
if(user_pic !=null && user_pic !=undefined && user_pic !=''){
var pic_src = Ti.Utils.base64decode(user_pic);
}
else{
var pic_src = 'newimages/user_profile.png';
}
var invitefriend_image = Titanium.UI.createImageView({
image:pic_src,
top:20,
width:'16%',
height:60,
borderColor:'#fff',
borderRadius:5,
borderWidth:1,
right:'0%',
zIndex:100
});
var invitefriend_dynamicview = Titanium.UI.createView({
top:30,
backgroundImage:'newimages/chat_box_1.png',
width:230,
height: Titanium.UI.SIZE,
right:'20%'
});
var invitefriend_user_name = Ti.UI.createLabel({
color: '#000',
font: {
fontSize:16,
fontWeight: 'bold',
fontFamily:'ThisApp.FONTBOLD',
},
text: msgArr[0],
right:'2%',
top:2,
width: 'auto',
height: 30,
backgroundImage:'none'
});
thisRow.add(invitefriend_image);
invitefriend_dynamicview.add(invitefriend_user_name);
invitefriend_dynamicview.height=invitefriend_user_name.height+10;
thisRow.add(invitefriend_dynamicview);
searchData.push(thisRow);
tableview.setData(searchData);
lastRow = searchData.length - 1;
tableview.scrollToIndex(lastRow,{animated:true,position:Ti.UI.iPhone.TableViewScrollPosition.BOTTOM});
////----------------updated by supriya----------6th august13--------////
// sendAndroidGCM(chat_msg);
}
},
unregister: function (ev) {
// on unregister
Ti.API.info('******* unregister, ' + ev.deviceToken);
},
data: function (data) {
// if we're here is because user has clicked on the notification
// and we set extras in the intent
// and the app WAS RUNNING (=> RESUMED)
// (again don't worry, we'll see more of this later)
Ti.API.info('******* data (resumed) ' + JSON.stringify(data));
//alert('******* data (resumed) ' + JSON.stringify(data));
}
});
});
and i want when any of messages came to users when the users not in that particular screen, then a notification widget shown with two button as we shown in line messaenger.
when click on the read button then it redirect to the chatscreen.js as in app.
and if not then it is not to move to further process.
Please provide me a solution as soon as possible...
thanks,
supriya