标签归档:android

a question about android manager proxy settings in linux at stackoverflow.com

question:

I am trying to install the Android SDK, in Ubuntu, behind my work firewall and am getting ‘failed to connect to dl-ssl.google.com’ messages. This is a known problem but every solution I see involves proxy settings and selecting the ‘force http’ option. It appears that this is straightforward in windows, however I’d like to know how to do the same in LINUX. I can set the eclipse proxy settings but I don’t think this gets used by the android sdk manager. Is there a config file somewhere?

Thanks in advance.

answer:

question:
I am trying to install the Android SDK, in Ubuntu, behind my work firewall and am getting ‘failed to connect to dl-ssl.google.com’ messages. This is a known problem but every solution I see involves proxy settings and selecting the ‘force http’ option. It appears that this is straightforward in windows, however I’d like to know how to do the same in LINUX. I can set the eclipse proxy settings but I don’t think this gets used by the android sdk manager. Is there a config file somewhere?

Thanks in advance.

answer:
The solution was to setup a local proxy to perform authentication and create the file ~/.android/androidtool.cfg to redirect android to the local proxy as follows.

### Settings for Android Tool
#Tue Jun 12 01:34:55 PDT 2012
http.proxyPort=3128
sdkman.monitor.density=108
http.proxyHost=127.0.0.1
sdkman.show.update.only=true
sdkman.ask.adb.restart=false
sdkman.force.http=true
sdkman.show.updateonly=true

This file may already exist with entries such as

http.proxyPort=
http.proxyHost=127.0.0.1\:8087

For me, this did not work until I changed it to the form shown above:

http.proxyPort=3128
http.proxyHost=127.0.0.1

this question is from http://stackoverflow.com/questions/10634202/android-sdk-manager-proxy-settings-in-linux

android手机变身电脑遥控器—–shutdown your computer

这个想法,早就有了,想给电脑装个遥控器,但是一直没有试过。最近换了android的手机,支持wifi,然后就简单的实现了一个基础功能吧。也就是用手机关掉自己的笔记本。
使用范围:wifi范围内,遥控器装备(android系统,支持网络通信,支持wifi,支持internet),笔记本(安装jdk或者jre吧)

实现分两步,手机端和电脑端。实现思路如下:
笔记本上运行一个socket监听程序,来监听来自外部的连接,如果接受到连接,然后从连接流中读取一行,判断是否是shutdown,如果是,那么执行关机程序。
手机端分为两个部分,一个文本框EditText,一个button,当点击button的时候,读取文本框中的值作为IP,连接到该IP的指定端口,然后写入一行shutdonw。
反应开始,shutdown这一行字符通过局域网的路由器到达电脑端,电脑经过解析判断,然后执行关机程序。

实现的几段基本代码:

监听代码:

ServerSocket server;
try {
   server = new ServerSocket(9995);
   System.out.println("Server Started!");
   while(true){
	Socket client = server.accept();
	InputStream ins = client.getInputStream();
	BufferedReader br = new BufferedReader(new InputStreamReader(ins));
	String tmp = br.readLine();
	System.out.println("Message received!");
	if(tmp.equals("shutDown".toString())) {
	   System.out.println("Hello message!");
	   Main.shutDown();    
	 }
   }} catch (IOException e) {
// TODO Auto-generated catch block
	e.printStackTrace();
}

关机代码:
Main类的shutdown函数:

try {
   Runtime.getRuntime().exec("poweroff -f");
} catch (IOException e) {
// TODO Auto-generated catch block
  e.printStackTrace();
}

注:本段代码的关机命令,只适用于linux系统。关机命令欠妥,容易丢失数据,服务器还是不要这么做了。

andorid连接和发送代码:

try {
   Socket socket = new Socket(m, 9995);
   OutputStream os = socket.getOutputStream();
   PrintStream ps = new PrintStream(os);
   ps.println("shutDown");
   ps.flush();
   ps.close();
  os.close();
  socket.close();
  this.showError("Close successfully!");
} catch (UnknownHostException e) {
  // TODO Auto-generated catch block
  this.showError("当前主机不在线或者已经被你关掉了!");					 
} catch (IOException e) {
  // TODO Auto-generated catch block
  this.showError("当前主机不在线或者已经被你关掉了!");			
}

android需要以下的权限:

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

设置开机启动java程序,然后ps -aux 可以看到如下两行

root      1809  0.0  0.0   2040   188 ?        S    Feb21   0:00 /bin/sh -e /etc/srcs.shell
root      1812  0.0  0.0 732708   684 ?        Sl   Feb21   0:35 java -jar /home/istrone/shutdown.jar

如何实现的开机启动就留给聪明一点儿的人去探索吧!