Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to implement Notification service
    primarykey
    data
    text
    <p>I referred following links to study the demo example on Notification service in Android : <a href="http://saigeethamn.blogspot.in/2009/09/android-developer-tutorial-for.html" rel="nofollow">Sai Geetha Blog</a> and <a href="http://www.vogella.com/articles/AndroidNotifications/article.html#notificationmanager_example" rel="nofollow">Vogella Tutorial</a>.</p> <p>Both worked but partially i.e. I've downloaded both projects as it is and executed them. Both has button to initiate the notification. On Button Click notification appears at the top status bar.</p> <p>Here comes the problem, on click of that notification, neither any message is getting displayed nor intent is getting fired to navigate to new activity.</p> <p>I'm new to this concept so any help appreciated...</p> <p><em><strong>CODE</em></strong></p> <p><strong>CreateNotification .class</strong></p> <pre><code>public class CreateNotification extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void notify(View view) { NotificationManager nm= (NotificationManager) getSystemService(NOTIFICATION_SERVICE); final int UNIQUE_ID = 123458; Intent navigationIntent = new Intent(); navigationIntent.setClass(CreateNotification.this, NotificationReceiver.class); PendingIntent pi = PendingIntent.getActivity(this, 0, navigationIntent, 0); String body = "New Notification added!!!"; String title = "Title"; Notification n = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis()); n.number = 2; n.setLatestEventInfo(this, title, body, pi); n.defaults = Notification.DEFAULT_ALL; nm.notify(UNIQUE_ID, n); } } </code></pre> <hr> <p><strong>NotificationReceiver.class</strong></p> <pre><code>public class NotificationReceiver extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); Log.i("Receiver", "NotificationReceiver"); } } </code></pre> <p><strong>main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="match_parent" android:onClick="notify" android:text="Create Notification" &gt; &lt;/Button&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>result.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the result activity opened from the notification" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>AndroidManifest.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.notificationmanager" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" /&gt; &lt;uses-permission android:name="android.permission.VIBRATE" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".CreateNotification" 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;activity android:name=".NotificationReceiver" /&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    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.
 

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