-3
我正在使用GCM通知,我已經完成了關於接收數據的所有設置,Gcm通知即將到來,但是當我點擊通知時,它會打開,但我意圖得到空值。Gcm活動中的通知數據
我chatscreenctivity
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
}
這裏是我的自定義通知和我傳遞的價值在notificationIntent
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);
}
如果應用程序崩潰你必須顯示'Logcat'跡線,以便我們可以識別'bug'更容易 – hrskrs 2015-02-06 07:35:20
我說過錯誤已經解決了,但是我得到了空值 String message = intent.getExtras()。getString(「broadmessage」); ** // Hre我得到空** String sender_image = intent.getExtras()。getString(「sender_image」); ** // Hre我得到空** String sender_Name = intent.getExtras()。getString(「發件人名稱」);這裏 – user3825086 2015-02-06 07:44:19
請修改你的問題然後 – hrskrs 2015-02-06 08:20:16