Advertisement
simondid

s

Jan 4th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. package test.test;
  2.  
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.app.Notification;
  6. import android.app.NotificationManager;
  7. import android.app.PendingIntent;
  8. import android.content.Context;
  9. import android.content.Intent;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.View;
  13. import android.view.View.OnClickListener;
  14. import android.widget.Button;
  15.  
  16.  
  17. public class TesttActivity extends Activity implements OnClickListener {
  18. private Dialog dialog;
  19. private static final int HELLO_ID = 1;
  20. Button b1;
  21. Bundle hej;
  22. public void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.main);
  25. hej = getIntent().getExtras();
  26.  
  27.  
  28. initilize();
  29.  
  30.  
  31. }
  32. private void initilize() {
  33. // TODO Auto-generated method stub
  34. b1 =(Button)findViewById(R.id.Button1);
  35. b1.setOnClickListener(this);
  36. }
  37.  
  38. public void onClick(View v) {
  39. // TODO Auto-generated method stub
  40. switch(v.getId()){
  41. case R.id.Button1:
  42.  
  43. createNotification(1325, "test", "testNote");
  44. Object test = hej.get("Note");
  45. String hk = test.toString();
  46. Log.i("test", ""+test);
  47. break;
  48. }
  49. }
  50. private void createNotification(int id,String MessageTitle,String MessageBody) {
  51. // TODO Auto-generated method stub
  52. String ns = Context.NOTIFICATION_SERVICE;
  53. NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
  54.  
  55. int icon = R.drawable.ic_launcher;
  56. CharSequence tickerText = "Hello";
  57. long when = System.currentTimeMillis();
  58.  
  59. Notification notification = new Notification(icon, tickerText, when);
  60.  
  61. Context context = getApplicationContext();
  62. CharSequence contentTitle = MessageTitle;
  63. CharSequence contentText = MessageBody;
  64. Intent notificationIntent = new Intent(this, TesttActivity.class);
  65. notificationIntent.putExtra("category", "category1");
  66.  
  67. notificationIntent.putExtra("Note", "note1");
  68.  
  69. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
  70.  
  71. notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
  72.  
  73. mNotificationManager.notify(id, notification);
  74. }
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement