I have successfully create a PUSH Notification App but the problem is the Message Received is not getting displayed on notification bar. It only Displays the title which I have set in the code.
@Override
protected void onMessage(Context context, Intent intent) {
if(aController == null)
aController = (Controller) getApplicationContext();
Log.i(TAG, "Received message");
String message = intent.getExtras().getString("price");
aController.displayMessageOnScreen(context, message);
generateNotification(context, message);
}
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
void displayMessageOnScreen(Context context, String message) {
Intent intent = new Intent(Config.DISPLAY_MESSAGE_ACTION);
intent.putExtra(Config.EXTRA_MESSAGE, message);
context.sendBroadcast(intent);
}
<!--
<uses-permission android:name="android.permission.INTERNET" />
<!--
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!--
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
<permission
android:name="com.raatechnocrates.panjoluni.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.raatechnocrates.panjoluni.permission.C2D_MESSAGE" />
<!--
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".Controller"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!--
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!--
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.raatechnocrates.panjoluni" />
</intent-filter>
</receiver>
<service android:name="com.raatechnocrates.panjoluni.GCMIntentService" />