You can go for HTTP post method...like this
JSONArray jArray;
JSONArray jArray1;
String wifiAddress = null;
String result = null;
InputStream is = null;
StringBuilder sb = null;
Handler handler;
String option1[] = new String[100];
String option2[] = new String[100];
String option3[] = new String[100];
String option4[] = new String[100];
String option5[] = new String[100];
String option6[] = new String[100];
String option7[] = new String[100];
String option8[] = new String[100];
String option9[] = new String[100];
String option10[] = new String[100];
String option11[] = new String[100];
String option12[] = new String[100];
String option13[] = new String[100];
String option14[] = new String[100];
int count, j, ques = 0;
boolean blinkOn = true;
String txt=new String();
int i=0;
String lock="false";
String fileName;
StringBuilder urlserver = new StringBuilder();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);
this.setContentView(sv);
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/Classteacher_Apk/url.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
urlserver.append(line);
//Toast.makeText(getApplication(),urlserver ,
Toast.LENGTH_LONG).show();
}
}
catch (IOException e) {
}
//checkAll();
ScheduledExecutorService scheduler =
Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
Log.i("hello", "world");
runOnUiThread(new Runnable() {
public void run() { try {
WifiManager myWifiManager = (WifiManager)
getSystemService(WIFI_SERVICE);
WifiInfo myWifiInfo =
myWifiManager.getConnectionInfo();
int ipAddress = myWifiInfo.getIpAddress();
wifiAddress =
android.text.format.Formatter.formatIpAddress(ipAddress);
} catch (Exception e) {
Log.e("log_tag", "Error converting result " +
e.toString());
}
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
urlserver+"/ajaxRefresh/"+wifiAddress+".txt");
httppost.setEntity(new
UrlEncodedFormEntity(nameValuePairs));
HttpResponse response =
httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag","Error in http connection"+
e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"),
8);
sb = new StringBuilder();
sb.append(reader.readLine());
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
result = sb.toString();
if(txt.equals(result)==false){
txt=result;
checkAll();
//Toast.makeText(getApplication(), txt,
Toast.LENGTH_LONG).show();
}else{
//Toast.makeText(getApplication(), result,
Toast.LENGTH_LONG).show();
}
}
catch (ParseException e1) {
e1.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
},3,3, TimeUnit.SECONDS);
}
public void checkAll(){
try {
WifiManager myWifiManager = (WifiManager)
getSystemService(WIFI_SERVICE);
WifiInfo myWifiInfo = myWifiManager.getConnectionInfo();
int ipAddress = myWifiInfo.getIpAddress();
wifiAddress =
android.text.format.Formatter.formatIpAddress(ipAddress);
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
if (blinkOn) {
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
try {
HttpClient httpclient = new DefaultHttpClient();
Random ram = new Random();
//HttpPost httppost = new HttpPost(
//"
http://192.168.1.101/Classteacher/getDetails.php?tabid="+ wifiAddress +
"&random="+ ram.nextInt(300));
HttpPost httppost = new HttpPost(
urlserver+"/getDetails.jsp?tabid="+ wifiAddress +
"&random="+ ram.nextInt(300));
httppost.setEntity(new
UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag","Error in http connection"+ e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"),
8);
sb = new StringBuilder();
sb.append(reader.readLine());
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
result = sb.toString();
try {
jArray = new JSONArray(result);
JSONObject json_data = null;
for (int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
option1[i] = json_data.getString("id");
option2[i] = json_data.getString("name");
option3[i] = json_data.getString("tab_id1");
option4[i] = json_data.getString("online1");
option5[i] = json_data.getString("locked1");
//option6[i] = json_data.getString("blankout1");
option7[i] = json_data.getString("bgImageUrl");
option8[i] = json_data.getString("bgImageShowed");
option9[i] = json_data.getString("speakOut");
option10[i] = json_data.getString("cntrl");
option11[i] = json_data.getString("chatOn");
option12[i] = json_data.getString("freeze");
option13[i] = json_data.getString("shutdown");
option14[i]=json_data.getString("pushedContent");
try {
if (option4[i].toString().equals("true")) {
if (option5[i].toString().equals("true")) {
lock="true";
Intent i1=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i1 =
manager.getLaunchIntentForPackage("com.Lock");
i1.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i1);
}
else if(lock.equals("true") &&
option5[i].toString().equals("false")){
Intent i13=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i13 =
manager.getLaunchIntentForPackage("com.Unlock");
i13.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i13);
lock="false";
}
Toast.makeText(getApplication(),
option8[i].toString(), Toast.LENGTH_LONG).show();
if
(option8[i].toString().equals("")||option8[i].toString().equals("true")||
option7[i].toString().equals(null)) {
} else {
Intent i3=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i3 =
manager.getLaunchIntentForPackage("com.Notifier");
i3.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i3);
}
if (option9[i].toString().equals("")||
option7[i].toString().equals(null)) {
} else {
startActivity(new
Intent(Intent.ACTION_VIEW).setData(Uri.parse(option9[i].toString())));
}
if(option10[i].toString().equals("-1")){
Toast.makeText(getApplication(), "You
will be master in next few seconds !!!! ", Toast.LENGTH_LONG).show();
Intent i4=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i4 =
manager.getLaunchIntentForPackage("com.ClassMaster");
i4.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i4);
}else{
}
if(option11[i].toString().equals("true")){
Intent i4=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i4 =
manager.getLaunchIntentForPackage("com.Chat");
i4.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i4);
}else{
}
if(option12[i].toString().equals("true")){
Toast.makeText(getApplication(), "Your
device gon freeze in next few seconds !!!", Toast.LENGTH_LONG).show();
Intent i4=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i4 =
manager.getLaunchIntentForPackage("com.Freeze");
i4.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i4);
}else{
}
if(option13[i].toString().equals("true")){
Toast.makeText(this, "Your device will
turn off now!!", Toast.LENGTH_LONG).show();
Intent i15=new
Intent(Intent.ACTION_MAIN);
PackageManager manager =
getPackageManager();
i15 =
manager.getLaunchIntentForPackage("com.Shutdown");
i15.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i15);
}else{
}
if(option14[i].toString().equals("")){
}else{
down(option14[i].toString());
Toast.makeText(getApplication(),
option14[i].toString(), 600).show();
}
}
}
catch (ParseException e2) {
e2.printStackTrace();
}
}
}
catch (JSONException e1) {
} catch (ParseException e1) {
e1.printStackTrace();
}
} catch (Exception e) {
System.out.println("Exception caught ="
+ e.getMessage());
}
} else {
}
}
private void down(String string) {
// TODO Auto-generated method stub
try{
URL url = new
URL(urlserver+"/upload/upl/"+option14[i].toString());
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH =
Environment.getExternalStorageDirectory().toString()+"/load";
Log.v("LOG_TAG", "PATH: " + PATH);
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file,option14[i].toString());
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
//byte[] buffer = new byte[1024*1024];
byte[] buffer = new byte[4096];
//byte[] buffer = new byte[1024];
int len1 = 0;
// long totalLen = 0;
/* while ( (len1 = is.read(buffer)) > 0 ) {
fos.write(buffer,0, len1);
}
*/
while ((len1 = is.read(buffer)) != -1) {
// totalLen += len1;
// publishProgress(""+(int)((totalLen*100)/lenghtOfFile));
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Toast.makeText(this, " A new file is downloaded successfully",
Toast.LENGTH_LONG).show();
}
catch(IOException e){
e.printStackTrace();
}
}
@Override
public void onBackPressed()
{
Intent intent = new Intent(this, LoginTimer.class);
startActivity(intent);
}
/*AlertDialog.Builder alertDialogBuilder = new
AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Master Control");
alertDialogBuilder.setMessage("You are the master
now").setCancelable(false).setNegativeButton("Yes",new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();*/
}
On Thu, Aug 9, 2012 at 12:07 PM, Meena Rengarajan <[email protected]>wrote:
> How do i wanna send datas to devices using WiFi ? can anyone help me
> please.. Can anyone send videos or sample code ?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> 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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en