当我点击状态栏通知,应用程序不启动 [英] When I click on notification in status bar, application is not launching

查看:223
本文介绍了当我点击状态栏通知,应用程序不启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试开发一种使用GCM库的应用程序,但是当我点击通知状态栏,应用程序没有启动...

I try to develop an application which use GCM library, but when I click on notification in status bar, application is not launching...

下面是我的源$ C ​​$ C在我GCMIntentService类:

Here is my source code in my GCMIntentService class:

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, LauncherActivity.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(1, notification);
}

而code清单中:

And the code in manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smarttram.caen"
android:versionCode="7"
android:versionName="1.0" >    

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
<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.smarttram.caen.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.smarttram.caen.permission.C2D_MESSAGE" />  
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />   
<uses-permission android:name="android.permission.VIBRATE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light.DarkActionBar" > 

    <activity
        android:name="com.smarttram.caen.LauncherActivity"
        android:label="@string/title_activity_main"
        android:screenOrientation="portrait"
        android:hardwareAccelerated="true">    

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <activity android:name="com.google.ads.AdActivity"             
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    <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.smarttram.caen" />
        </intent-filter>

    </receiver>

    <service android:name=".GCMIntentService" />         

</application>

推荐答案

您都争相推出 LauncherActivity.class 吧?

删除行:

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);

尝试添加标志在的PendingIntent

的PendingIntent pintent = PendingIntent.getActivity(背景下,0,意向,Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

这篇关于当我点击状态栏通知,应用程序不启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆