MSN和ICQ在国内渐渐的没落,QQ和新浪微博开始在国内大放异彩。也许会有人有QQ强迫症,自己不想登录QQ,又想知道某个好友现在是不是在登录QQ,或者某些情况下,被昔日的好友拉进了黑名单,但又牵挂不下,想看看老情人是不是在QQ上泡MM或者泡GG,这时就需要QQ在线探测软件了,其实技术原理并不复杂。就是通过WEB技术查看对方QQ头像颜色的,彩色在线,黑白不在线或者隐身,以前其实不加QQ也能聊天的,可惜因为容易造成骚扰恐慌,马大爷把这个通信端口关闭了,所以现在也就只能看看是不是在线了。
原理很简单,废话也不说了,公布代码。创建一个名叫QQ的工程。在activity_main.xml文件里添加一个ImageView控件,当然你也可以在代码里动态创建,如果你觉得那样很酷的话。如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imgview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</RelativeLayout>
在AndroidManifest.xml里添加一个声明访问网络权限的代码,如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qq"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.qq.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在MainActivity.java文件里添加实现代码,首先添加
public class MainActivity extends Activity {
//这里修改QQ号码
String urlString = "http://wpa.qq.com/pa?p=1:93825549:7";
private ImageView imageView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//jia add,show
imageView = (ImageView) findViewById(R.id.imgview);
try {
imageView.setImageBitmap(returnBitMap(urlString));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
//这里是读取QQ在线状态的图片
private Bitmap returnBitMap(String url) throws IOException {
Bitmap bm = null;
URL myFileUrl = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream in = conn.getInputStream();
bm = BitmapFactory.decodeStream(in);
in.close();
return bm;
}
}
有注释,不多解释了,编绎运行就行,转载请注明出处。