Android应用程序如何调用外部程序?

发布于 2024-12-03 03:30:07 字数 182 浏览 4 评论 0原文

我找到了它:http://gitorious.org/android-obex/pages/Home

我想从我的 Android 应用程序中调用它,有人知道该怎么做吗?

I've found it: http://gitorious.org/android-obex/pages/Home

I would like to call it from my Android app, does anyone know how to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2024-12-10 03:30:07

您链接的页面上的命令行工具似乎旨在从开发人员手机上可用的根 adb shell 使用,并且可能不使用给定消费者手机上实际可用的蓝牙堆栈版本。使用独立可执行文件也不是“android 方式”。通常,您应该将代码构建到一个库中,以便在应用程序的进程中通过 jni 调用,但如果您需要在可能的设备上以 root 身份运行代码,则必须将其作为单独的进程运行(因为您的应用程序本身无法以 root 身份运行)。

如果您想在 root 设备上使用此代码,请查找有关如何执行 su 命令并将命令行程序的名称和参数通过管道传输到其中的众多 Stack Overflow 答案之一。这将很难工作,不受支持,并且肯定不适用于所有设备。

如果您想以“android 方式”做事,请考虑编写或调整代码,以便将其插入当前的 android 蓝牙 api。这很可能是 java 代码,尽管您可以检查是否有适当的本机 API 或通过 jni 使用本机代码中的 java 代码。

The command line tools on the page you linked appear to be intended for use from the root adb shell available on developer phones, and may not be using a version of the bluetooth stack actually available on a given consumer phone. The use of stand alone executables is also not the "android way". Normally, you should build the code into a library to invoke via jni within your application's process, though if you need to run the code as root on a device where that is possible, then it will have to be run as a separate process (since you app itself cannot run as root).

If you want to play with this code on a rooted device, look for one of the many Stack Overflow answers on how to exec the su command and pipe the name and parameters of a command line program into it. This will be tricky to get working, unsupported, and will definitely not work on all devices.

If you want to do things the "android way" look into writing or adapting code so that it plugs into the current android bluetooth apis. That's likely to be java code, though you can check if there are appropriate native APIs or use the java ones from native code through jni.

猫烠⑼条掵仅有一顆心 2024-12-10 03:30:07

阅读此内容会对您有所帮助:

应用程序的三个核心组件——活动、服务、
和广播接收器 - 通过消息激活,称为
意图。意图消息传递是后期运行时绑定的工具
相同或不同应用程序中的组件之间。

使用意图,您可以启动活动或服务,并且

传递给任何广播方法(例如 Context.sendBroadcast()、Context.sendOrderedBroadcast() 或 Context.sendStickyBroadcast())的 Intent 对象将被传送到所有感兴趣的广播接收者。许多类型的广播源自系统代码。

因此,您需要做的就是确定哪些 Intent 可以接收您想要启动的应用程序,并发送特定的广播 Intent。如果应用程序已安装,它将启动,否则什么也不会发生。

希望有帮助。

It will be useful for you to read this:

Three of the core components of an application — activities, services,
and broadcast receivers — are activated through messages, called
intents. Intent messaging is a facility for late run-time binding
between components in the same or different applications.

Using Intents you can start activity or service, and

Intent objects passed to any of the broadcast methods (such as Context.sendBroadcast(), Context.sendOrderedBroadcast(), or Context.sendStickyBroadcast()) are delivered to all interested broadcast receivers. Many kinds of broadcasts originate in system code.

So everything you need is to determine what Intents can reсeive application you want to start, and to send specific broadcast intent. If application is installed, it will be launched, otherwise nothing will happen.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文