Advertisement
Guest User

Untitled

a guest
Aug 18th, 2010
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package de.foxylion.android.testapp;
  2.  
  3. import android.app.Activity;
  4. import android.app.Notification;
  5. import android.app.NotificationManager;
  6. import android.app.PendingIntent;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.TextView;
  13.  
  14. public class Main extends Activity {
  15.     /** Called when the activity is first created. */
  16.     @Override
  17.     public void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.main);
  20.        
  21.         TextView tv = (TextView) findViewById(R.id.text);
  22.         tv.setText("Main.class");
  23.        
  24.         Button button = (Button) findViewById(R.id.button);
  25.         button.setOnClickListener(new View.OnClickListener() {
  26.             public void onClick(View v) {
  27.                 startActivity(new Intent(Main.this,
  28.                         de.foxylion.android.testapp.Sub.class));
  29.             }
  30.         });
  31.        
  32.         /* Notification basteln */
  33.         String ns = Context.NOTIFICATION_SERVICE;
  34.         NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
  35.        
  36.         int icon = R.drawable.icon;
  37.         CharSequence tickerText = "Hello";
  38.         long when = System.currentTimeMillis();
  39.        
  40.         Notification notification = new Notification(icon, tickerText, when);
  41.        
  42.         Context context = getApplicationContext();
  43.         CharSequence contentTitle = "My notification";
  44.         CharSequence contentText = "Hello World!";
  45.         Intent notificationIntent = new Intent(this, Main.class);
  46.         notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
  47.         PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
  48.        
  49.         notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
  50.         notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
  51.        
  52.         mNotificationManager.notify(1, notification);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement