最近在写一个用Socket协议获取后台server的xml数据的程序,
DDMS的Logcat抛出错误:java.net.SocketException: Permission denied
解决方法:
在AndroidMainfest.xml中加入
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
public void fetch_status(){
TelephonyManager tm = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);//
String str = "";
str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
str += "Line1Number = " + tm.getLine1Number() + "\n";
str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
str += "NetworkType = " + tm.getNetworkType() + "\n";
str += "honeType = " + tm.getPhoneType() + "\n";
str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
str += "SimOperator = " + tm.getSimOperator() + "\n";
str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
str += "SimState = " + tm.getSimState() + "\n";
str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
}
//获取手机当前系统的信息
public void getLocalMsg(){
Locale.getDefault().getLanguage();//获取手机的当前系统语言
Locale.getDefault().getCountry();//获取国家代号
}
//獲取手機信息
private void getPhoneInfo(){
String language = getResources().getConfiguration().locale.getCountry();
DisplayMetrics dm = getResources() .getDisplayMetrics();
int w = dm.widthPixels;
int h = dm.heightPixels;
String screen_size = w+"*"+h;
String device = Build.MODEL;//手机型号
String osver = android.os.Build.VERSION.SDK;//手机SDK版本 - level - 4
String relea = android.os.Build.VERSION.RELEASE;//手机SDK版本 1.6
TelephonyManager telephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();//手机IMEI
String mobileno = telephonyManager.getLine1Number();//手机号码
}
Android 2.0 平台,可以用IGoogleLoginService.getAccounts()的得到gmail 帐号,也能用IGoogleLoginService.saveUsernameAndPassword() 把一个已知的gmail帐号和密码设进去。
ItemizedOverlay的在mapview上弹出气泡
首先定义一个overlay extends ItemizedOverlay,例如:
class RestaurantOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items = new ArrayList<OverlayItem>();
private Drawable marker = null;
public RestaurantOverlay(Drawable defaultMarker) {
super(defaultMarker);
this.marker = defaultMarker;
}
//添加OverlayItem对象
public void addOverlay(OverlayItem overlay) {
items.add(overlay);
populate();
}
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected OverlayItem createItem(int i) {
return items.get(i);
}
@Override
public int size() {
return items.size();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
boundCenterBottom(marker);
}
}
其次,获取要加载overlay的mapview句柄,调用mapview.getOverlays()方法,返回一个List<OverLay>对象。
然后,定义自己的overlay,如:RestaurantOverlay me = new RestaurantOverlay(Drawable对象);通过List<Overlay>对象的add(),把自己的Overlay添加上去。但还要为me添加OverlayItem对象,既可以显示图标在地图上。
最后,就是怎么点击标记图标,显示详细信息的泡泡呢?可以通过ItemizedOverlay内部类OnFocusChangeListener的onFocusChanged方法实现。如:
private final ItemizedOverlay.OnFocusChangeListener onFocusChangeListener = new ItemizedOverlay.OnFocusChangeListener() {
public void onFocusChanged(ItemizedOverlay overlay, OverlayItem newFocus) {
if (popView != null) {
popView.setVisibility(View.GONE);
}
if (newFocus != null) {
MapView.LayoutParams geoLP = (MapView.LayoutParams) popView
.getLayoutParams();
geoLP.point = newFocus.getPoint();// 这行用于popView的定位
TextView title = (TextView) popView
.findViewById(R.id.map_bubbleTitle);
title.setText(newFocus.getTitle());
TextView desc = (TextView) popView
.findViewById(R.id.map_bubbleText);
if (newFocus.getSnippet() == null
|| newFocus.getSnippet().length() == 0) {
desc.setVisibility(View.GONE);
} else {
desc.setVisibility(View.VISIBLE);
desc.setText("距离当前位置:"+newFocus.getSnippet()+"公里");
}
citymap.updateViewLayout(popView, geoLP);
popView.setVisibility(View.VISIBLE);
}
}
};
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xiongyingzhuantu/archive/2010/11/15/6011000.aspx
email:javayulong@126.com