Note that there are some explanatory texts on larger screens.

plurals
  1. POGCM-Android more notifications
    primarykey
    data
    text
    <p>I want to send a notification to my android devices. the problem is after the first notification which is correctly sent and received I have to close(kill) and open the app to receive another one. I don't know what i have to change. Thank you very much</p> <p>I programmed the app like this (like the google example):</p> <pre><code>public class FirstActivity extends Activity { String TAG = "FirstActivity"; String SENDER_ID = "123456789101"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); } else { Log.v(TAG, "Already registered"); } } } </code></pre> <p>and:</p> <pre><code>public class GCMIntentService extends GCMBaseIntentService { String TAG = "GCMIntentService"; public GCMIntentService() { // TODO Auto-generated constructor stub } @Override protected void onError(Context arg0, String arg1) { // TODO Auto-generated method stub Log.d(TAG, "onError"); } @Override protected void onMessage(Context arg0, Intent arg1) { // TODO Auto-generated method stub Log.d(TAG, "onMessage"); generateNotification(arg0, arg1.getStringExtra("message")); } private static void generateNotification(Context context, String message) { long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, FirstActivity.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.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } @Override protected void onRegistered(Context arg0, String arg1) { // TODO Auto-generated method stub Log.d(TAG, "onRegistered"); } @Override protected void onUnregistered(Context arg0, String arg1) { // TODO Auto-generated method stub Log.d(TAG, "onUnregistered"); } } </code></pre> <p>manifest:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="at.demo.gcm" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;permission android:name="at.demo.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt; &lt;uses-permission android:name="at.demo.gcm.permission.C2D_MESSAGE" /&gt; &lt;!-- App receives GCM messages. --&gt; &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt; &lt;!-- GCM connects to Google Services. --&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;!-- GCM requires a Google account. --&gt; &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt; &lt;!-- Keeps the processor from sleeping when a message is received. --&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="at.demo.gcm.FirstActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" &gt; &lt;intent-filter&gt; &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt; &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt; &lt;category android:name="at.demo.gcm" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;service android:name=".GCMIntentService" /&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload