Deutron
- Forum-Beiträge: 53
11.05.2012, 21:25:28 via Website
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:
Was kann ich tun?
Vielen, Vielen Dank im Voraus
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;
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
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.