- 浏览: 248472 次
- 性别:
- 来自: 济南
文章分类
- 全部博客 (303)
- c (31)
- c++ (16)
- java (18)
- c# (1)
- python (3)
- java web (6)
- oracle (7)
- sqlserver (2)
- mysql (2)
- android (24)
- android系统 (15)
- android多媒体部分 (15)
- android游戏 (12)
- linux (26)
- javaScript (1)
- ajax (1)
- node JS (2)
- html (5)
- apache (3)
- jboss (1)
- weblogic (0)
- 通信协议 (10)
- 云计算 (1)
- 分布式 (5)
- ejb (1)
- webservice (5)
- 设计模式 (16)
- JNI (6)
- swing (13)
- 版本控制 (1)
- UML (1)
- xml (4)
- spring (5)
- hibernate (5)
- struts1 (3)
- struts2 (4)
- ibatis (0)
- tomcat (2)
- 心得体会 (1)
- css (1)
- 嵌入式 (41)
- arm体系结构 (10)
/**
* 测试UPNP协议 显法移动设备
*
* @time 下午12:59:57
* @author zhenhuayue
* @Email zhenhuayue@sina.com
*/
public class UPNP_DempActivity extends ListActivity {
// 设备列表适配器
private ArrayAdapter<DeviceDisplay> deviceAdapter;
private RegistryListener listener = new BrowseRegistryListener();
private AndroidUpnpService upnpService;
private int screenWidth, screenHeight;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
Log.e("tag", "屏幕大小为:" + screenWidth + "*" + screenHeight);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(screenWidth, screenHeight);
deviceAdapter = new ArrayAdapter<DeviceDisplay>(UPNP_DempActivity.this, android.R.layout.simple_list_item_1);
setListAdapter(deviceAdapter);
// 绑定数据
getApplicationContext().bindService(new Intent(this, AndroidUpnpServiceImpl.class), serviceConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onResume() {
super.onResume();
if (null != upnpService) {
upnpService.getRegistry().addListener(listener);
}
showNotification();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (null != upnpService) {
upnpService.getRegistry().removeListener(listener);// 移除监听
}
// 与service解除绑定
getApplicationContext().unbindService(serviceConnection);
// 删除标题栏信息
UPNP_DempActivity.this.stopService(new Intent(UPNP_DempActivity.this, ShowNotificationService.class));
}
/**
* @see 设备档案监听
* @time 下午02:08:51
* @author zhenhuayue
* @Email zhenhuayue@sina.com
*/
class BrowseRegistryListener extends DefaultRegistryListener {
@Override
public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice device) {
Log.e("tag", "开始搜索设备" + device.getDisplayString());
deviceAdded(device);
}
@Override
public void remoteDeviceDiscoveryFailed(Registry registry, final RemoteDevice device, final Exception ex) {
Log.e("tag", "搜索设备失败:" + device.getDisplayString() + "=>" + ex);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(UPNP_DempActivity.this,
"Discovery failed of '" + device.getDisplayString() + "': " + (ex != null ? ex.toString() : "Couldn't retrieve device/service descriptors"),
Toast.LENGTH_LONG).show();
}
});
deviceRemoved(device);
}
@Override
public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
Log.e("tag", "移动设备可见" + device.getDisplayString());
deviceAdded(device);
}
@Override
public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
Log.e("tag", "移动设备更新" + device.getDisplayString());
deviceAdded(device);
}
@Override
public void remoteDeviceRemoved(Registry registry, RemoteDevice device) {
Log.e("tag", "移动设备移除:" + device.getDisplayString());
deviceRemoved(device);
}
@Override
public void localDeviceAdded(Registry registry, LocalDevice device) {
Log.e("tag", "本地设备添加" + device.getDisplayString());
deviceAdded(device);
}
@Override
public void localDeviceRemoved(Registry registry, LocalDevice device) {
Log.e("tag", "本地设备移除" + device.getDisplayString());
deviceRemoved(device);
}
@Override
public void beforeShutdown(Registry registry) {
Log.e("tag", "在关闭之前设备的数量为:" + registry.getDevices().size());
}
@Override
public void afterShutdown() {
Log.e("tag", "开始搜索设备");
}
/**
* 添加设备
*/
@SuppressWarnings("rawtypes")
public void deviceAdded(final Device device) {
runOnUiThread(new Runnable() {
@Override
public void run() {
DeviceDisplay d = new DeviceDisplay(device);
int position = deviceAdapter.getPosition(d);
if (position >= 0) {
deviceAdapter.remove(d);
deviceAdapter.insert(d, position);
} else {
deviceAdapter.add(d);
}
}
});
}
/**
* @see 移除设备
*/
@SuppressWarnings("rawtypes")
public void deviceRemoved(final Device device) {
runOnUiThread(new Runnable() {
public void run() {
deviceAdapter.remove(new DeviceDisplay(device));
}
});
}
}
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
Log.e("tag", "serviceConnection()");
upnpService = (AndroidUpnpService) service;
deviceAdapter.clear();
for (Device device : upnpService.getRegistry().getDevices()) {
((BrowseRegistryListener) listener).deviceAdded(device);
}
upnpService.getRegistry().addListener(listener);
upnpService.getControlPoint().search();
}
public void onServiceDisconnected(ComponentName className) {
upnpService = null;
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 0, 0, R.string.search_lan).setIcon(android.R.drawable.ic_menu_search);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.e("tag", "search1");
if (item.getItemId() == 0 && upnpService != null) {
Log.e("tag", "search2");
upnpService.getRegistry().removeAllRemoteDevices();
upnpService.getControlPoint().search();
}
return false;
}
/************************* 常用方法 ***************************************************/
/**
* 在状态栏(标题栏)显示当前应用信息
*/
private void showNotification() {
Log.e("tag", "showNotification()");
Intent intent = new Intent(UPNP_DempActivity.this, ShowNotificationService.class);
intent.setAction(ShowNotificationService.ACTION);
startService(intent);
}
}
/**
* @see 设备对象
* @time 下午01:49:21
* @author zhenhuayue
* @Email zhenhuayue@sina.com
*/
@SuppressWarnings("rawtypes")
public class DeviceDisplay {
Device device;
public DeviceDisplay(Device device) {
this.device = device;
}
public Device getDevice() {
return device;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
DeviceDisplay that = (DeviceDisplay) o;
return device.equals(that.device);
}
@Override
public int hashCode() {
return device.hashCode();
}
@Override
public String toString() {
return device.isFullyHydrated() ? device.getDisplayString() : device.getDisplayString() + " *";
}
}
/**
* 用于在状态栏(标题栏)显示本应用信息的服务
*
* @time 上午09:55:06
* @author zhenhuayue
* @Email zhenhuayue@sina.com
*/
public class ShowNotificationService extends Service {
public static String ACTION = "cn.yue.upnp.service.ShowNotificationService.SHOWNOTIFICATION";
private NotificationManager manager;
private List<ProcessInfo> processInfos;
/**
*
*/
@Override
public void onCreate() {
Log.e("tag", "showNotificationService is onCreate!");
// 取得消息管理器
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
@Override
public void onStart(Intent intent, int startId) {
Log.e("tag", "showNotificationService onStart()");
if (null != intent && !"".equals(intent)) {
createNotification(intent);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("tag", "showNotificationService onStartCommand()");
createNotification(intent);
return START_STICKY;
}
@Override
public void onDestroy() {
Log.e("tag", "showNotificationService onDestroy()");
manager.cancel(R.string.app_name);
stopForeground(false);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
/**
* 取得当前应用所占内存数
*/
private void getRunningAppProcess() {
// 取得activityManager
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
// 取得所有进程信息
List<RunningAppProcessInfo> runningAppProcessInfos = activityManager.getRunningAppProcesses();
processInfos = new ArrayList<ProcessInfo>();
// 遍历进程信息取得所需内容
for (RunningAppProcessInfo info : runningAppProcessInfos) {
ProcessInfo processInfo = new ProcessInfo();
processInfo.setPid(info.pid);
processInfo.setUid(info.uid);
processInfo.setProcessName(info.processName);
processInfo.setPkName(info.pkgList);
// 取得进程内存
int[] mempid = new int[] { info.pid };
android.os.Debug.MemoryInfo[] memoryInfo = activityManager.getProcessMemoryInfo(mempid);
processInfo.setMemSize(memoryInfo[0].dalvikPrivateDirty);
processInfos.add(processInfo);
}
}
/**
* 新建消息
*/
private void createNotification(Intent intent) {
// TODO 此处需要实时更新
int temp = 0;
String unit = "MB";
getRunningAppProcess();
if (processInfos.size() > 0) {
for (int i = 0; i < processInfos.size(); i++) {
temp += processInfos.get(i).getMemSize();
}
// 如果小于1024就显示kb,否则显示mb
if (temp < 1024) {
unit = "KB";
} else {
temp = temp / 1024;
unit = "MB";
}
}
CharSequence text = getText(R.string.app_name);
Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis());
// 取得当前cpu占用率
// 设置启动对象
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, UPNP_DempActivity.class), 0);
notification.setLatestEventInfo(this, text, "RAM:" + temp + unit + " \t CPU:" + 0 + "%", pendingIntent);
// startForeground(R.string.app_name, notification);
setForeground(true);
manager.notify(R.string.app_name, notification);
}
}
发表评论
-
tcp/ip协议学习笔记
2012-11-11 16:55 738tcp/ip协议栈与数据包封装 osi (open syst ... -
http协议学习笔记
2012-09-04 10:59 550请求行由三部分 请求方式 资源路径 协议 状态行 请求协议 ... -
http协议学习二
2012-09-05 11:23 687请求头: 1.请求行 GET、POST、HEAD、 OPT ... -
udp 学习笔记
2012-09-08 18:04 300public class UdpSend {public st ... -
upnp 学习笔记一
2012-10-18 18:39 847PC端安装 下载workbench调试桥 地址为: h ... -
upnp 学习笔记二
2012-10-19 14:40 3937现在从客户端入手 刚搭的环境eclipse4.2+adt20 ... -
https学习笔记一
2012-10-23 19:41 725http 80 https 443 rsa 非对称128加密 ... -
https 学习笔记二
2012-10-28 11:43 718在apache httpServer布署https协议 修改 ... -
https 学习笔记三
2012-10-28 11:45 603tomcat布署https协议 为tomcat服务器生成一个 ...
相关推荐
关于UPnP协议的框架性介绍,您可以参考《UPnP编程实践》系列的第一篇。UPnP协议的设备发现过程使用简单服务发现协议,此协议实现了在网络中发现网络服务,控制点定位网络上相关资源和设备在网络上声明其可用性的方法...
upnp协议介绍以及相关资料,包含一个pdf文件和一个资料压缩包
UPnP协议编程.pptUPnP协议编程.pptUPnP协议编程.ppt
Upnp协议标准中文版 内涵详细协议保准 与 开发帮助
UPNP协议与架构,以及所有UPNP网关功能、模板文档
基于Linux的UPnP协议栈结构分析及其在嵌入式通信系统中的应用研究.pdf
基于Upnp协议的DMR简易播放器,采用dlna开源库做的简易dmr播放器,可可实现传屏功能
案例分析Upnp协议实现自动端口映射,案例适用,介绍的比较详细
upnp协议中文资料(DLNA)
基于DLNA的UPNP协议的分析及实现,DLNA
UPnP是一种构建于互联网标准技术(如TCP/IP,HTTP,XML等)之上的、用于实现网络设备智能互连以及 ...在简要介绍了基于UPnP协议的基础结构和工作原理的基础上,给出了应用UPnP技术 及其AV架构实现媒体服务器的实例。
本文介绍了UPnP所使用的基本协议(如SSDP、GENA、SOAP等),重点分析了UPnP实现的基本工作流程。然后,论文在剖析了当前最常用的Intel SDK的结构和功能后,以TV控制点和TV设备的开发为例,给出了如何应用该SDK实现...
利用UPnP协议获取路由器IP、网关地址以及在路由器上添删端口映射功能的DLL模块(直接提供接口),可以直接调用接口实现端口映射服务
中文文档,全面详细分析了upnp协议的格式与实现。非常有用,值得参考
基于uPnP协议在DLNA架构中多媒体播放设备DMP的开发
UPnP协议的分析及实现.docUPnP协议的分析及实现.doc
网络游戏-实现基于UPNP协议无线网络路由机制的方法.zip
对于UPnP协议的描述文档。 完整描述了设备发现、服务发现、控制等相关内容
DLNA__Guideline UPnP-arch-DeviceArchitecture-v1.0 UPnP-arch-DeviceArchitecture-v2.0 UPnP-av-AVArchitecture-v1 UPnP-av-AVArchitecture-v2