Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.foxylion.android.testapp;
- import android.app.Activity;
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class Main extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- TextView tv = (TextView) findViewById(R.id.text);
- tv.setText("Main.class");
- Button button = (Button) findViewById(R.id.button);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- startActivity(new Intent(Main.this,
- de.foxylion.android.testapp.Sub.class));
- }
- });
- /* Notification basteln */
- String ns = Context.NOTIFICATION_SERVICE;
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
- int icon = R.drawable.icon;
- CharSequence tickerText = "Hello";
- long when = System.currentTimeMillis();
- Notification notification = new Notification(icon, tickerText, when);
- Context context = getApplicationContext();
- CharSequence contentTitle = "My notification";
- CharSequence contentText = "Hello World!";
- Intent notificationIntent = new Intent(this, Main.class);
- notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
- notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
- notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
- mNotificationManager.notify(1, notification);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement