activity 中的 Gcm 通知数据
Gcm Notification data in activity
我正在使用 GCM 通知,我已经完成了所有关于接收数据的设置,GCM 通知即将到来,但是当我点击通知时,它打开了,但我的意图是空的。
我的聊天屏幕活动
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.chatscreenctivity);
Intent intent=getIntent();
registerReceiver(mHandleMessageReceiver, new IntentFilter(
DISPLAY_MESSAGE_ACTION));
String message = intent.getExtras().getString("broadmessage"); **//Hre i got Null**
String sender_image=intent.getExtras().getString("sender_image");**//Hre i got Null**
String sender_Name=intent.getExtras().getString("sender_name");
mlistview=(ListView)findViewById(R.id.listview1);
sendmessage=(ImageView)findViewById(R.id.sendmeassage);
sentext=(EditText)findViewById(R.id.et_sent_msg);
getActionBar().setTitle(sender_Name);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
Hre i got the value from gcm
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String Message ="",image="",sendername="";
String Broadscast = intent.getExtras().getString("message");
if(Broadscast.equals("You have got login points!"))
{
Message=Broadscast;
generateNotification(context, Message);
}
else
{
try
{
JSONObject json=new JSONObject(Broadscast);
Message=json.getString("message");
image=json.getString("image");
sendername=json.getString("firstname")+" "+json.getString("lastname");
}
catch(JSONException e)
{
}
generateNotification(context, Broadscast);
}
displayMessage(context, Message);
// notifies user
}
这是我的自定义通知,我正在传递值
Intent notificationIntent = new Intent(context, SlidingMenuActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent=intent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
here is diaplaymessage in common utilites
static void displayMessage(Context context, String message) {
Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
intent.putExtra("broadmessage", message);
intent.putExtra("sender_image", "fdgdfg");
context.sendBroadcast(intent);
}
像这样在 notificationIntent 中设置 Intent 数据
Intent notificationIntent = new Intent(context, SlidingMenuActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("broadmessage", message);
notificationIntent.putExtra("sender_image", "fdgdfg");
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent=intent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
我正在使用 GCM 通知,我已经完成了所有关于接收数据的设置,GCM 通知即将到来,但是当我点击通知时,它打开了,但我的意图是空的。
我的聊天屏幕活动
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.chatscreenctivity);
Intent intent=getIntent();
registerReceiver(mHandleMessageReceiver, new IntentFilter(
DISPLAY_MESSAGE_ACTION));
String message = intent.getExtras().getString("broadmessage"); **//Hre i got Null**
String sender_image=intent.getExtras().getString("sender_image");**//Hre i got Null**
String sender_Name=intent.getExtras().getString("sender_name");
mlistview=(ListView)findViewById(R.id.listview1);
sendmessage=(ImageView)findViewById(R.id.sendmeassage);
sentext=(EditText)findViewById(R.id.et_sent_msg);
getActionBar().setTitle(sender_Name);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
Hre i got the value from gcm
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String Message ="",image="",sendername="";
String Broadscast = intent.getExtras().getString("message");
if(Broadscast.equals("You have got login points!"))
{
Message=Broadscast;
generateNotification(context, Message);
}
else
{
try
{
JSONObject json=new JSONObject(Broadscast);
Message=json.getString("message");
image=json.getString("image");
sendername=json.getString("firstname")+" "+json.getString("lastname");
}
catch(JSONException e)
{
}
generateNotification(context, Broadscast);
}
displayMessage(context, Message);
// notifies user
}
这是我的自定义通知,我正在传递值
Intent notificationIntent = new Intent(context, SlidingMenuActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent=intent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
here is diaplaymessage in common utilites
static void displayMessage(Context context, String message) {
Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
intent.putExtra("broadmessage", message);
intent.putExtra("sender_image", "fdgdfg");
context.sendBroadcast(intent);
}
像这样在 notificationIntent 中设置 Intent 数据
Intent notificationIntent = new Intent(context, SlidingMenuActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("broadmessage", message);
notificationIntent.putExtra("sender_image", "fdgdfg");
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent=intent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);