Sending data with push notification

I am not being able to send data through the push notification using intents. Is there any easy way around?

Hello!

Can you please describe what data you’d like to send? Is it an object of any class?

Alex.

I am pasting the code for push notification which I used below:

public class PushReceiver extends BackendlessBroadcastReceiver
{
Context applicationContext = Balchal.getContextOfApplication();
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(applicationContext);
//SharedPreferences sharedPref= getSharedPreferences(“user_data”, Context.MODE_PRIVATE);
//SharedPreferences.Editor spEditor= sharedPref.edit();

@Override
public boolean onMessage( Context context, Intent intent )
{

    CharSequence tickerText = intent.getStringExtra( PublishOptions.ANDROID_TICKER_TEXT_TAG );
    CharSequence contentTitle = intent.getStringExtra( PublishOptions.ANDROID_CONTENT_TITLE_TAG );
    CharSequence contentText = intent.getStringExtra( PublishOptions.ANDROID_CONTENT_TEXT_TAG );
    String subtopic = intent.getStringExtra( "message" );

    if( tickerText != null && tickerText.length() > 0 )
    {
        int appIcon = context.getApplicationInfo().icon;
        if( appIcon == 0 )
            appIcon = android.R.drawable.sym_def_app_icon;

        Intent notificationIntent = new Intent( context, Balchal.class );
        notificationIntent.putExtra("subtopic",subtopic);
        notificationIntent.putExtra("checker",1);
        //sharedPref.getString("subtopic", "")
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(Balchal.class);
        stackBuilder.addNextIntent(notificationIntent);

        //notificationIntent.putExtra("checker",1);

        PendingIntent contentIntent =stackBuilder.getPendingIntent(
                0,
                PendingIntent.FLAG_UPDATE_CURRENT
        );
        // PendingIntent.getActivity( context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT );

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( context );
        notificationBuilder.setSmallIcon( appIcon );
        notificationBuilder.setTicker( tickerText );
        notificationBuilder.setWhen( System.currentTimeMillis() );
        notificationBuilder.setContentTitle( contentTitle );
        notificationBuilder.setContentText( contentText );
        notificationBuilder.setAutoCancel( true );
        notificationBuilder.setContentIntent( contentIntent );

        Notification notification = notificationBuilder.build();

        NotificationManager notificationManager = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE );
        notificationManager.notify( 0, notification );
    }

    return false;
}

}************************************************************If possible give me an example of an intent being sent through push notification.

You can send info through instance of Intent class using bundle “Extras” putting values on sending side and getting them on receiving side.
For example:
// on sending side
notificationIntent.putExtra( “firstKey”, “firstValue” );
// on receiving side
String recievedValue = intent.getStringExtra( “firstKey” );
More you can read here: http://developer.android.com/reference/android/content/Intent.html

If you don’t see notification on receiving side and you’re using our generated code, it might be because of the following statement:
if( tickerText != null && tickerText.length() > 0 )
If one of these conditions is false, you’ll not be able to see any message on device. To check that comment this row in code, recompile the project and try sending notification again.

I am being able to see the message, but somehow the activity created through the intent is not opening on clicking the notification message. Moreover I am putting a ticker text whose length is more than zero. The code segment where the push notification is being used is given below:


PublishOptions publishOptions = new PublishOptions();
publishOptions.setPublisherId(sp.getString(“facebook_id”, “”));
publishOptions.setSubtopic(subtopic);
publishOptions.putHeader( PublishOptions.ANDROID_TICKER_TEXT_TAG, String.format( DefaultMessages.CONNECT_DEMAND,
sp.getString(“facebook_id”, “”) ) );
publishOptions.putHeader( PublishOptions.ANDROID_CONTENT_TITLE_TAG, getResources().getString( R.string.app_name ) );
publishOptions.putHeader( PublishOptions.ANDROID_CONTENT_TEXT_TAG, String.format( DefaultMessages.CONNECT_DEMAND,
sp.getString(“facebook_id”, “”) ) );
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushPolicy( PushPolicyEnum.ONLY );
deliveryOptions.addPushSinglecast( sp.getString(“companion”, “”) );

So you cannot open application by clicking on received message?
If so, then describe what exactly happens? Maybe, any errors are present in device logs?

Will it be easier if upload the entire project?

Yes, sure.
My email is alex.navara@themidnightcoders.com if you’d like to send it directly.

I’ve sent you the zipped file. Check your email.

I don’t see it. Can you check if it has been sent and try again please?

Yahoo is showing me its already sent. So, can you please check your email once again?

This is the mediafire link: https://www.mediafire.com/?k9m6294e3c6kudo