Merged with Need help in reading an xml file.
What am I doing wrong here?
String stringXmlContent;
try {
stringXmlContent = getEventsFromAnXML(this);
tv.setText(stringXmlContent);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
button1.setOnClickListener(this);
}
private String getEventsFromAnXML(Activity activity)throws XmlPullParserException, IOException
{
StringBuffer stringBuffer = new StringBuffer();
String attVal = null;
String desc;
Resources res = activity.getResources();
XmlResourceParser xrp = res.getXml(R.xml.myxml);
try {
xrp.next();
int eventType = xrp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.START_DOCUMENT)
{
stringBuffer.append(" ");
}
if(eventType == XmlPullParser.START_TAG)
{
if(xrp.getName().equals("Number")){
attVal = xrp.getAttributeValue(0);
}
}
else if(eventType == XmlPullParser.TEXT)
{
if(xrp.getName().equals("Description") && attVal.equals("2")){
stringBuffer.append(" " + xrp.getText());
}
}
}
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return stringBuffer.toString();
Related
public void getData(View view) {
try {
FileInputStream fileInput = openFileInput("user_data.txt");
InputStreamReader reader = new InputStreamReader(fileInput);
BufferedReader buffer = new BufferedReader(reader);
StringBuffer strBuffer = new StringBuffer();
String lines;
while ((lines = buffer.readLine()) != null) {
strBuffer.append(lines); //Вывод имени
}
textView3.setText(strBuffer.toString());
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
public void saveData (View view) {
String user_name = editSave.getText().toString();
try {
FileOutputStream fileOutput = openFileOutput("user_data.txt", MODE_PRIVATE);
fileOutput.write((user_name).getBytes());
fileOutput.close();
textView3.setText(user_name);
Toast.makeText(setting.this, " ", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Hello. I'm just learning. I need user_name to be called from any activity so I can insert it into the code that passes the text, right now I can't do it.
I will now try to explain what I want to get: textView.setText("random text" + user_name + "text random")
I would be very grateful if you could edit my code.
i call below php webservice and get xml response and parse resonse and set it to hashmap.now i want save server response in offline mode .can i save data in offline mode.how plz give me answer.
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
try {
if (response.length() > 0) {
int code = Integer.parseInt(XMLManualParser.getTagValue(Constant.TAG_CODE, response));
if (code == 1) {
spinner.clear();
ArrayList<String> eventlist = XMLManualParser.getMultipleTagList(Constant.TAG_LIST, response);
for (int i = 0; i < eventlist.size(); ++i) {
String responseContent = eventlist.get(i);
HashMap<String, String> hashMap = new HashMap<String, String>();
String title = XMLManualParser.getTagValue(Constant.title, responseContent);
hashMap.put("title", title);
hashMap.put("id", XMLManualParser.getTagValue(Constant.id, responseContent));
hashMap.put("url", XMLManualParser.getTagValue(Constant.url, responseContent));
hashMap.put("balanceurl", XMLManualParser.getTagValue(Constant.balanceurl, responseContent));
spinner.add(hashMap);
}
} else {
Toast.makeText(SettingsEditActivity.this, "no data found", Toast.LENGTH_SHORT).show();
}
CustomSpinnerAdapter customSpinnerAdapter = new CustomSpinnerAdapter(SettingsEditActivity.this, spinner);
settingsBinding.splist.setAdapter(customSpinnerAdapter);
settingsBinding.splist.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
item = parent.getItemAtPosition(position).toString();
// Toast.makeText(parent.getContext(), "Android Custom Spinner Example Output..." + item, Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
You can save your response into a file and get in offline
public static void saveDataSingleItemDetails(Context context,String file, MainListModel data) {
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = context.openFileOutput(file, MODE_PRIVATE);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (NullPointerException e) {
return;
}
ObjectOutputStream objectOutputStream = null;
try {
objectOutputStream = new ObjectOutputStream(fileOutputStream);
} catch (IOException | NullPointerException e) {
e.printStackTrace();
}
try {
if (objectOutputStream != null) {
objectOutputStream.writeObject(data);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (objectOutputStream != null) {
objectOutputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static MainListModel getSinglItemDetails(Context context,String file) {
MainListModel items = null;
FileInputStream fileInputStream = null;
try {
fileInputStream = context.openFileInput(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
return items;
} catch (NullPointerException e) {
return items;
}
ObjectInputStream objectInputStream = null;
try {
objectInputStream = new ObjectInputStream(fileInputStream);
} catch (IOException | NullPointerException e) {
e.printStackTrace();
return items;
}
try {
items = (MainListModel) objectInputStream.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
objectInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return items;
}
I am trying to write and read to a text file name students but I am having all kinds of hassles I am very new to android programming so I am trying this out for the first time. I have looked at code here and there to try and figure out what I am doing wrong but I cant find one specific thing to help, this question has probably been asked a couple of times, so I am sorry for asking it again. Please see my different .xml and .java files below. The actual question is to be able to write data to a textfile and from the main screen click on a textfield which will take you to the edit screen, where you get to edit that specific field and save it to a text file (this however has not been done yet as I am still struggling to figure out why my writing and reading to the textfile is not working, I hope my poor attempt at coding will shed some light on the matter.
Please don't crucify me for my bad coding I am super new to android
/////////////////////////////add screen.java///////////////////////////////
public class AddNew extends Activity {
private static final String newLine = System.getProperty("line.separator");
TextView txtText;
EditText Modules;
EditText Types;
#Override
protected void onCreate(Bundle SavedInstanceState){
super.onCreate(SavedInstanceState);
setContentView(R.layout.add);
txtText = (TextView)findViewById(R.id.textView1);
Modules = (EditText)findViewById(R.id.etMod);
Types = (EditText)findViewById(R.id.etType);
Button backMan = (Button)findViewById(R.id.btnBackMain);
backMan.setOnClickListener(new OnClickListener(){
public void onClick(View v){
//This is where your code will go
startActivity(new Intent(AddNew.this, MainActivity.class));
}
}); //end back Button
//get the day, month & year from the Date picker
DatePicker myDPicker = (DatePicker)findViewById(R.id.dpDate);
Integer Year = myDPicker.getYear();
Integer Month = myDPicker.getMonth();
Integer Day = myDPicker.getDayOfMonth();
StringBuilder sb = new StringBuilder();
sb.append(Year.toString()).append("-").append(Month.toString()).append
("-").append(Day.toString());
final String dobStr=sb.toString();
txtText.setText("TEST");
Button Save = (Button)findViewById(R.id.btnSaveAdded);
Save.setOnClickListener(new OnClickListener(){
public void onClick(View v){
//This is where your code will go
try {
writeToFile(Modules.getText().toString(),
Types.getText().toString(),dobStr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void writeToFile(String Mod, String AsType, String dobDate) throws
IOException {
// TODO Auto-generated method stub
//String textTofile;
StringBuilder sbText = new StringBuilder();
sbText.append(Mod + "," + dobStr + "," + AsType);
//textTofile=sbText.toString();
String fileName = "student";
PrintWriter printWriter = null;
File file = new File(fileName);
try {
if (!file.exists()) file.createNewFile();
printWriter = new PrintWriter(new FileOutputStream(fileName,
true));
printWriter.write(newLine ); //+textTofile);
} catch (IOException ioex) {
ioex.printStackTrace();
} finally {
if (printWriter != null) {
printWriter.flush();
printWriter.close();
}
}
}
}); //end back Button
}
}
`public class MainActivity extends Activity {
TextView fDisplay;
TextView fTest;
int numItems=0; //use it later to keep track of the number of items.
String inText; //use this variable for the information read in from the textfile.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but1=(Button)findViewById(R.id.btnAdd);
but1.setOnClickListener(new OnClickListener(){
public void onClick(View v){
//This is where your code will go
startActivity(new Intent(MainActivity.this, AddNew.class));
}
}); //end but1
Button but2 = (Button)findViewById(R.id.btnEditCur);
but2.setOnClickListener(new OnClickListener(){
public void onClick(View v){
//This is where your code will go
startActivity(new Intent(MainActivity.this, EditCur.class));
}
}); //end of button 2
fDisplay = (TextView)findViewById(R.id.tvAssign1);
try {
readFromFile();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void readFromFile() throws IOException {
// TODO Auto-generated method stub
// String ret="";
BufferedReader br;
FileReader fr = null;
try {
fr = new FileReader("student");
br = new BufferedReader(fr);
String line = br.readLine();
while (null != line) {
fDisplay.append(line);
fDisplay.append("\n");
line = br.readLine();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (null != fr) {
try {
fr.close();
} catch (IOException e) {
// ignore
}
}
}
}
}
`
For writting on a file I have used this
String filename;
String content;
filename = "PATH_AND_FILE";
content = "CONTENT ON THE FILE"
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write(myString.toString());
out.flush();
out.close();
And for reading I have this function:
public static String readFileAsString() {
String result = "";
String filename;
filename = "PATH_AND_FILE";
File file = new File(filename);
if ( file.exists() ) {
FileInputStream fis = null;
try { fis = new FileInputStream(file);
char current;
while (fis.available() > 0) {
current = (char) fis.read();
result = result + String.valueOf(current);
}
} catch (Exception e) {
// System.out.println("DEBUG Exception String :"+ e.toString());
} finally {
if (fis != null)
{ try {
fis.close();
} catch (IOException ignored) {
}}
else {// System.out.println("DEBUG Exception String NULL");
}
}
return result;
}
else
{
return "DEFAULT CONTENT";
}
}
In Android, the file' directory is different then that on a PC, like :the files are stored in a directory related to your App, the accessing permissions are different.
This link might be helpful:
How To Read/Write String From A File In Android
Two simple functions (Java) to read and write:
private static void writeToFile(String path, String text) {
PrintWriter writer;
try {
writer = new PrintWriter(path, "UTF-8");
writer.print(text);
writer.close();
} catch (FileNotFoundException | UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String getFileContent(String filename){
String everything = "";
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(filename));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
StringBuilder sb = new StringBuilder();
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
try {
line = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
everything = sb.toString();
} finally {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return everything;
}
I am doing a validation for fields in an android form.I am checking with server whether the username is available in the server or not.But the main thread goes to the next page before the async checking completes.
The code:
btnnext1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
isallValid=true;
//check second time for username validation(first time was in onfocus changed)
// if(txtusername.getText().toString().trim().equals("achuthan")){
// txtusername.setError("Username exsists!");
// isUsernameValid=false;
// }
//
// else
// {
// isUsernameValid=true;
// }
try {
Void async_result=new validateusername().execute().get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(txtfullname.getText().toString().trim().length()==0)
{
txtfullname.requestFocus();
txtfullname.setError("Field required");
isallValid=false;
}
if(txtdob.getText().toString().trim().length()==0)
{
txtdob.requestFocus();
txtdob.setError("Field required");
isallValid=false;
}
if(txtoccupation.getText().toString().trim().length()==0)
{
txtoccupation.requestFocus();
txtoccupation.setError("Field required");
isallValid=false;
}
if(txtusername.getText().toString().trim().length()<6){
txtusername.requestFocus();
txtusername.setError("Minimum length of 6 characters");
isallValid=false;
}
if(txtpassword.getText().toString().trim().length()==0)
{
txtpassword.requestFocus();
txtpassword.setError("Field required");
isallValid=false;
}
if(txtconfirmpassword.getText().toString().trim().length()==0)
{
txtconfirmpassword.requestFocus();
txtconfirmpassword.setError("Field required");
isallValid=false;
}
else if(!txtpassword.getText().toString().trim().equals(txtconfirmpassword.getText().toString().trim()))
{
//txtconfirmpassword.requestFocus();
txtconfirmpassword.setError("Passwords not equal");
txtpassword.setError("Passwords not equal");
isallValid=false;
}
if(isallValid&&isUsernameValid)
{
//Toast.makeText(getActivity(),"VALID FORM!!",Toast.LENGTH_LONG).show();
((SignUpPage)getActivity()).getValues().fullname=txtfullname.getText().toString().trim();
((SignUpPage)getActivity()).getValues().dob=txtdob.getText().toString().trim();
int id=radiogender.getCheckedRadioButtonId();
RadioButton rb=(RadioButton) view.findViewById(id);
String gender=rb.getText().toString();
((SignUpPage)getActivity()).getValues().gender=gender;
int id1=radiomarital.getCheckedRadioButtonId();
RadioButton rb1=(RadioButton) view.findViewById(id1);
String marital_status=rb1.getText().toString();
((SignUpPage)getActivity()).getValues().marital_status=marital_status;
((SignUpPage)getActivity()).getValues().occupation=txtoccupation.getText().toString().trim();
((SignUpPage)getActivity()).getValues().username=txtusername.getText().toString().trim();
((SignUpPage)getActivity()).getValues().password=txtpassword.getText().toString().trim();
((SignUpPage)getActivity()).selectFragment(1);
}
//if all valid , store values and go to next fragment
//((SignUpPage)getActivity()).selectFragment(1);
}
});
return view;
}
The async class:
public class validateusername extends AsyncTask<String,Void,Void>
{
#Override
protected Void doInBackground(String... arg0) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("username",txtusername.getText().toString().trim()));
try {
httppost.setEntity(new UrlEncodedFormEntity(pairs));
response = httpclient.execute(httppost);
result=responsetostring.getResponseBody(response);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result1) {
try {
jsonobj=new JSONObject(result);
job2=jsonobj.getJSONObject("server_message");
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
finalresult=job2.getString("username_availability_message");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(finalresult.equals("exist")){
txtusername.setError("Username exsists!");
isUsernameValid=false;
}
else if(finalresult.equals("available"))
{
isUsernameValid=true;
}
}
}
I tried using the get method so that the main thread waits till the async class finishes but it didnt work.Please help!!
Check isallValid only in button click , then Do this validation inside your onPostExecute(Void result) method,
if(isUsernameValid)
{
//Toast.makeText(getActivity(),"VALID FORM!!",Toast.LENGTH_LONG).show();
((SignUpPage)getActivity()).getValues().fullname=txtfullname.getText().toString().trim();
((SignUpPage)getActivity()).getValues().dob=txtdob.getText().toString().trim();
int id=radiogender.getCheckedRadioButtonId();
RadioButton rb=(RadioButton) view.findViewById(id);
String gender=rb.getText().toString();
((SignUpPage)getActivity()).getValues().gender=gender;
int id1=radiomarital.getCheckedRadioButtonId();
RadioButton rb1=(RadioButton) view.findViewById(id1);
String marital_status=rb1.getText().toString();
((SignUpPage)getActivity()).getValues().marital_status=marital_status;
((SignUpPage)getActivity()).getValues().occupation=txtoccupation.getText().toString().trim();
((SignUpPage)getActivity()).getValues().username=txtusername.getText().toString().trim();
((SignUpPage)getActivity()).getValues().password=txtpassword.getText().toString().trim();
((SignUpPage)getActivity()).selectFragment(1);
}
now it will work.................
Do not use get() to call the AsyncTask, it hangs your UI.
So call your AsyncTask like,
String userName = txtusername.getText().toString().trim();
new validateusername().execute(userName); // pass the String from EditText, as you cannot interact with UI in doInBackground
Modify your AsyncTask like
public class validateusername extends AsyncTask<String,Void,String>
{
#Override
protected String doInBackground(String... arg0) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("username",arg0[0])); // arg0[0] is the username passed from AsyncTask call
try {
httppost.setEntity(new UrlEncodedFormEntity(pairs));
response = httpclient.execute(httppost);
result=responsetostring.getResponseBody(response);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
#Override
protected void onPostExecute(String result1) {
try {
jsonobj=new JSONObject(result);
job2=jsonobj.getJSONObject("server_message");
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
finalresult=job2.getString("username_availability_message");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(finalresult.equals("exist")){
txtusername.setError("Username exsists!");
isUsernameValid=false;
}
else if(finalresult.equals("available"))
{
isUsernameValid=true;
}
if(txtfullname.getText().toString().trim().length()==0)
{
txtfullname.requestFocus();
txtfullname.setError("Field required");
isallValid=false;
}
if(txtdob.getText().toString().trim().length()==0)
{
txtdob.requestFocus();
txtdob.setError("Field required");
isallValid=false;
}
if(txtoccupation.getText().toString().trim().length()==0)
{
txtoccupation.requestFocus();
txtoccupation.setError("Field required");
isallValid=false;
}
if(txtusername.getText().toString().trim().length()<6){
txtusername.requestFocus();
txtusername.setError("Minimum length of 6 characters");
isallValid=false;
}
if(txtpassword.getText().toString().trim().length()==0)
{
txtpassword.requestFocus();
txtpassword.setError("Field required");
isallValid=false;
}
if(txtconfirmpassword.getText().toString().trim().length()==0)
{
txtconfirmpassword.requestFocus();
txtconfirmpassword.setError("Field required");
isallValid=false;
}
else if(!txtpassword.getText().toString().trim().equals(txtconfirmpassword.getText().toString().trim()))
{
//txtconfirmpassword.requestFocus();
txtconfirmpassword.setError("Passwords not equal");
txtpassword.setError("Passwords not equal");
isallValid=false;
}
if(isallValid&&isUsernameValid)
{
//Toast.makeText(getActivity(),"VALID FORM!!",Toast.LENGTH_LONG).show();
((SignUpPage)getActivity()).getValues().fullname=txtfullname.getText().toString().trim();
((SignUpPage)getActivity()).getValues().dob=txtdob.getText().toString().trim();
int id=radiogender.getCheckedRadioButtonId();
RadioButton rb=(RadioButton) view.findViewById(id);
String gender=rb.getText().toString();
((SignUpPage)getActivity()).getValues().gender=gender;
int id1=radiomarital.getCheckedRadioButtonId();
RadioButton rb1=(RadioButton) view.findViewById(id1);
String marital_status=rb1.getText().toString();
((SignUpPage)getActivity()).getValues().marital_status=marital_status;
((SignUpPage)getActivity()).getValues().occupation=txtoccupation.getText().toString().trim();
((SignUpPage)getActivity()).getValues().username=txtusername.getText().toString().trim();
((SignUpPage)getActivity()).getValues().password=txtpassword.getText().toString().trim();
((SignUpPage)getActivity()).selectFragment(1);
}
}
onPostExecute(), check the conditions and navigate to next activity.
I'm making a app which can send a character ("B") to activate microcontroller then accept the result data from it. The data will be numbers 0-100. However I'm stuck in converting stream data to string.
I've tried the codes in comment but the process ended up being looping forever.
Here is my codes :
public Bluetooth(startover so, Handler handler, ProgressDialog pd) {
// TODO Auto-generated constructor stub
this.handler=handler;
activity=so;
this.pd=pd;
}
#Override
public void run() {
// TODO Auto-generated method stub
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.enable();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
try
{
btSocket =device.createRfcommSocketToServiceRecord(MY_UUID);
//Toast.makeText(this, "Bluetooth_socket is created", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Log.e(TAG, "ON RESUME: Socket creation failed.", e);
}
try
{
btSocket.connect();
Log.e(TAG, "ON RESUME: BT connection established, datatransfer link open.");
//Toast.makeText(this, "Bluetooth_socket is connected", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
try
{
btSocket.close();
}
catch (IOException e2)
{
Log.e(TAG, "ON RESUME: Unable to close socket during connection failure", e2);
}
}
message = "B";
sendMessage(message);
InputStream mInput=null;
try {
mInput = btSocket.getInputStream();
System.out.println("Input Open");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(!Thread.currentThread().isInterrupted() && mBluetoothAdapter.isEnabled()) {
try {
int bytesAvailable = mInput.available();
if(bytesAvailable > 0) {
System.out.println("Pesan Diterima");
BufferedReader r = new BufferedReader(new InputStreamReader(mInput));
StringBuilder total = new StringBuilder(bytesAvailable);
String line;
//BACA LEBIH DARI 1 KARAKTER
//while ((line = r.readLine()) != null) {
// total.append(line);
//}
final String message=total.toString();
handler.post(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
pd.dismiss();
System.out.println("Turn "+message);
activity.startActivity(new Intent(activity.getApplicationContext(),result.class).putExtra("data", message));
}
});
break;
}
}
catch (IOException ex) {
}
}
super.run();
}
private void sendMessage (String message) {
byte[] send = message.getBytes();
try {
OutputStream OutStream = btSocket.getOutputStream();
OutStream.write(send);
System.out.println("Send "+message);
}
catch (IOException e) {
Log.e(TAG, "Exception during write", e);
}
}
}