Android 安卓活动不';无法接收来自GCM的消息
我与GCM客户有问题。 我已收到通知,并已阅读消息,但无法调用“TestView”活动 这是gcminentservice.java:Android 安卓活动不';无法接收来自GCM的消息,android,android-fragments,google-cloud-messaging,splash-screen,flags,Android,Android Fragments,Google Cloud Messaging,Splash Screen,Flags,我与GCM客户有问题。 我已收到通知,并已阅读消息,但无法调用“TestView”活动 这是gcminentservice.java: @Override protected void onMessage(Context context, Intent intent1) { String message = intent1.getExtras().getString("message"); Log.i(TAG, "new message= "+message); int
@Override protected void onMessage(Context context, Intent intent1) {
String message = intent1.getExtras().getString("message");
Log.i(TAG, "new message= "+message);
int icon = R.drawable.icon;
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 = null;
notificationIntent = new Intent(context, TestView.class);
notificationIntent.putExtra("msg", message);
//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);
}
这是manifest.xml文件:
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="example.SplashScreen"
android:label="@string/title_activity_splash_screen"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="example.TestView"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
这是TestView.java:
public class TestView extends ActionBarActivity implements ... {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
//doesn't work
Bundle extras = getIntent().getExtras();
String msg = extras.getString("msg");
Log.d("MSG","msg:"+msg);
如果我替换:
notificationIntent = new Intent(context, TestView.class);
与:
一切都好
我想将“消息”从“GCMinentService”发送到“TestView”
感谢您在这种情况下提供的任何帮助在TestView活动中尝试以下方法:
public void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) { ...
notificationIntent = new Intent(context, SplashScreen.class);
public void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) { ...