从启动的Intent中获取GCM Payload

时间:2016-05-14 03:30:09

标签: java android android-intent google-cloud-messaging

点击GCM通知后,我的应用会启动其主要活动。但是,我需要从通知中访问一些数据。由于意图是从有效载荷本身启动的,我不知道在哪里可以添加捆绑以合并和传递数据。活动的onResume:

@Override
public void onResume(){super.onResume();
if (getIntent().getAction() == "OPEN_ACTIVITY1") {
    Log.d("Look Here", "Called");
    String to = intent.getString("to");
    notificationlaunched = true;
    Fragment mFragment = new ChallengeFragment();
    final Bundle bundle = new Bundle();


    Log.d("to", to);
String challenge = "";
    bundle.putString("to", to);
    bundle.putString("challenge", challenge);
    mFragment.setArguments(bundle);
    FragmentTransaction transaction =      getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment, mFragment);
    transaction.addToBackStack(null);
    transaction.commit();

}
}

示例消息:

May 13, 2016 11:08:33 PM com.gcm.samples.friendlyping.GcmServer send
INFO: sending msg: <message><gcm xmlns="google:mobile:data">{"data":{"action":"ping_client","sender":"clzeqRiwDqw:APA91bFK2l6DezSXtL0v4zqnU7-L_0EZ6vjQjbbkH59jay4mGemr9mIDwf3jvlLoCDQhaJIlkCBQLZKIQoYtCzJgvcd9owYcF1oIDndaaCM6BqHwjCBM4hTbvtyTta6sS5UIhD6VcR4G"},"notification":{"body":"John Smith","num":"chmm","title":"App Title","icon":"mipmap/ic_launcher","action":"ping_client","sound":"default","click_action":"OPEN_ACTIVITY1"},"to":"dZ4JkLMxhcU:APA91bGe2fdnOiqeZbHBr7ZxX21VmSQxz5xmbtJLsyccwNbVvZP9Ln5mL3DN4ErLk0HLfuxszZgGFytmuG-GJ7kl21Hk_d1QN1qbyfc5m_KDTsX1SKAW9lEkEAit7gYulUe3Bhb9RN_l","message_id":"1463195313920"}</gcm></message>

getString(&#34; to&#34;)为空。目的在于清单。如何从此消息中获取信息? 谢谢你的帮助。

0 个答案:

没有答案