Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Android titanium com.activate.gcm Module Issues

$
0
0

Hello Everyone,

Its urgent to help me that i am using the module of com.activate.gcm module for the purpose os push Notification.. So i am using to this following steps:----> 1).I am generating a sender Id, API Key with the help of my email id.and save a api key to the server. with the help of http://developer.android.com/google/gcm/gs.html#create-proj.

2).these sender id i have to used in tiapp.xml..

<property name="com.activate.gcm.sender_id" type="string">759989341661 </property> <!-- put your sender_id here --> <!--<property name="com.activate.gcm.icon" type="int">2130837504</property> get this from R.java, but converted to decimal, 0x7f020000 give you 2130837504 (type "0x7f020000 to decimal" in google) --> <property name="com.activate.gcm.component" type="string">gcm.gcm/gcm.gcm.GcmActivity</property>

3).Then in my application when the open the window of chat screen then i used this code with 5 functions :-------------------> registerC2dm success error callback unregister unregister

registerC2dm success error--------------->these three functions are working well,-----------> but if i gave only the single alert under callback, then it never work, i dont know what the exact problem exist here .

I want only the implement functionaltity that when the two users are goiing to be chat with each othere then when the first user do a chat then the messages shown on the left . and when the messages came from the friends the it shows on the right .

i am using this following code for cloud messaging. please check it an dprovide me a solution that why the callback function is not executing.

var gcm = require('com.activate.gcm');
// 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...');
// alert('Registering...');
gcm.registerC2dm({ success:function(e) { //alert('1'); Ti.API.info('JS registration success event: ' + e.registrationId); alert('JS registration success event: ' + e.registrationId); Ti.API.info('Sender ID:' + gcm.getSenderId()); alert('Sender ID:' + gcm.getSenderId()); // // //saveAndroidDeviceToken(e.registrationId); }, error:function(e) { Ti.API.error("Error during registration : " + e.error); //alert("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) { alert('working'); // alert(e.data); 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("::::"); //
// ///------------------updated by supriya in chat 3rd august 113------------////
var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, className : 'com.apphomeSNS.LINKME.LinkmeActivity', packageName : 'com.apphomeSNS.LINKME' }); // alert(intent); intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); // This is fairly static: Not much need to be altered here var pending = Ti.Android.createPendingIntent({ activity : Ti.Android.currentActivity, intent : intent, type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY, });

                var notification = Ti.Android.createNotification({
                    contentIntent : pending,
                    contentTitle : 'New message',
                    contentText : e.data.message,
                    tickerText : &quot;New message&quot;
                });
               // /// alert(notification.contentText);
                  Ti.Android.NotificationManager.notify(1, notification);

                var toast = Ti.UI.createNotification({
                     message:e.data,
                     duration: Ti.UI.NOTIFICATION_DURATION_LONG
                 });
                 toast.show();
                if(msgArr[1] == &quot;friend_request&quot;){

                }
                else{
                         var thisRow = Ti.UI.createTableViewRow();
                         thisRow.selectedColor ='transparent';
                          var user_pic =Titanium.App.Properties.getString('friend_image');
                          if(user_pic !=null &amp;&amp; user_pic !=undefined &amp;&amp; user_pic !=''){

                             var pic_src = Ti.Utils.base64decode(user_pic);
                           }
                           else{

                             var pic_src = 'images/user_profile.png';
                           }


                           var invitefriend_image = Titanium.UI.createImageView({
                                 image:pic_src,
                                 top:20,
                                 width:'16%',
                                 height:50,
                                 borderColor:'#fff',
                                 borderRadius:5,
                                 borderWidth:1,
                                 right:'0%',
                                 zIndex:100
                          });
                          var invitefriend_dynamicview = Titanium.UI.createView({
                                 top:30,
                                 backgroundColor:'#ead8b4',
                                 width:230,
                                 height:75,
                                 borderColor:'#ead8b4',
                                 borderRadius:5,
                                 borderWidth:2,
                                 right:'20%'
                          });
                          var invitefriend_user_name = Ti.UI.createLabel({
                                    color: '#000',
                                    font: { 
                                     fontSize:16,
                                     fontWeight: 'bold',
                                     fontFamily:'ThisApp.FONTBOLD',
                                     },
                                    text: 'hello',
                                    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);
                     }
                },

            unregister: function (ev) {
                //alert('unregister');
                // 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 (=&gt; 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));
            }
     });
});

/////-------------the right view for when the messages came from friends....

thanks, supriya


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>