Archive for 'Notifications'

Android Notification

NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(this, "Your linked class");

    PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);

    Notification note =  new Notification(R.drawable.ic_launcher, "Notification Title", System.currentTimeMillis());

    note.setLatestEventInfo(this, "Title", "Description", pi);

    note.defaults |= Notification.DEFAULT_ALL;

    note.flags |= Notification.FLAG_AUTO_CANCEL;

    int id = Integer.parseInt(intent.getStringExtra("id"));

    manager.notify(id, note);

 

The following android application will create a “Hello World” notification in the status bar. Just copy the following code and paste it in your android app:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//Create notification service reference
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

//Notification icon
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";

//When to show notification
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

Context context = getApplicationContext();

//Notification title and text
CharSequence notificationTitle = "My notification";
CharSequence notificationText = "Hello World!";
//Notification intent
Intent notificationIntent = new Intent(this, NotificationAppActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, notificationTitle, notificationText, contentIntent);

final int HELLO_ID = 1;
//Show notification
mNotificationManager.notify(HELLO_ID, notification);

}

Hiding the Notification Bar and Title Bar in Android

Android Hiding the Status Bar or Notification Bar
Hiding the title bar & status bar is generally used in gaming and full-screen applications in-order to utilize the entire screen area. We come also come across various places where we need to hide the title bar or notifications bar.

What is Status Bar or Notifications Bar and Title bar?

What is Status bar and title bar in Android?

Method 1: Through Code

Hide the Status bar or Notifications Bar and Title Bar through coding (Not recommended)
Code:

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.myActivity);

// Hide the Title Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);

// Hide the Notification or Status Bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

//use in any combinations you want

}

Method 2: Through AndroidManifest.xml
Hiding the Title bar through AndroidManifest.xml
CODE

<activity  android:name=".YourClassName"
android:theme="@android:style/Theme.NoTitleBar"/>

Hiding both the Status or Notification bar and Title bar through AndroidManifest.xml

<activity  android:name=".YourClassName"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

Incoming search terms:

  • hide notification bar Android

Code to cancel all local notifications

Using this code we can cancel all the local notifications in iPhone, programmatically.



[[UIApplication sharedApplication] cancelAllLocalNotifications];


We Can Build Your App for You. Lets Get Started !