PendingIntent Problem

  • Antworten:1
Deutron
  • Forum-Beiträge: 53

11.05.2012, 21:25:28 via Website

Hallo liebe Entwickler,

Ich versuche in den BluetoothChat von den Android Developers zu verbessern und möchte, dass bei einer Einkommenden Nachricht eine NotificationBar Notification erstellt wird. Wenn ich aber den Code einbaue bekomme ich nur folgende Fehlermeldung: The constructor Intent(new Handler(){}, Class<BluetoothChat>) is undefined. Wenn ich den Code aber bei onCreate schreibe funktioniert alles super.

Mein Code:
1case MESSAGE_READ:
2 byte[] readBuf = (byte[]) msg.obj;
3 // construct a string from the valid bytes in the buffer
4 String readMessage = new String(readBuf, 0, msg.arg1);
5 mConversationArrayAdapter.add(mConnectedDeviceName+": " + readMessage);
6 // Get instance of Vibrator from current Context
7 Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
8 // Vibrate for 30 milliseconds
9 v.vibrate(30);
10 CharSequence title = "Chat mit " + (mConnectedDeviceName);
11 CharSequence message = readMessage;
12
13 NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
14 Notification notification = new Notification(R.drawable.app_icon, "Chat gestartet", System.currentTimeMillis());
15
16 Intent notificationIntent = new Intent(this, BluetoothChat.class);
17 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
18
19 notification.setLatestEventInfo(BluetoothChat.this, title, message, pendingIntent);
20 notificationManager.notify(NOTIFICATION_ID, notification);
21 break;

Was kann ich tun?
Vielen, Vielen Dank im Voraus

— geändert am 11.05.2012, 21:31:33

Antworten
Ansgar M
  • Forum-Beiträge: 1.544

11.05.2012, 22:08:46 via App

Versuch mal etwas wie MeineActivity.this oder Service, etc.
Lg Ansgar

Antworten