Java ME Bluetooth geräte suchen

Knexi

Mitglied
Hallo

ich würde gerne eine J2ME Anwendung schreiben mit der mit möglichst vielen Handys die Suche von Geräten und das verbinden mit dem Gerät funktioniert. Habe bereits 1ne Java Klasse dafür aber diese funktioniert nur auf 2 von 20 getesteten Handys fehlerfrei. Bei allen anderen stürzt die Suche ab oder das Programm lässt sich nicht starten.

Nun hab ich in einem Buch was zur Bluetooth Verbindung gefunden und versucht eine neue Klasse dafür zu erstellen, aber beim builden kommen Fehler, die ich nicht beheben konnte und mir merkwürdig vorkommen.

Programm sieht wie folgt aus:
Java:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.bluetooth.*;
import java.util.Vector;
import java.io.*;
import javax.microedition.io.*;

/**
 * @author Knexi
 */
public class bt_test extends MIDlet implements
        Runnable,CommandListener,DiscoveryListener{
    private List deviceList;
    private List SRListe;
    private DiscoveryAgent agent;
    private Vector gefundeneGeraete=new Vector();
    private boolean aktiveSuche=false;
    private static final Command CMD_NAME=new Command("Gerätenamen",Command.ITEM,3);
    private static final Command CMD_EXIT=new Command("Ende",Command.EXIT,0);
    private static final Command CMD_INQUIRY=new Command("Inquiry",Command.ITEM,1);
    private static final Command CMD_SIMPLE=new Command("Einfache Suche",Command.ITEM,2);
    private static final Command CMD_DIENST=new Command("Dienst Suche",Command.ITEM,2);
    protected void pauseApp() {}
    
     protected void destroyApp(boolean arg0) {}
    
    protected void startApp() {new Thread(this).start();}

    public void commandAction(Command c,Displayable d)
    {
        if(c==CMD_NAME)
        {
            if(aktiveSuche)
            {
                agent.cancelInquiry(this);
                aktiveSuche=false;
            }
            if(deviceList.getSelectedIndex()>=0)
                ZeigeInfo((RemoteDevice)gefundeneGeraete.elementAt(deviceList.getSelectedIndex()));
        }
        if(c==CMD_EXIT)
        {
            agent.cancelInquiry(this);
            aktiveSuche=false;
            notifyDestoyed();
        }
        if(c==CMD_INQUIRY)
        {
            Alert info=new Alert("Inquiry","Suche gestartet.",null,AlertType.INFO);
            info.setTimeout(3000);
            Display.getDisplay(this).setCurrent(info);
            try
            {
                agent.startInquiry(DiscoveryAgent.GIAC,this);
            }catch(BluetoothStateException e){//behandeln
            }
            aktiveSuche=true;
        }
        if(c==CMD_SIMPLE)
        {
            EinfacheGeraeteSuche();
        }
        if(c==CMD_DIENST)
        {
            if(aktiveSuche)
            {
                agent.cancelInquiry(this);
                aktiveSuche=false;
            }
            if(deviceList.getSelectedIndex()>=0)
                dienstSuche((RemoteDevice)gefundeneGeraete.elementAt(deviceList.getSelectedIndex()));
            //Implementierung siehe weiter unten
        }
    }
    public void run()
    {
        try{
            LocalDevice local=LocalDevice.getLocalDevice();
            agent=local.getDiscoveryAgent();
        }catch(BluetoothStateException e){
            //Exception behandeln
        }
        deviceList=new List("Geräteliste",List.IMPLICIT);
        deviceList.addCommand(CMD_EXIT);
        deviceList.addCommand(CMD_INQUIRY);
        deviceList.addCommand(CMD_SIMPLE);
        deviceList.addCommand(CMD_NAME);
        deviceList.setCommandListener(this);
        Display.getDisplay(this).setCurrent(deviceList);
    }

    public void deviceDiscovered(RemoteDevice device,DeviceClass cod)
    {
        try
        {
            String friendlyName=device.getFriendlyName(true);
            deviceList.append(friendlyName, null);
            gefundeneGeraete.addElement(device);
        }catch(java.io.IOException e){
            //Exception behandeln
        }
    }

    public void inquiryCompleted(int type)
    {
        if(type==DiscoveryListener.INQUIRY_COMPLETED)
        {
            Alert info=new Alert("Inquiry","Suche beendet",null,AlertType.INFO);
            info.setTimeout(3000);
            Display.getDisplay(this).setCurrent(info);
        }
        else
        {
            Alert info=new Alert("Inquiry","Suche mit Fehler beendet.",null,AlertType.INFO);
            info.setTimeout(3000);
            Display.getDisplay(this).setCurrent(info);
        }
    }
    public void servicesDiscovered(int transID,ServiceRecord[] record)
    {
    }
    public void serviceSearchCompleted(int transID, int type)
    {
    }

    private void EinfacheGeraeteSuche()
    {
        RemoteDevice[] list=agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
        if(list!=null)
        {
            for(int i=0;i<list.length;i++)
            {
                try{
                    String friendlyName=list[i].getFriendlyName(true);
                    deviceList.append(friendlyName,null);
                    gefundeneGeraete.addElement(list[i]);
                }catch(java.io.IOException e){
                    //Exception behandeln
                }
            }
        }
        list=agent.retrieveDevices(DiscoveryAgent.CACHED);
        if(list!=null)
        {
            //...wie oben
        }
    }
    private void ZeigeInfo(RemoteDevice device)
    {
        String daten="leer";
        try
        {
            daten=device.getBluetoothAddress()
                    +"\n"
                    +device.getFriendlyName(false);
        }catch(java.io.IOException e){
            //Exception behandeln
        }
        Alert info=new Alert("Geräteinformationen",daten,null,AlertType.INFO);
        info.setTimeout(Alert.FOREVER);
        Display.getDisplay(this).setCurrent(info);
    }
}


Es kommt in der Zeile 76 zu Fehlern:


D:\bluetooth_test_buch\src\bt_test.java:76: cannot find symbol
symbol : method dienstSuche(javax.bluetooth.RemoteDevice)
location: class bt_test
dienstSuche((RemoteDevice)gefundeneGeraete.elementAt(deviceList.getSelectedIndex()));





Ich hoffe einer von euch kann mir weiterhelfen


MfG Knexi
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
K Androidstudio Bluetooth connect Android & Cross-Platform Mobile Apps 6
xXSkyWalkerXx1 Android Bluetooth LE - Frage zur Funktionalität Android & Cross-Platform Mobile Apps 26
S Android Studio Bluetooth App Problem Android & Cross-Platform Mobile Apps 6
D Android Bluetooth Chat Example modifizieren Android & Cross-Platform Mobile Apps 6
T Musik über Bluetooth streamen Android & Cross-Platform Mobile Apps 2
H WIFI, Bluetooth und NFC Verbindung überwachen Android & Cross-Platform Mobile Apps 1
A Zweite Kamera an HTC und per Bluetooth kommunizieren? Android & Cross-Platform Mobile Apps 2
W Bluetooth und obex Package nutzen Android & Cross-Platform Mobile Apps 4
P Bluetooth vom remoteDevice auf den Stream Android & Cross-Platform Mobile Apps 9
K Java ME Bluetooth verbindung parameter Android & Cross-Platform Mobile Apps 3
K Java ME J2ME Bluetooth - bluesoleil,bluecove, JSR82... ? Android & Cross-Platform Mobile Apps 6
S Wie teste ich meine Bluetooth Anwendung Android & Cross-Platform Mobile Apps 4
G Bluetooth LocalDevice.isPowerOn() meldet false Android & Cross-Platform Mobile Apps 2
R Bluetooth und Sun Wireless Toolkit 2.5.2 Android & Cross-Platform Mobile Apps 3
G Bluetooth Verbindung zwischen Handy und PC Android & Cross-Platform Mobile Apps 5
W Datenbankzugriff, WLAN, Bluetooth Android & Cross-Platform Mobile Apps 2
T Java Bluetooth Kalender Android & Cross-Platform Mobile Apps 2
C How to send AT-Commands via Bluetooth using JSR-82 Android & Cross-Platform Mobile Apps 3
G Bluetooth Verbindung Android & Cross-Platform Mobile Apps 2
J Bluetooth Stick und Lego Mindstorms Android & Cross-Platform Mobile Apps 2
O Bluetooth Verbindung zwischen 2 Handys Android & Cross-Platform Mobile Apps 5
D Bluetooth Pairing dem Programm ueberlassen? Android & Cross-Platform Mobile Apps 3
L HTTP via Bluetooth Android & Cross-Platform Mobile Apps 2
D Start/Stop Bit per Bluetooth von PC zu PC, oder PCtoHandy Android & Cross-Platform Mobile Apps 2
M bluetooth? Android & Cross-Platform Mobile Apps 3
D Android Layout für alle Geräte Android & Cross-Platform Mobile Apps 4
M Zwei Android Geräte verbinden Android & Cross-Platform Mobile Apps 7
G Android C++ Quellcode für Android Geräte compilieren Android & Cross-Platform Mobile Apps 2
L Geräte Kompatibilität Android & Cross-Platform Mobile Apps 4
B Android wie kann ich in einer xml nach bestimme item suchen (DOM) Android & Cross-Platform Mobile Apps 7
Fischkralle Android Nach Textdateien in Ordner suchen Android & Cross-Platform Mobile Apps 5

Ähnliche Java Themen

Neue Themen


Oben