Click here to Skip to main content
15,889,724 members
Home / Discussions / Android
   

Android

 
QuestionRealize multipage app Pin
Andy_Bell1-Sep-16 12:14
Andy_Bell1-Sep-16 12:14 
AnswerRe: Realize multipage app Pin
Afzaal Ahmad Zeeshan4-Sep-16 0:43
professionalAfzaal Ahmad Zeeshan4-Sep-16 0:43 
QuestionWant to keep bluetooth device connection in entire application. Bluetooth connection is lost while switch to another activity ... ? Pin
utkarsh.incarnate26-Aug-16 19:48
utkarsh.incarnate26-Aug-16 19:48 
QuestionRe: Want to keep bluetooth device connection in entire application. Bluetooth connection is lost while switch to another activity ... ? Pin
Richard MacCutchan26-Aug-16 21:04
mveRichard MacCutchan26-Aug-16 21:04 
AnswerRe: Want to keep bluetooth device connection in entire application. Bluetooth connection is lost while switch to another activity ... ? Pin
Member 1016528829-Aug-16 12:53
Member 1016528829-Aug-16 12:53 
QuestionRe: Want to keep bluetooth device connection in entire application. Bluetooth connection is lost while switch to another activity ... ? Pin
David Crow29-Aug-16 16:36
David Crow29-Aug-16 16:36 
GeneralRe: Want to keep bluetooth device connection in entire application. Bluetooth connection is lost while switch to another activity ... ? Pin
Utkarsh Joshi 13-Sep-16 21:09
Utkarsh Joshi 13-Sep-16 21:09 
AnswerRe: Want to keep bluetooth device connection in entire application. Bluetooth connection is lost while switch to another activity ... ? Pin
Utkarsh Joshi 13-Sep-16 20:59
Utkarsh Joshi 13-Sep-16 20:59 
When you are Selecting A device to connect and when you are click on the device list item for requesting a connection to the device use AsyncTask
and put the connect method inside the AsyncTask like this :-

AsyncTask.execute(new Runnable() {
@Override
public void run() {

try {

bluetoothSocket = Globals.bluetoothDevice.createRfcommSocketToServiceRecord(Globals.DEFAULT_SPP_UUID);
bluetoothSocket.connect();

// After successful connect you can open InputStream
} catch (IOException e) {
e.printStackTrace();
}

Here is the full code for the same problem that i have cracked :-

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {

lablelexconnected.setText("Connecting ...");
bdDevice = arrayListBluetoothDevices.get(position);
//bdClass = arrayListBluetoothDevices.get(position)
// Toast.makeText(getApplicationContext()," " + bdDevice.getAddress(),Toast.LENGTH_SHORT).show();
Log.i("Log", "The dvice : " + bdDevice.toString());

bdDevice = bluetoothAdapter.getRemoteDevice(bdDevice.getAddress());


Globals.bluetoothDevice = bluetoothAdapter.getRemoteDevice(bdDevice.getAddress());
System.out.println("Device in GPS Settings : " + bdDevice);
// startService(new Intent(getApplicationContext(),MyService.class));

/* Intent i = new Intent(GpsSettings.this, MyService.class);
startService(i);*/
// finish();


// connectDevice();


AsyncTask.execute(new Runnable() {
@Override
public void run() {

try {

bluetoothSocket = Globals.bluetoothDevice.createRfcommSocketToServiceRecord(Globals.DEFAULT_SPP_UUID);
bluetoothSocket.connect();

// After successful connect you can open InputStream

InputStream in = null;
in = bluetoothSocket.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
br = new BufferedReader(isr);

while (found == 0) {
String nmeaMessage = br.readLine();
Log.d("NMEA", nmeaMessage);
// parse NMEA messages
sentence = nmeaMessage;

System.out.println("Sentence : " + sentence);


if (sentence.startsWith("$GPRMC")) {
String[] strValues = sentence.split(",");
System.out.println("StrValues : " + strValues[3] + " " + strValues[5] + " " + strValues[8]);
if (strValues[3].equals("") && strValues[5].equals("") && strValues[8].equals("")) {
Toast.makeText(getApplicationContext(), "Location Not Found !!! ", Toast.LENGTH_SHORT).show();

} else {

latitude = Double.parseDouble(strValues[3]);
if (strValues[4].charAt(0) == 'S') {
latitude = -latitude;
}
longitude = Double.parseDouble(strValues[5]);
if (strValues[6].charAt(0) == 'W') {
longitude = -longitude;
}
course = Double.parseDouble(strValues[8]);

// Toast.makeText(getApplicationContext(), "latitude=" + latitude + " ; longitude=" + longitude + " ; course = " + course, Toast.LENGTH_SHORT).show();
System.out.println("latitude=" + latitude + " ; longitude=" + longitude + " ; course = " + course);
// found = 1;

NMEAToDecimalConverter(latitude, longitude);


}
}


}


} catch (IOException e) {
e.printStackTrace();
}


}
});


}

});


BDW Richard MacCutchan this is my another account. I have solved My Problem.

modified 14-Sep-16 5:52am.

QuestionProblem with custom row in List View Pin
Andy_Bell26-Aug-16 9:38
Andy_Bell26-Aug-16 9:38 
QuestionRe: Problem with custom row in List View Pin
David Crow26-Aug-16 10:02
David Crow26-Aug-16 10:02 
AnswerRe: Problem with custom row in List View Pin
Andy_Bell26-Aug-16 10:50
Andy_Bell26-Aug-16 10:50 
SuggestionRe: Problem with custom row in List View Pin
David Crow26-Aug-16 15:29
David Crow26-Aug-16 15:29 
QuestionHow download picture Pin
Andy_Bell25-Aug-16 12:21
Andy_Bell25-Aug-16 12:21 
AnswerRe: How download picture Pin
Richard MacCutchan25-Aug-16 20:45
mveRichard MacCutchan25-Aug-16 20:45 
GeneralRe: How download picture Pin
Andy_Bell25-Aug-16 23:25
Andy_Bell25-Aug-16 23:25 
GeneralRe: How download picture Pin
Richard MacCutchan26-Aug-16 0:02
mveRichard MacCutchan26-Aug-16 0:02 
GeneralRe: How download picture Pin
Andy_Bell26-Aug-16 3:35
Andy_Bell26-Aug-16 3:35 
GeneralRe: How download picture Pin
Richard MacCutchan26-Aug-16 3:45
mveRichard MacCutchan26-Aug-16 3:45 
GeneralRe: How download picture Pin
Andy_Bell26-Aug-16 4:35
Andy_Bell26-Aug-16 4:35 
GeneralRe: How download picture Pin
Richard MacCutchan26-Aug-16 4:40
mveRichard MacCutchan26-Aug-16 4:40 
GeneralRe: How download picture Pin
Andy_Bell26-Aug-16 5:12
Andy_Bell26-Aug-16 5:12 
SuggestionRe: How download picture Pin
David Crow26-Aug-16 7:03
David Crow26-Aug-16 7:03 
Questionandroid: Using Global Multidimensional array variable in CustomView Pin
Member 984019022-Aug-16 18:32
Member 984019022-Aug-16 18:32 
AnswerRe: android: Using Global Multidimensional array variable in CustomView Pin
Richard MacCutchan22-Aug-16 22:12
mveRichard MacCutchan22-Aug-16 22:12 
PraiseRe: android: Using Global Multidimensional array variable in CustomView Pin
Member 984019023-Aug-16 17:58
Member 984019023-Aug-16 17:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.