[android-developers] How i connect from android to another cellphone with (DUN or PAN)?

2013-02-12 Thread Antonis Kanaris
 
   
I create a simple bluetooth terminal for android and i want to connect with 
other cellphone not android support uuid=1115(PAN) with personal area 
networkand share internet connection to android.How i do this?I know 
for (DUN) is AT+CGDCONT=1,"IP","APN"...and after dial with ATD*99***1# What 
is the procedure for PAN?I connected with my PC and BlueSoleil with 
cellphone share internet to pc...I test it again with DUN bluetooth 
service...

 AT+CGDCONT=1,"IP","MYAPN"
 REPLY OK

 ATD*99***1#
 REPLY CONNECT

After what can i do?I can use url from my terminal?How i keep my 
application to backgroung and open my browser for use internet? 

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[android-developers] problem samsung android.graphics.Bitmap.createScaledBitmap

2013-01-22 Thread Antonis Kanaris
Hello i create an application with camera and resize the photo 640x480.In 
my smartphone android sony ericsson work but no work Samsung Galaxy 
Tablet.I have this error 

java.lang.NullPointerException
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:432)
at power.web.camera.WebCam2$2$1.run(WebCam2.java:202)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)

How i fix it?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How do I fix error open Bluetooth?

2013-01-16 Thread Antonis Kanaris
 
  
I created an application with bluetooth, but when bluetooth is closed i put 
enable request for open bt but apk crashing,close after show toast request 
for user and must restart the apk and I have this error... *
java.lang.NullPointerException* in *io.webbt.Activity2.openBT.Any idea?I 
must use OnResume OnActivityResult?How i fix it?*

*  public class Activity2 extends Activity {

public String strValue;
public String strValue2;
public String strUrlup;

public String strValued ="http://";;
public String strValue2d ="HC-07";
public String strValue3d="";
 
public String data="0";//Temperature (data from arduino)

public boolean killMe = false;

TextView temptext,txt,myLabel,text,text2,text3,text4; 
  
Handler handler = new Handler();

BluetoothAdapter mBluetoothAdapter;
BluetoothSocket mmSocket;
BluetoothDevice mmDevice;
OutputStream mmOutputStream;
InputStream mmInputStream;

Thread workerThread;
byte[] readBuffer;
int readBufferPosition;
int counter;
volatile boolean stopWorker;
boolean work = true;
private static final int REQUEST_ENABLE_BT = 1;
public long refreshtime = 3;//replay download/upload time 30 secs

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
 
myLabel = (TextView)findViewById(R.id.label);
temptext = (TextView)findViewById(R.id.temptxt);

SharedPreferences preferences = getSharedPreferences("dataioweb" , 
MODE_PRIVATE);

   strValue = preferences.getString("Url",strValued);
  text = (TextView) findViewById(R.id.txt1);
  text.setText(strValue);
   strValue2 = preferences.getString("DevName",strValue2d);
  text2 = (TextView) findViewById(R.id.txt2);  
  text2.setText(strValue2); 
   strUrlup = preferences.getString("Urlup",strValue3d);   
  text4 = (TextView) findViewById(R.id.txt4);  
  text4.setText(strUrlup); 
  
  //findBT();
}

private class DownloadWebPageTask extends AsyncTask {
@Override
protected String doInBackground(String... urls) {
  String response = "";
  for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }

} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
}

@Override
protected void onPostExecute(String result) {
TextView text3 = (TextView) findViewById(R.id.txt3);
text3.setText(result);
try {
sendData(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
  }

   

protected void onStart() {
super.onStart();

try
{ 
findBT();
openBT();
}
catch (IOException ex) { }

runnable.run();

  }

protected void onResume() {
super.onResume();

   

   }

  private Runnable runnable = new Runnable()
  {
  
  public void run()
  {
  if(killMe)
  return;
  DownloadWebPageTask task = new DownloadWebPageTask();
  task.execute(new String[] { strValue });//Download data on/off
  
  beginListenForData();//Listen Bluetooth temperature
  
  SimpleHttpPut task2 = new SimpleHttpPut();
task2.execute(new String[] { strUrlup,data });//Upload data 
class

  handler.postDelayed(this, refreshtime);//Refresh page time
  }
  };
  
  void findBT() 
  {
  mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  if(mBluetoothAdapter == null)
  {
  myLabel.setText("No bluetooth adapter available");
  }
 
  if(!mBluetoothAdapter.isEnabled())
  {
  
  Intent enableBluetooth = new 
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  startActivityForResult(enableBluetooth, REQUEST_ENABLE_BT);

  //mBluetoothAdapter.enable();
  
  
  }
 
  Set pairedDevices = 
mBluetoothAdapter.getBondedDevices();
  if(p

[android-developers] How i pass downloaddata to my main activity?

2013-01-14 Thread Antonis Kanaris
 
 Hello.I have an downloadservice.class for download data and i call it from 
main activity inside onCreate.How i pass download data to main activity for 
display as text?

  public class DownloadService extends IntentService {

public String response;

  public DownloadService() {
super("DownloadService");
  }

  // Will be called asynchronously be Android
  @Override
  protected void onHandleIntent(Intent intent) {

//String urldown = intent.getStringExtra("url");
String urldown="http://mplampla.net/LEDstate.txt";;
  
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urldown);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }
  
  //Arduwebled instance = new Arduwebled();
  //instance.test(response);
  
 // while (mOutputStream  != null) {
  //mOutputStream.write(buffer);
 //   }
  
} catch (IOException e) {
  e.printStackTrace();
}
   // Arduwebled instance = new Arduwebled();
   // instance.test(response);   
  }
  
  // Sucessful finished
}

public class Arduwebled extends Activity {

TextView text;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup);

sendBroadcast(new Intent(this,MyScheduleReceiver.class));

}


public void test(String response){
TextView text = (TextView) findViewById(R.id.downdata);
text.setText(response);
}

public void StopRepeat(View view) {

sendBroadcast(new Intent(this,MyStopReceiver.class));

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Help for stop service with Alarm Manager

2013-01-13 Thread Antonis Kanaris
 
 

I have created the start alarm as shown below

 public class MyScheduleReceiver extends BroadcastReceiver {

   // Restart service every 30 secondsprivate static final long REPEAT_TIME = 
1000 * 5;
@Overridepublic void onReceive(Context context, Intent intent) {
  AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
 Intent i = new Intent(context, MyStartServiceReceiver.class);
 PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 5);
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), REPEAT_TIME, pending);

I crate this for stop alarm and i call it from main activity.Manifest i 
think is ok...Work repeat but no stop!!!

  public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup);

sendBroadcast(new Intent(this,MyScheduleReceiver.class));
}
public void StopRepeat(View view) {

sendBroadcast(new Intent(this,MyStopReceiver.class));   
}

 public class MyStartServiceReceiver extends BroadcastReceiver {


 public void onReceive(Context context, Intent intent) {

  Toast.makeText(context, "Repeat service!.",
   Toast.LENGTH_LONG).show();
}

  public class MyStopReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 5;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent istop = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, istop,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 5);

  service.cancel(pending);

But the service is not stopping. What might be the issue?Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] I can not choice in eclipse Qvga 240x320

2013-01-08 Thread Antonis Kanaris
 
   
I can not choice in eclipse Qvga 240x320 2.7 for small layout.Graphical 
layout no work...I have message Exception raised during rendering: Index: 
1, Size: 1 Exception details are logged in Window > Show View > Error 
Log

Why? How i fix it? Avd manager is ok.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Problem upload location with service and broadcast receiver

2013-01-05 Thread Antonis Kanaris

  Hello.I try upload location with service and broadcast receiver...but no 
worki have make for battery level and workmanifest is okthis is 
my code.


  private void buttonGetLocationClick() {
getCurrentLocation(); // gets the current location and update 
mobileLocation variable

if (mobileLocation != null) {
locManager.removeUpdates(locListener); // This needs to stop 
getting the location data and save the battery power.

 londitude = "Londitude: " + mobileLocation.getLongitude();
 latitude = "Latitude: " + mobileLocation.getLatitude();
 altitiude = "Altitiude: " + mobileLocation.getAltitude();
String accuracy = "Accuracy: " + mobileLocation.getAccuracy();
String time = "Time: " + mobileLocation.getTime();

editTextShowLocation.setText(londitude + "\n" + latitude + "\n"
+ altitiude + "\n" + accuracy + "\n" + time);

Intent intent = new Intent(this, MyBroadcastReceiver.class);
intent.putExtra("lat",latitude);
intent.putExtra("lon",londitude);


} else {
editTextShowLocation.setText("Sorry, location is not 
determined");
}
}

public class MyBroadcastReceiver extends BroadcastReceiver { 

@Override
  
  public void onReceive(Context context, Intent intent) {

String latitude=intent.getStringExtra("lat");
String londitude=intent.getStringExtra("lon");

String strUrlup="http://www.x.net/location.php";;

Intent service = new Intent(context, UploadService.class);

service.putExtra("url", strUrlup );   
service.putExtra("lats","30");
service.putExtra("lons",londitude);

context.startService(service);


}



} 

  public class UploadService extends IntentService {

  public UploadService() {
super("UploadService");
  }

  // Will be called asynchronously be Android
  @Override
  protected void onHandleIntent(Intent intent) {

String urlup = intent.getStringExtra("url");

String lat1 = intent.getStringExtra("lats");
String lon1 = intent.getStringExtra("lons"); 

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlup);
try {
  List nameValuePairs = new 
ArrayList(2);
  nameValuePairs.add(new BasicNameValuePair("lat","30"));
  nameValuePairs.add(new BasicNameValuePair("lon",lon1));
  
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
  HttpResponse response = client.execute(post);
  BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
  String line = "";
  while ((line = rd.readLine()) != null) {
System.out.println(line);
  }

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

  }
  // Sucessful finished
}



-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How i upload my battery level data to my web server with service?

2013-01-02 Thread Antonis Kanaris
How i upload my battery level data to my web server with service?I try this 
code but no work...any help?What is wrong?

 

public class BatteryLevel extends Activity {

private TextView contentTxt;

String strUrlup ="http://bat_android.php";
String textbat;

  private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(final Context context, Intent intent) {
  // TODO Auto-generated method stub
  int level = intent.getIntExtra("level", 0);
  contentTxt.setText(String.valueOf(level) + "%");

   textbat = String.valueOf(level) + "%";

Toast.makeText(context, textbat, Toast.LENGTH_SHORT).show();

Intent service = new Intent(context, UploadService.class);
service.putExtra("url", strUrlup);
service.putExtra("batlevel",textbat); 
context.startService(service);
};


  @Override
  public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
contentTxt = (TextView) this.findViewById(R.id.txt);
this.registerReceiver(this.mBatInfoReceiver, 
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  }
 }

public class UploadService extends IntentService {

  private int result = Activity.RESULT_CANCELED;

  public UploadService() {
super("UploadService");
  }

  // Will be called asynchronously be Android
  @Override
  protected void onHandleIntent(Intent intent) {

String url = intent.getStringExtra("url");

String bat=intent.getStringExtra("batlevel");

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
try {
  List nameValuePairs = new 
ArrayList(1);
  nameValuePairs.add(new BasicNameValuePair("bat_and_lev",bat));
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
  HttpResponse response = client.execute(post);
  BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
  String line = "";
  while ((line = rd.readLine()) != null) {
System.out.println(line);
  }

} catch (IOException e) {
  e.printStackTrace();
}
//return null;


  }
  // Sucessful finished
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How i remove my old apk and publish update on google play market?

2012-12-27 Thread Antonis Kanaris
   
   
How i remove my old apk and publish update on google play market?I publish 
my apk but i put something extra to my code...I make unpublish...but how i 
delete the old and upload new?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How i send data from intent service to Main activity?

2012-12-23 Thread Antonis Kanaris
Hello.I make an intent service for download data and store to a string.How 
i pass the data (string s inside my code) to main activity?

  i try this code...

  

public class DownloadService extends IntentService {
private int result = Activity.RESULT_CANCELED;public String s = "";
public DownloadService() {super("DownloadService");}
// Will be called asynchronously be Android@Overrideprotected void 
onHandleIntent(Intent intent) {Uri data = intent.getData();String urlPath = 
intent.getStringExtra("urlpath");
InputStream stream = null;//FileOutputStream fos = null;try {

  URL url = new URL(urlPath);
  stream = url.openConnection().getInputStream();
  InputStreamReader reader = new InputStreamReader(stream);
  //fos = new FileOutputStream(output.getPath());
  int next = -1;

  while ((next = reader.read()) != -1) {
//fos.write(next);
s=s+next;
  }
  // Sucessful finished
  result = Activity.RESULT_OK;

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Problem exit,close my application...

2012-12-19 Thread Antonis Kanaris

I make an application download data from web send to bluetooth,listen 
bluetooth and upload to web with loopbut when push button close my apk 
freeze...no work...


/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
 
//txt=(TextView)findViewById(R.id.txt);
myLabel = (TextView)findViewById(R.id.label);
temptext = (TextView)findViewById(R.id.temptxt);

SharedPreferences preferences = getSharedPreferences("dataioweb" , 
MODE_PRIVATE);

   strValue = preferences.getString("Url","");
  TextView text = (TextView) findViewById(R.id.txt1);
  text.setText(strValue);
   strValue2 = preferences.getString("DevName","");
  TextView text2 = (TextView) findViewById(R.id.txt2);  
  text2.setText(strValue2);
  
  
 
}

private class DownloadWebPageTask extends AsyncTask {
@Override
protected String doInBackground(String... urls) {
  String response = "";
  for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }

} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
}

@Override
protected void onPostExecute(String result) {
TextView text3 = (TextView) findViewById(R.id.txt3);
text3.setText(result);
try {
sendData(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
  }

   

protected void onStart() {
super.onStart();

try
{ 
findBT();
openBT();
}
catch (IOException ex) { }

runnable.run();
 
  }

  private Runnable runnable = new Runnable()
  {

  public void run()
  {
 
  DownloadWebPageTask task = new DownloadWebPageTask();
  task.execute(new String[] { strValue });//Download data on/off
  
  beginListenForData();//Listen Bluetooth temperature
  
  SimpleHttpPut task2 = new SimpleHttpPut();
task2.execute(new String[] { urlt,data });//Upload data 
class

if(work){  handler.postDelayed(this, 3);}//Refresh page time
  }
  };
  
  void findBT()
  {
  mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  if(mBluetoothAdapter == null)
  {
  myLabel.setText("No bluetooth adapter available");
  }
 
  if(!mBluetoothAdapter.isEnabled())
  {
  //mBluetoothAdapter.enable();
  Intent enableBluetooth = new 
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  startActivityForResult(enableBluetooth, 0);
  
  
  }
 
  Set pairedDevices = 
mBluetoothAdapter.getBondedDevices();
  if(pairedDevices.size() > 0)
  {
  for(BluetoothDevice device : pairedDevices)
  {
  if(device.getName().equals(strValue2))
  {
  mmDevice = device;
  break;
  }
  }
  }
  myLabel.setText("Bluetooth Device Found");
  }
 
  void openBT() throws IOException
  {
  UUID uuid = UUID.fromString("1101--1000-8000-00805f9b34fb"); 
//Standard SerialPortService ID
  mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);   
  mmSocket.connect();
  mmOutputStream = mmSocket.getOutputStream();
  mmInputStream = mmSocket.getInputStream();
 
 // beginListenForData();
 
  myLabel.setText("Bluetooth Opened");
  }
 
  void sendData(String msg) throws IOException
  {
 
  msg += "\n";
  mmOutputStream.write(msg.getBytes());
  myLabel.setText("Data Sent");
  }
 
  void beginListenForData()
  {
  final Handler handler = new Handler(); 
  final byte delimiter = 10; //This is the ASCII code for a newline 
character
  
  stopWorker = false;
  readBufferPosition = 0;
  readBuffer = new byte[1024];
  workerThread = new Thread(new Runnable()
  {
  public void run()
  {
 while(!Thread.currentThread().isInterrupted() && !stopWorker)

[android-developers] How i convert upload code to AsyncTask?

2012-12-18 Thread Antonis Kanaris
   
 How i convert this class code with AsyncTask method?

public class SimpleHttpPut {
public static void main(String urlt,int t) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlt);
try {
  List nameValuePairs = new 
ArrayList(1);
  nameValuePairs.add(new 
BasicNameValuePair("temp",String.valueOf(t)));
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
  HttpResponse response = client.execute(post);
  BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
  String line = "";
  while ((line = rd.readLine()) != null) {
System.out.println(line);
  }

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

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How i getting a value out of the function?

2012-12-18 Thread Antonis Kanaris

I try it but no work...

>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How i getting a value out of the function?

2012-12-18 Thread Antonis Kanaris

 Hello.I make an apk for listen bluetooth and i want to get value data from 
function ListenBt() to pass to another function upload().I make public 
final string data but no work!Any help?

   public class Activity2 extends Activity {

public String strValue;
public String strValue2;

public int t;//Temperature
public String urlt;
public final String data="0";

TextView txt;
   
Handler handler = new Handler();
   
TextView myLabel;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
 
//txt=(TextView)findViewById(R.id.txt);
myLabel = (TextView)findViewById(R.id.label);  
 
}

private class DownloadWebPageTask extends AsyncTask {
@Override
protected String doInBackground(String... urls) {
  String response = "";
  for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }

} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
}

@Override
protected void onPostExecute(String result) {
TextView text3 = (TextView) findViewById(R.id.txt3);
text3.setText(result);
try {
sendData(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
  }

public void readWebpage(View view) {
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { strValue });

  }

protected void onStart() {
super.onStart();
try
{
  
findBT();
openBT();

}
catch (IOException ex) { }
runnable.run();
 
  }

  private Runnable runnable = new Runnable()
  {

  public void run()
  {
 
  DownloadWebPageTask task = new DownloadWebPageTask();
  task.execute(new String[] { strValue });
  beginListenForData();
  upload();

if(work){  handler.postDelayed(this, 3);}//Refresh page time
  }
  };
  
  void ListenBt()
  {
  final Handler handler = new Handler(); 
  final byte delimiter = 10; //This is the ASCII code for a newline 
character
  
  stopWorker = false;
  readBufferPosition = 0;
  readBuffer = new byte[1024];
  workerThread = new Thread(new Runnable()
  {
  public void run()
  {
 while(!Thread.currentThread().isInterrupted() && !stopWorker)
 {
  try 
  {
  int bytesAvailable = 
mmInputStream.available();
  if(bytesAvailable > 0)
  {
  byte[] packetBytes = new byte[bytesAvailable];
  mmInputStream.read(packetBytes);
  for(int i=0;ihttp://groups.google.com/group/android-developers?hl=en

[android-developers] How will combine download and then upload in a loop?

2012-12-18 Thread Antonis Kanaris
 

I make an Android application for download a variable from my webserver 
(use AsyncTask) and then send it to bluetooth.I make it with loop 
(handler,postdelayed).I make a receive function from bluetooth and display 
the insert new data temperature.I know how i upload i make a class and work 
in another apk.How combine download and upload together?I test it but no 
work...Need close inputstream,outputstream first?

 public void run()
  {

  DownloadWebPageTask task = new DownloadWebPageTask();
  task.execute(new String[] { strValue });
  beginListenForData();//Receive data from bluetooth
 // upload();//My problem is there

if(work){  handler.postDelayed(this, 3);}//Refresh page time
  }
 };

 public void upload(){

//t = Integer.parseInt(data);
SimpleHttpPut.main(urlt,t);//Upload data class  
  } 

 public class SimpleHttpPut {
public static void main(String urlt,int t) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlt);
try {
  List nameValuePairs = new ArrayList(1);
  nameValuePairs.add(new BasicNameValuePair("temp",String.valueOf(t)));
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

  HttpResponse response = client.execute(post);
  BufferedReader rd = newBufferedReader(new 
   InputStreamReader(response.getEntity().getContent()));
  String line = "";
  while ((line = rd.readLine()) != null) {
System.out.println(line);
  }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How i call class into my activity?

2012-12-17 Thread Antonis Kanaris
Hello i find this class for upload data...but how i call it from my 
Activity?On create...

  public class SimpleHttpPut {
public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.power7.net/temp.php";);
try {
  List nameValuePairs = new 
ArrayList(1);
  nameValuePairs.add(new BasicNameValuePair("temp","30"));
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
  HttpResponse response = client.execute(post);
  BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
  String line = "";
  while ((line = rd.readLine()) != null) {
System.out.println(line);
  }

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

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How use and call AsyncTask into my code for upload data?

2012-12-17 Thread Antonis Kanaris
How use and call AsyncTask into my code for upload data?

  

List nameValuePairs = new ArrayList(2);  //you 
should put here your temp variable
nameValuePairs.add(new BasicNameValuePair("temperature", String.valueOf(30)));
HttpPost request = post("http://mysite.com/temperature.php";, nameValuePairs);
DefaultHttpClient client = generateHttpClient();HttpResponse httpResponse = 
client.execute(request);

Where:

public static DefaultHttpClient generateHttpClient(){
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_CONNECTION);
HttpConnectionParams.setSoTimeout(params, TIMEOUT_SOCKET);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 
PlainSocketFactory.getSocketFactory(), 80));

try{

KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);

SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
sf.setHostnameVerifier(
   SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sf, 443));
}catch (Exception e) {
e.printStackTrace();
}
//  params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, 
HttpVersion.HTTP_1_1);
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, 
registry);
DefaultHttpClient client = new DefaultHttpClient(cm, params);
client.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() { 
@Override 
public long getKeepAliveDuration(HttpResponse response, HttpContext 
context) { 
return 60; // seconds 
} 

}); 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How to upload to a webserver simple integer variable from android?

2012-12-17 Thread Antonis Kanaris
 How to upload to my webserver a simple integer variable from android?I 
want send the temperature variable.My server support php.Need permisions 
from webserver?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] problem display all data sharedpreference

2012-12-14 Thread Antonis Kanaris

 I save data url,device name but when call getstring display only device 
name...this is my functionfor one string work ok

  public void Save(View view) {

 SharedPreferences preferences = 
getSharedPreferences("dataioweb.txt" , MODE_PRIVATE);
  SharedPreferences.Editor editor = preferences.edit();  // Put the 
values from the UI
  EditText txtUrl = (EditText)findViewById(R.id.txtUrl);
  String strUrl = txtUrl.getText().toString();
  
  EditText txtDevName = (EditText)findViewById(R.id.txtDevName);
  String strDevName = txtDevName.getText().toString();
  
  //CheckBox chkTandC = (CheckBox)findViewById(R.id.chkTandC);
  //boolean blnTandC = chkTandC.isChecked();
  
  editor.putString("Url", strUrl); // value to store
  editor.putString("DevName", strDevName); // value to store
  //editor.putBoolean("TandC", blnTandC); // value to store
  // Commit to storage
  editor.commit();

  String strValue = preferences.getString("Url","");
  TextView text = (TextView) findViewById(R.id.text);  
  text.setText(strValue);
  String strValue2 = preferences.getString("DevName","");
  TextView text2 = (TextView) findViewById(R.id.textDevName);  
  text.setText(strValue2);

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: SharedPreferences no work

2012-12-14 Thread Antonis Kanaris


Τη Παρασκευή, 14 Δεκεμβρίου 2012 9:15:12 π.μ. UTC+2, ο χρήστης Antonis 
Kanaris έγραψε:
>
> Hello.I make an apk with two activities and use SharedPreferences for 
> store user values but no workthe string url no store this is my 
> code...Need something extra to manifest for work SharedPreferences?
>
> public class MainActivity extends Activity {
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_main);
> 
>
>
> if (savedInstanceState != null)
> {
>   String strValue = savedInstanceState.getString("Url");
>   if (strValue != null)
>   {
>   TextView text = (TextView) findViewById(R.id.text);
>   
>   //Sets the new text to TextView (runtime click event)
>   text.setText(strValue);
>   }
> }
> 
> }
> 
> public void Save(View view) {
> 
>  SharedPreferences preferences = getPreferences(MODE_PRIVATE);
>   SharedPreferences.Editor editor = preferences.edit();  // Put 
> the values from the UI
>   
>   EditText txtUrl = (EditText)findViewById(R.id.txtUrl);
>   String strUrl = txtUrl.getText().toString();
>   
>   
>   
>   editor.putString("Url", strUrl); // value to store
> 
>   // Commit to storage
>   editor.commit();
> 
> Intent myIntent = new Intent(view.getContext(), Activity2.class);
> startActivityForResult(myIntent, 0);
> }
>
>
> public class Activity2 extends Activity {
>
> /** Called when the activity is first created. */
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity2);
>
> if (savedInstanceState != null)
> {
>   String strValue = savedInstanceState.getString("Url");
>   if (strValue != null)
>   {
>   TextView text = (TextView) findViewById(R.id.texturl);
>   
>   //Sets the new text to TextView (runtime click event)
>   text.setText(strValue);
>   }
> }
>  
> }
> 
> public void Setup(View view) {
> Intent intent = new Intent();
> setResult(RESULT_OK, intent);
> finish();
> }
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] SharedPreferences no work

2012-12-13 Thread Antonis Kanaris
Hello.I make an apk with two activities and use SharedPreferences for store 
user values but no workthis is my code...Need something extra to 
manifest for work SharedPreferences?

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

   

if (savedInstanceState != null)
{
  String strValue = savedInstanceState.getString("Url");
  if (strValue != null)
  {
  TextView text = (TextView) findViewById(R.id.text);
  
  //Sets the new text to TextView (runtime click event)
  text.setText(strValue);
  }
}

}

public void Save(View view) {

 SharedPreferences preferences = getPreferences(MODE_PRIVATE);
  SharedPreferences.Editor editor = preferences.edit();  // Put the 
values from the UI
  
  EditText txtUrl = (EditText)findViewById(R.id.txtUrl);
  String strUrl = txtUrl.getText().toString();
  
  
  
  editor.putString("Url", strUrl); // value to store

  // Commit to storage
  editor.commit();

Intent myIntent = new Intent(view.getContext(), Activity2.class);
startActivityForResult(myIntent, 0);
}


public class Activity2 extends Activity {

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);

if (savedInstanceState != null)
{
  String strValue = savedInstanceState.getString("Url");
  if (strValue != null)
  {
  TextView text = (TextView) findViewById(R.id.texturl);
  
  //Sets the new text to TextView (runtime click event)
  text.setText(strValue);
  }
}
 
}

public void Setup(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How stop alarm manager problem call cancel

2012-12-11 Thread Antonis Kanaris

 I make an application download file repeat with alarm manager and my 
problem is how i call alarmmanager.cancel() with button on click for stop 
it.My code is...

   protected void onCreate(Bundle savedInstanceState) {
super.onCreate(
savedInstanceState);
setContentView(R.layout.activity_main);

sendBroadcast(new Intent(this,MyScheduleReceiver.class));//Start 
Repeat 

}

public void stop(){

//How i call cancel alarmmanager?
  
}



public class MyScheduleReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 30;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);
//
// Fetch every 30 seconds
// InexactRepeating allows Android to optimize the energy consumption
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), REPEAT_TIME, pending);

// service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
// REPEAT_TIME, pending);

  }
} 

public class MyStartServiceReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

  Toast.makeText(context, "Download repeat!",
   Toast.LENGTH_LONG).show();
  
  Intent service = new Intent(context, DownloadService.class);
//Messenger messenger = new Messenger(handler);
//intent.putExtra("MESSENGER", messenger);

service.setData(Uri.parse("http://www.mpla.net/LEDstate.txt
"));
service.putExtra("urlpath", 
"http://www.mpla.net/LEDstate.txt");   

context.startService(service);
  }
} 

public class MyStopReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 30;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);

service.cancel( pending);

  }
} 
   

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How stop alarm manager and call cancel

2012-12-11 Thread Antonis Kanaris

 I make an application download file repeat with alarm manager and my 
problem is how i call alarmmanager.cancel() with button on click for stop 
it.My code is...

   protected void onCreate(Bundle savedInstanceState) {
super.onCreate(
savedInstanceState);
setContentView(R.layout.activity_main);

sendBroadcast(new Intent(this,MyScheduleReceiver.class));//Start 
Repeat 

}

public void stop(){

//How i call cancel alarmmanager?
  
}



public class MyScheduleReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 30;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);
//
// Fetch every 30 seconds
// InexactRepeating allows Android to optimize the energy consumption
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), REPEAT_TIME, pending);

// service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
// REPEAT_TIME, pending);

  }
} 

public class MyStartServiceReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

  Toast.makeText(context, "Download repeat!",
   Toast.LENGTH_LONG).show();
  
  Intent service = new Intent(context, DownloadService.class);
//Messenger messenger = new Messenger(handler);
//intent.putExtra("MESSENGER", messenger);
service.setData(Uri.parse("http://www.power7.net/LEDstate.txt";));
service.putExtra("urlpath", "http://www.power7.net/LEDstate.txt";);   
context.startService(service);
  }
} 

public class MyStopReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 30;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);

service.cancel( pending);

  }
} 
   

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Problem stop repeat alarmmanager.

2012-12-11 Thread Antonis Kanaris

 I make an application download file repeat with alarm manager and my 
problem is how i call alarmmanager.cancel() with button on click for stop 
it.My code is...

   protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sendBroadcast(new Intent(this,MyScheduleReceiver.class));//Start 
Repeat 

}

public void stop(){

//How i call cancel alarmmanager?
  
}



public class MyScheduleReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 30;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);
//
// Fetch every 30 seconds
// InexactRepeating allows Android to optimize the energy consumption
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), REPEAT_TIME, pending);

// service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
// REPEAT_TIME, pending);

  }
} 

public class MyStartServiceReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

  Toast.makeText(context, "Download repeat!",
   Toast.LENGTH_LONG).show();
  
  Intent service = new Intent(context, DownloadService.class);
//Messenger messenger = new Messenger(handler);
//intent.putExtra("MESSENGER", messenger);
service.setData(Uri.parse("http://www.power7.net/LEDstate.txt";));
service.putExtra("urlpath", "http://www.power7.net/LEDstate.txt";);   
context.startService(service);
  }
} 

public class MyStopReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 30;

  @Override
  public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);

service.cancel( pending);

  }
} 
   

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Read file convert bytes

2012-12-10 Thread Antonis Kanaris

Hello.I have a simple file.txt with only data the 1 but when put 
if(value=="1") no work why?

File sdcard = Environment.getExternalStorageDirectory();

//Get the text file
File file = new File(sdcard,"LEDstate.txt");

byte[] byteArray = new byte[(int) file.length()];
try {
new FileInputStream(file).read(byteArray);
} catch (Exception e) {
e.printStackTrace();
}

String value = new String(byteArray);

 if(value=="1"){
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.txt);

//Set the text
tv.setText(value);
//}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Problem read data from file out to usb

2012-12-09 Thread Antonis Kanaris

 I try this but work only for text no out the dataAny help?

   public void blinkLED(View v){
 
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"

String line = null;
File sdcard = Environment.getExternalStorageDirectory();

//Get the text file
File file = new File(sdcard,"LEDstate.txt");

//Read text from file
StringBuilder text = new StringBuilder();

try {
BufferedReader br = new BufferedReader(new FileReader(file));
//String line;

while ((line = br.readLine()) != null) {

//mOutputStream.write(line.getBytes());

text.append(line);

text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}

//Find the view by its id
TextView tv = (TextView)findViewById(R.id.textView2);

//Set the text
tv.setText(text);

if (mOutputStream != null) {
try {
mOutputStream.write(text.getBytes());
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e(TAG, "write failed", e);
}
}

I think the wrong is when convert text to byte...my file is 1 byte 0 or 
1

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Download web data out to usb automate repeat

2012-12-08 Thread Antonis Kanaris

 I make this service for download file.How convert code for output data to 
usb+arduino?

  public class DownloadService extends IntentService {

  private int result = Activity.RESULT_CANCELED;

  public DownloadService() {
super("DownloadService");
  }

  // Will be called asynchronously be Android
  @Override
  protected void onHandleIntent(Intent intent) {
Uri data = intent.getData();
String urlPath = intent.getStringExtra("urlpath");
String fileName = data.getLastPathSegment();
File output = new File(Environment.getExternalStorageDirectory(),
fileName);
if (output.exists()) {
  output.delete();
}

InputStream stream = null;
FileOutputStream fos = null;
try {

  URL url = new URL(urlPath);
  stream = url.openConnection().getInputStream();
  InputStreamReader reader = new InputStreamReader(stream);
  
  fos = new FileOutputStream(output.getPath());
  int next = -1;
  while ((next = reader.read()) != -1) {
fos.write(next);
  }
  // Sucessful finished
  result = Activity.RESULT_OK;

i call this intentservice every 30 secs with broadcast receiver and alarm 
manager...

i find this for usb

  private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbAccessory accessory = 
UsbManager.getAccessory(intent);
if (intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
openAccessory(accessory);
} else {
Log.d(TAG, "permission denied for accessory "
+ accessory);
}
mPermissionRequestPending = false;
}
} else if 
(UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) {
UsbAccessory accessory = UsbManager.getAccessory(intent);
if (accessory != null && accessory.equals(mAccessory)) {
closeAccessory();
}
}
}
};
 
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 
mUsbManager = UsbManager.getInstance(this);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new 
Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
registerReceiver(mUsbReceiver, filter);
 
if (getLastNonConfigurationInstance() != null) {
mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
openAccessory(mAccessory);
}
 
setContentView(R.layout.main);
buttonLED = (ToggleButton) findViewById(R.id.toggleButtonLED);
 
}
 
@Override
public Object onRetainNonConfigurationInstance() {
if (mAccessory != null) {
return mAccessory;
} else {
return super.onRetainNonConfigurationInstance();
}
}
 
@Override
public void onResume() {
super.onResume();
 
if (mInputStream != null && mOutputStream != null) {
return;
}
 
UsbAccessory[] accessories = mUsbManager.getAccessoryList();
UsbAccessory accessory = (accessories == null ? null : 
accessories[0]);
if (accessory != null) {
if (mUsbManager.hasPermission(accessory)) {
openAccessory(accessory);
} else {
synchronized (mUsbReceiver) {
if (!mPermissionRequestPending) {

mUsbManager.requestPermission(accessory,mPermissionIntent);
mPermissionRequestPending = true;
}
}
}
} else {
Log.d(TAG, "mAccessory is null");
}
}
 
private void openAccessory(UsbAccessory accessory) {
mFileDescriptor = mUsbManager.openAccessory(accessory);
if (mFileDescriptor != null) {
mAccessory = accessory;
FileDescriptor fd = mFileDescriptor.getFileDescriptor();
mInputStream = new FileInputStream(fd);
mOutputStream = new FileOutputStream(fd);
Log.d(TAG, "accessory opened");
} else {
Log.d(TAG, "accessory open fail");
}
}
 
private void closeAccessory() {
try {
if (mFileDescriptor != null) {
mFileDescriptor.close();
}
} catch (IOException e) {
} finally {
mFileDescriptor = null;
mAccessory = null;
}
}
 
public void blinkLED(View v){
 
byte[] buffer

[android-developers] How i call IntentService from Broadcast Receiver?

2012-12-07 Thread Antonis Kanaris

  
  
I make an intent service for download data and i want to repeat with 
broadcast receive and alarm manager.How i call my intent service?I try this 
but no work

public class AlarmActivity extends Activity {

@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
public void startAlert(View view) {

EditText text = (EditText) findViewById(R.id.time);

int i = Integer.parseInt(text.getText().toString());

Intent intent = new Intent(this, MyBroadcastReceiver.class);

PendingIntent pendingIntent = 
PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

//alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
   // + (i * 1000),pendingIntent);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
System.currentTimeMillis()
 ,(i*1000),pendingIntent);

   // alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar
//  .getTimeInMillis(), intervals, pendingIntent);


Toast.makeText(this, "Alarm set in " + i + " seconds",
Toast.LENGTH_LONG).show();
  }




public class MyBroadcastReceiver extends BroadcastReceiver {


@Override

  public void onReceive(Context context, Intent intent) {

  Toast.makeText(context, "Don't panik but your time is up.",
Toast.LENGTH_LONG).show();
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator)   
context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500);

 Intent newIntent = new Intent(context, DownloadService.class)
 newIntent.setData(Uri.parse("http://www.mysite.net/LEDstate.txt";));
 newIntent.putExtra("urlpath", "http://www.mysite.net/LEDstate.txt";);


 context.startService(newIntent);
}
i use downloadservice from vogella IntentService tutorialand i want to 
convert it for repeat automate service...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Android get web data and output to usb

2012-12-06 Thread Antonis Kanaris

 I want to make an application to get web data and out to usb every x 
secs.I make it for output to bluetooth.For get web data i use AsyncTask and 
timer for repeat.I found this for usb 
http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/How
 i combine Broadcast receiver alarmmanager for repeat task and out data 
to usb?Need AsyncTask , broadcast , service for work perfect?Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Android application with usb host shield 2.0 and arduino problem

2012-12-04 Thread Antonis Kanaris
I try test Usb host shield 2.0+Arduino duemilanove with example 
ArduinoBlinkLED sketch from Usb host shield 2.0 Library.I upload it in my 
arduino board and after upload to my android cell phone(4.0.4) this 
application 
http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/
 
I
 upload the application to my phone but when push button for on led 
...stop and exit.Any help for this?I use external power supply.Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Problem get data web sent bluetooth

2012-11-26 Thread Antonis Kanaris
Hello.I try this code 

package com.example.timer1;
;

public class ReadWebArduino1 extends Activity {

TextView txt;

Handler handler = new Handler();


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt=(TextView)findViewById(R.id.txt);
myLabel = (TextView)findViewById(R.id.label);
}

private class DownloadWebPageTask extends AsyncTask {
@Override
protected String doInBackground(String... urls) {
  String response = "";
  for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }

} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
}

@Override
protected void onPostExecute(String result) {
  txt.setText(result);
}
  }

  public void readWebpage(View view) {
 
  DownloadWebPageTask task = new DownloadWebPageTask();
  task.execute(new String[] { "http://www.site.net/LEDstate.txt"; });
  
 }


protected void onStart() {
  super.onStart();
runnable.run();
}

private Runnable runnable = new Runnable() 
{

public void run() 
{

DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://www.site.net/LEDstate.txt"; 
});
try 
{
findBT();
openBT();
sendData();
}
catch (IOException ex) { }

handler.postDelayed(this, 1);//Refresh page time is 10secs
}
};

void findBT()
{
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter == null)
{
myLabel.setText("No bluetooth adapter available");
}

if(!mBluetoothAdapter.isEnabled())
{
Intent enableBluetooth = new 
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBluetooth, 0);
}

Set pairedDevices = 
mBluetoothAdapter.getBondedDevices();
if(pairedDevices.size() > 0)
{
for(BluetoothDevice device : pairedDevices)
{
if(device.getName().equals("HC-07")) 
{
mmDevice = device;
break;
}
}
}
myLabel.setText("Bluetooth Device Found");
}

void openBT() throws IOException
{
UUID uuid = 
UUID.fromString("1101--1000-8000-00805f9b34fb"); //Standard 
SerialPortService ID
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mmSocket.connect();
mmOutputStream = mmSocket.getOutputStream();
//mmInputStream = mmSocket.getInputStream();

   // beginListenForData();

myLabel.setText("Bluetooth Opened");
}

void sendData() throws IOException
{
//String msg = myTextbox.getText().toString();
String msg="H";
msg += "\n";
mmOutputStream.write(msg.getBytes());
myLabel.setText("Data Sent");
}


}

my problem is bt data no loop(work only the first time) and how sent the 
web data to msg variable for out to bt.Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Auto refresh data from webserver to activity

2012-11-23 Thread Antonis Kanaris


Τη Παρασκευή, 23 Νοεμβρίου 2012 2:06:11 μ.μ. UTC+2, ο χρήστης Paul-Peter 
Tournaris έγραψε:
>
> You should try to use an AlarmManager isntead and create a Broadcast 
> Receiver to update the data when the Alarm is fired
>
>  

>
>>  Please send me a link with a good tutorial for convert my code with 
>> AlarmManager?
>>
>   Paul-Peter Tournaris your email? 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-23 Thread Antonis Kanaris


ok i look it betterthanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-23 Thread Antonis Kanaris
How i can use this 
http://stackoverflow.com/questions/5822161/refreshing-the-activity inside 
my code with AsyncTask for update activity?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-23 Thread Antonis Kanaris


Τη Παρασκευή, 23 Νοεμβρίου 2012 10:38:57 π.μ. UTC+2, ο χρήστης skink έγραψε:
>
>
>
> Antonis Kanaris wrote: 
> > i use this code for call function refreshRunable from button layout... 
> > 
> >   > android:id="@+id/button1" 
> > android:layout_width="wrap_content" 
> > android:layout_height="wrap_content" 
> > android:layout_alignRight="@+id/textView1" 
> > android:layout_below="@+id/textView1" 
> > android:layout_marginTop="57dp" 
> > android:onClick="refreshRunable" 
> > android:text="Button Refresh automatically" /> 
>
>
> http://stackoverflow.com/questions/4153517/how-exactly-does-the-androidonclick-xml-attribute-differ-from-setonclicklistene
>  
>
> pskink 
>

ok need extra codebut why work for the first button  
onclick:"readWebpage" without Listener?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-23 Thread Antonis Kanaris

I have this message on editor main.java ...> The value of the field 
ReadWebpageAsyncTask.refreshRunnable is not used

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-23 Thread Antonis Kanaris

i use this code for call function refreshRunable from button layout...

 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-22 Thread Antonis Kanaris


I use Android:onClick"void" for call from layout main activity...is 
ok?or wrong method?

 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Auto refresh data from webserver to activity

2012-11-22 Thread Antonis Kanaris


Τη Παρασκευή, 23 Νοεμβρίου 2012 8:38:22 π.μ. UTC+2, ο χρήστης Antonis 
Kanaris έγραψε:
>
>
>
>   
>  Hello.I want to make an application for get web data every x secs i try 
> this code but no work...where is the mistake?Thanks.
>
>  public class ReadWebpageAsyncTask extends Activity {
>  private TextView textView;
>
>  private final Handler handler = new Handler();
>
>  @Override
>  public void onCreate(Bundle savedInstanceState) {
>  super.onCreate(savedInstanceState);
>  setContentView(R.layout.activity_read_webpage_async_task);
>  textView = (TextView) findViewById(R.id.textView1);
>  }
>
> private class DownloadWebPageTask extends AsyncTask {
> @Override
> protected String doInBackground(String... urls) {
>   String response = "";
>
>  .
> } catch (Exception e) {
>   e.printStackTrace();
> }
>   }
>   return response;
>  }
>
> @Override
> protected void onPostExecute(String result) {
>   textView.setText(result);
> }
> }
>
>  public void readWebpage(View view) {
>
>   DownloadWebPageTask task = new DownloadWebPageTask();
>   task.execute(new String[] { "http://www.mysite.net/LEDstate.txt"; });
>
>  }
>
>  private final Runnable refreshRunnable = new Runnable() {
>   public void run() {
>
>  DownloadWebPageTask task = new DownloadWebPageTask();
>  task.execute(new String[] { "http://www.mysite.net/LEDstate.txt"; });
>  //new RefreshTask(param1, param2).execute();
>  long TIME_DELAY= 3000;
> handler.postDelayed(refreshRunnable, TIME_DELAY);
>  }
> };
>  
>
>  In main activity i have one text and two buttons the first button on 
> click call readwebpage and work and the second button call refreshRunable 
> and no work... i call refreshRunable with onClick
>
 
 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Auto refresh data from webserver to activity

2012-11-22 Thread Antonis Kanaris


  
 Hello.I want to make an application for get web data every x secs i try 
this code but no work...where is the mistake?Thanks.

 public class ReadWebpageAsyncTask extends Activity {
 private TextView textView;

 private final Handler handler = new Handler();

 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_read_webpage_async_task);
 textView = (TextView) findViewById(R.id.textView1);
 }

private class DownloadWebPageTask extends AsyncTask {
@Override
protected String doInBackground(String... urls) {
  String response = "";

 .
} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
 }

@Override
protected void onPostExecute(String result) {
  textView.setText(result);
}
}

 public void readWebpage(View view) {

  DownloadWebPageTask task = new DownloadWebPageTask();
  task.execute(new String[] { "http://www.mysite.net/LEDstate.txt"; });

 }

 private final Runnable refreshRunnable = new Runnable() {
  public void run() {

 DownloadWebPageTask task = new DownloadWebPageTask();
 task.execute(new String[] { "http://www.mysite.net/LEDstate.txt"; });
 //new RefreshTask(param1, param2).execute();
 long TIME_DELAY= 3000;
handler.postDelayed(refreshRunnable, TIME_DELAY);
 }
};
 

 In main activity i have one text and two buttons the first button on click 
call readwebpage and work and the second button call refreshRunable and no 
work...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] problem with timer and AsyncTask error....

2012-11-22 Thread Antonis Kanaris
Hello.I try this code for get data from mywebsite every x secsbut i 
have a syntax error on token.Why?

public class ReadWebpageAsyncTask extends Activity {
  private TextView textView;

  
/** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView01);
  }

  private class DownloadWebPageTask extends AsyncTask 
{
@Override
protected String doInBackground(String... urls) {
  String response = "";
  for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }

} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
}

@Override
protected void onPostExecute(String result) {
  textView.setText(result);
}
  }

  public void readWebpage(View view) {
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://www.mysite.net/LEDstate.txt"; });

  }
//}

Timer timer = new Timer();
TimerTask task = new TimerTask(){

@Override
public void run() {
new DownloadWebPageTask().execute(new String[] { 
"http://www.mysite.net/LEDstate.txt"; });
}

};
long whenToStart = 20*1000L; // 20 seconds
long howOften = 20*1000L; // 20 seconds



timer.scheduleAtFixedRate( task , whenToStart , howOften );//Syntax error 
on token "(",delete this token
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Automate update every x secs get data from myUrl

2012-11-21 Thread Antonis Kanaris
Hello.I am new developer android and i want to make an application read 
data from my webserver and control my arduino board...
I start with this example .for get data...ok work but only when click 
buttoni want to convert to automatic update.How i make this?.

public class ReadWebpageAsyncTask extends Activity {
  private TextView textView;

  
/** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_webpage_async_task);
textView = (TextView) findViewById(R.id.textView1);
  }

  private class DownloadWebPageTask extends AsyncTask 
{
@Override
protected String doInBackground(String... urls) {
  String response = "";
  for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new 
InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
response += s;
  }

} catch (Exception e) {
  e.printStackTrace();
}
  }
  return response;
}

@Override
protected void onPostExecute(String result) {
  textView.setText(result);
}
  }

  public void readWebpage(View view) {
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://www.mysite.net/LEDstate.txt"; });

  }
} 


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Get data from the web on android with AsyncTask

2012-11-21 Thread Antonis Kanaris
I am new developer and i want a good simple and analytical example for get 
data from my website.net/ledstate.txt with AsyncTaski try without 
asynctask and no workthis code...with permissions internet



 public class GetDataWeb extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {

try{

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_data_web);

TextView t = (TextView)findViewById(R.id.netResult);

try{

HttpClient httpclient = new DefaultHttpClient();   

HttpPost httppost = new HttpPost("http://www.mysite.net/LEDstate.txt";);

HttpResponse response = httpclient.execute(httppost);

HttpEntity entity = response.getEntity();

InputStream webs = entity.getContent();

  try{

  BufferedReader reader = new BufferedReader(new 
InputStreamReader(webs,"iso 8859-1"),8);

  t.setText(reader.readLine());

  webs.close();

  }catch(Exception e){
  Log.e("log_tag","Error converting result"+e.toString());

  }

}catch(Exception e){
Log.e("log_tag","Error in http connection"+e.toString());
}

thanks...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Get data from the web on android with AsyncTask....

2012-11-21 Thread Antonis Kanaris

 Hello.I am new developer and i want a good simple and analytical 
example for get data from my website.net/ledstate.txt
 with AsyncTaski try without asynctask and no workthis 
code...with permissions internet

public class GetDataWeb extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {

try{

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_data_web);

TextView t = (TextView)findViewById(R.id.netResult);

try{

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new 
HttpPost("http://www.power7.net/LEDstate.txt";);

HttpResponse response = httpclient.execute(httppost);

HttpEntity entity = response.getEntity();

InputStream webs = entity.getContent();

  try{
  
  BufferedReader reader = new BufferedReader(new 
InputStreamReader(webs,"iso 8859-1"),8);
  
  t.setText(reader.readLine());
  
  webs.close();
  
  }catch(Exception e){
  Log.e("log_tag","Error converting result"+e.toString());
  
  }
  
}catch(Exception e){
Log.e("log_tag","Error in http connection"+e.toString());
}
   
}catch(Exception e){
Log.e("ERROR","ERROR IN CODE: "+e.toString());
e.printStackTrace();
}   

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] HttpUrlConnection no print data to my screen

2012-11-20 Thread Antonis Kanaris
  
   
I am new android developer.

I am trying this code for access data from my webserver

@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

URL url;
try {
url = new URL("http://www.mysite.net/LEDstate.txt";);

HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();

InputStream in = urlConnection.getInputStream();

InputStreamReader isw = new InputStreamReader(in);

int data = isw.read();
while (data != -1) {
char current = (char) data;
data = isw.read();
//System.out.print(current);


TextView t = (TextView) findViewById(R.id.ledstate);

t.setText(current); 
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Overridepublic boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;}

}

But data is not appearing on Screen.There is no change in Textview.

I have checked Permissions they are ok.

Any help? Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How can I make my Android a GPRS server to be accessed from the Internet?

2012-11-20 Thread Antonis Kanaris
Hello.I am new android developer and i want to make a simple application to 
acesss byte data from one file into my 
webserver(www.mydomain.com/Ledstate.txt and store to a string.I want out 
the data to bluetooth or to usb for command my arduino board(example on off 
led).I want help.code for this.If i want sent my temp sensor data how i do 
it?Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en