ad728

Monday, October 10, 2016

AIDE Tutorial - 26.1 Updating Notification

Main.Xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
    <Button
android:onClick="show"
        android:text="Click here"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java

package com.kc.UpdatingNotification;
import android.app.*;
import android.os.*;
import android.view.*;
import android.content.*;
public class MainActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
int count=0;



public void show (View v){
count++;
Notification.Builder nb= new Notification.Builder(this);
nb.setContentTitle("My Notification");
nb.setContentText("You clicked!!! "+count+" times");
nb.setSmallIcon(R.drawable.ic_launcher);

NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1,nb.build());
}
}


Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300