注册应用程序启动时,USB产品连接到PC [英] Register application to launch when USB item is connected to PC

查看:205
本文介绍了注册应用程序启动时,USB产品连接到PC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Android应用程序,我想如果运行的是Android USB项目被连接到PC上自动打开。

I created an Android application I would like to automatically open when USB item running Android gets connected to the PC.

是否可以登记自己的应用程序以处理USB连接?我该怎么办呢?

Is it possible to register my application to handle USB connection? How do I do that?

推荐答案

在你的Manifest.xml,补充一点:

In your Manifest.xml, add this:

<receiver android:name=".BattStatusShow">
    <intent-filter>
        <action android:name="android.intent.action.ums_connected" />
    </intent-filter>
</receiver>

然后让你的电池状态类扩展的BroadcastReceiver ,因为你的清单文件中注册它的USB消息。

Then have your battery status class extend BroadcastReceiver, since your registered it for USB messages in the Manifest file.

public class BattStatusShow extends BroadcastReceiver{ 
  if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_CONNECTED")) {
    //do stuff here, like signal the view of your app it needs to do something
  }
}

您不给什么你的应用程序多的信息,但如果它只是一个电池电量显示的应用程序,编程PC主机应用程序来谈谈你的Andr​​oid应用程序似乎矫枉过正。如果你想要做更多,看看诺基亚PC站的应用程序与诺基亚的交互方式和仿效的行为。

You don't give much information about what your application, but if it is only a battery display application, programming a PC host application to talk to your Android app seems overkill. If you want to do more, look at how the Nokia PC station app interacts with Nokia and emulate the behavior.

这篇关于注册应用程序启动时,USB产品连接到PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆