导航:首页 > 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开发源码相关的资料

热点内容
国行苹果6耳机不兼容 浏览:308
信息老师应该学什么编程语言 浏览:614
凯恩帝系统深孔g74怎么编程序 浏览:226
怎么让电脑里文件显示后缀 浏览:400
pos机和app哪个好用 浏览:545
京东店铺数据更新哪里看 浏览:744
win10放大镜破解密码 浏览:709
三明市学编程去哪里 浏览:410
几百个数据如何整理分类出柱状图 浏览:171
网络精灵下载 浏览:943
家庭组网电视电脑网络机顶盒 浏览:165
pdf文件瘦身绿色软件 浏览:319
wdsmartware忘记密码 浏览:665
苹果5手机有红外线吗 浏览:721
oracle触发器两个数据库 浏览:979
ps能打开1小时前的文件 浏览:47
mc未发现任何版本的java 浏览:39
word2003修改图片尺寸 浏览:258
mac的系统文件在哪里 浏览:684
金蝶帐套备份后有两个文件吗 浏览:6

友情链接