導航:首頁 > APP軟體 > 安卓Wifi開發源碼

安卓Wifi開發源碼

發布時間:2025-09-10 19:56:07

⑴ 求助如何在基於安卓通過wifi與Arino通信,實現對LED燈的控制。

項目需要的硬體如下:

Arino Uno
Ethernet Shield
LED燈 2個.
電阻 2個.
麵包板(可選)
連接導線
路由器一個
項目要的連接管腳如下:
LED 1 --> pin 6 to ground
LED 2 --> pin 7 to ground
項目需要的軟體如下:
Eclipse IDE
Arino IDE 1.x.x
LED 1 --> pin 6 to ground
LED 2 --> pin 7 to ground

項目需要的軟體如下:

Eclipse IDE
Arino IDE 1.x.x

Step 1: 在 Arino上編程如下:#include "etherShield.h"
#include "ETHER_28J60.h"

int led2 = 7;
int led1 = 6;

static uint8_t mac[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xBB, 0xAA}; // this just needs to be unique for your network,
// so unless you have more than one of these boards
// connected, you should be fine with this value.

static uint8_t ip[4] = {192, 168, 0, 15}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.
static uint16_t port = 80; // Use port 80 - the standard for HTTP

ETHER_28J60 e;

void setup()
{
e.setup(mac, ip, port);

pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);

digitalWrite(led1, LOW);
digitalWrite(led2, LOW);

}

void loop()
{
char* params;
if (params = e.serviceRequest())
{
if (strcmp(params, "?cmd=1") == 0)
{
digitalWrite(led1, HIGH);
}
if (strcmp(params, "?cmd=2") == 0)
{
digitalWrite(led1, LOW);

}
if (strcmp(params, "?cmd=3") == 0)
{
digitalWrite(led2, HIGH);
}
if (strcmp(params, "?cmd=4") == 0)
{
digitalWrite(led2, LOW);

}

e.respond();
}
}
Step 2: 製作安卓APP

package com.androidarino;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {

StrictMode.ThreadPolicy policy = new StrictMode.
ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

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

View led1on = findViewById(R.id.led_1on);
View led1off = findViewById(R.id.led_1off);
View led2on = findViewById(R.id.led_2on);
View led2off = findViewById(R.id.led_2off);

led1on.setOnClickListener(this);
led1off.setOnClickListener(this);
led2on.setOnClickListener(this);
led2off.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

public void commandArino(String url){
try {
HttpClient httpclient = new DefaultHttpClient();
httpclient.execute(new HttpGet(url));
} catch (Exception e) {
}
}

public void onClick(View thisView) {
switch(thisView.getId()){
case R.id.led_1on:
commandArino("http://192.168.0.15/?cmd=1");
Toast.makeText(getApplicationContext(), "led_1on",Toast.LENGTH_LONG).show();
break;
case R.id.led_1off:
commandArino("http://192.168.0.15/?cmd=2");
Toast.makeText(getApplicationContext(), "led_1off",Toast.LENGTH_LONG).show();
break;
case R.id.led_2on:
commandArino("http://192.168.0.15/?cmd=3");
Toast.makeText(getApplicationContext(), "led_2on",Toast.LENGTH_LONG).show();
break;
case R.id.led_2off:
commandArino("http://192.168.0.15/?cmd=4");
Toast.makeText(getApplicationContext(), "led_2off",Toast.LENGTH_LONG).show();
break;

}

}

}

⑵ Android開發如何使用代碼配置手機wifi的pac地址

這里用到的手機型號為魅族M6120,其中的具體步驟如下:

1、打開手機的設置界面,需要選擇無線網路這一項。

⑶ 怎麼在eclipse中查看android源碼

在eclipse中查看android源代碼的兩種方法
方法一:
一名java開發工程師經常會查看庫的源代碼,因為我們用ADT發現android庫沒有自帶source code,我就創建一個user library來解決這個問題的。
1、首先你需要下載android源代碼,用git,詳見android開發官方網站
然後找到源碼目錄下的\frameworks\base\core\java,把android壓縮成android.zip把下面這些文件夾拖入到裡面(結構android.zip\)\frameworks\base\graphics\java\android\
\frameworks\base\location\java\android\
\frameworks\base\media\java\android\
\frameworks\base\opengl\java\android\
\frameworks\base\sax\java\android\
\frameworks\base\telephony\java\android\
\frameworks\base\services\java\com\android\\frameworks\base\vpn\java\android\
\frameworks\base\wifi\java\android\
2、在你的android工程上,右鍵->屬性,找到Java Build Path3、Add Library->User Library->Next->User Libraries->New4、輸入Library的名稱,比如android_src2.0
5、Add JARs->選擇剛剛創建的android.zip
這樣你就把android源碼添加上了。
方法二:
上面的方法我試了一下1.6的就是不行,只有2.0的才行,所以用網上搜索到的一種方法,添加1.6SDK的源代碼。
from __future__ import with_statement# for Python < 2.6import os
import re
import zipfile
# open a zip file
DST_FILE = 'sources.zip'
if os.path.exists(DST_FILE):
print DST_FILE, "already exists"
exit(1)
zip = zipfile.ZipFile(DST_FILE, 'w', zipfile.ZIP_DEFLATED)# some files are plicated, them only oncewritten = {}
# iterate over all Java files
for dir, subdirs, files in os.walk('.'):
for file in files:
if file.endswith('.java'):
# search package name
path = os.path.join(dir, file)
with open(path) as f:
for line in f:
match = re.match(r'\s*package\s+([a-zA-Z0-9\._]+);', line)if match:
# source into the zip file using the package as pathzippath = match.group(1).replace('.', '/') + '/' + fileif zippath not in written:
written[zippath] = 1
zip.write(path, zippath)
break;
zip.close()
把這些代碼拷貝一下,新建一個叫 makesrc.py的文件,放到< 源碼位置>/frameworks/base下面,然後執行makesrc.py,完畢之後會有sources.zip然後在platforms\android-1.6\sources 下面解壓到這個目錄具體目錄格式是\platforms\android-2.1\sources\
android
com
java
javax
junit
mock_android
org

閱讀全文

與安卓Wifi開發源碼相關的資料

熱點內容
三明市學編程去哪裡 瀏覽:410
幾百個數據如何整理分類出柱狀圖 瀏覽:171
網路精靈下載 瀏覽:943
家庭組網電視電腦網路機頂盒 瀏覽:165
pdf文件瘦身綠色軟體 瀏覽:319
wdsmartware忘記密碼 瀏覽:665
蘋果5手機有紅外線嗎 瀏覽:721
oracle觸發器兩個資料庫 瀏覽:979
ps能打開1小時前的文件 瀏覽:47
mc未發現任何版本的java 瀏覽:39
word2003修改圖片尺寸 瀏覽:258
mac的系統文件在哪裡 瀏覽:684
金蝶帳套備份後有兩個文件嗎 瀏覽:6
安卓Wifi開發源碼 瀏覽:961
java動態腳本 瀏覽:823
無法使用文件 瀏覽:946
手機哪個編程軟體好 瀏覽:573
代碼注釋清楚工具 瀏覽:442
站點主頁的文件名是什麼 瀏覽:853
網路編程外包怎麼考 瀏覽:499

友情鏈接