1、现在电脑上安装Teamviewer,运行该软件,会生成ID和密码,
如果要每次开机都能远程访问,可以设置无人值守访问,如下图:
2、安卓手机端也安装Teamviewer
3、打开手机端,输入ID和密码就可以直连了,如下图:
android客户端和java服务端之间可以用socket来传输。服务器端代码:
import javaioDataInputStream;
import javaioDataOutputStream;
import javaioFileInputStream;
import javaioIOException;
import javanetInetSocketAddress;
import javanetServerSocket;
import javanetSocket;
public class Server02 {
public static void main(String[] args) {
try {
ServerSocket server = new ServerSocket(40000);
Socket socket = serveraccept();
DataInputStream dos = new DataInputStream(socketgetInputStream());
int len = dosavailable();
Systemoutprintln("len = "+len);
byte[] data = new byte[len];
dosread(data);
Systemoutprintln("data = "+data);
dosclose();
socketclose();
serverclose();
} catch (IOException e) {
eprintStackTrace();
}
}
}
客户端代码:
[java] view plaincopy
imageView02 = (ImageView)findViewById(Ridimage02);
button02 = (Button)findViewById(RidButton02);
button02setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Socket socket;
try {
socket = new Socket("1921681203",40000);
DataOutputStream out = new DataOutputStream(socketgetOutputStream());
Bitmap bitmap = BitmapFactorydecodeResource(getResources(), Rdrawableqt);
imageView02setImageBitmap(bitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//读取到ByteArrayOutputStream
bitmapcompress(BitmapCompressFormatPNG, 100, baos);
byte[] bytes = baostoByteArray();
outwrite(bytes);
Systemoutprintln("bytes--->"+bytes);
outclose();
socketclose();
} catch (UnknownHostException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
}
}
});
}你需要写一个方法,读取网络,在上传 *** 作完成后,调用这个方法,
这个是我经常用的读取网络的方法,你参考一下:
//url为的网络地址,
public static Bitmap getImg(String url)
{
URL imgurl = null;
Bitmap bitmap = null;
try
{
imgurl = new URL(url);
}
catch(MalformedURLException e)
{
eprintStackTrace();
}
try
{
>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)