Android,如何在我的应用程序中使用外部 APK? [英] Android, How can I use external APK in my application?

查看:30
本文介绍了Android,如何在我的应用程序中使用外部 APK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个项目.第一个,提取手机信息并显示在屏幕上.我有这个项目的 .apk 文件(例如 test.apk).

I have created two projects. The first one, extracts information of handset and shows on the screen. I have .apk file of this project (for example test.apk).

然后我创建了第二个项目.这个在屏幕上有一个按钮,我想当我点击按钮时,第一个项目运行(显示手机信息).我已通过右键单击项目的根目录>构建路径>配置构建路径>添加外部 JAR>test.apk

Then I created second project. This one has a button on the screen and I want when I click the button, first project runs (shows information of handset). I have added test.apk into this project by right clicking on root of project>Build Path>Configure Build Path>Add External JARs>test.apk

然后在代码中,我使用意图调用了它.这是我的代码:

Then in the code, I called this by using intent. this is my code:

btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("com.in.test.MainActivity"); 
                startActivity(intent);
            }
        });

但是,当我运行应用程序时,根据 logcat,我看到以下错误:11-18 10:09:28.933:E/AndroidRuntime(2237):未捕获的处理程序:线程主因未捕获的异常而退出11-18 10:09:29.022: E/AndroidRuntime(2237): android.content.ActivityNotFoundException: 没有找到处理 Intent { act=com.in.test.MainActivity } 的活动11-18 10:09:29.022: E/AndroidRuntime(2237): 在 android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1484)...

however, when I run the application, according to logcat, I see following error: 11-18 10:09:28.933: E/AndroidRuntime(2237): Uncaught handler: thread main exiting due to uncaught exception 11-18 10:09:29.022: E/AndroidRuntime(2237): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.in.test.MainActivity } 11-18 10:09:29.022: E/AndroidRuntime(2237): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1484) . . .

我的问题在哪里?谢谢

更新:在清单文件中,我在 application 元素中添加了这一行:

update: In the manifest file I added this line inside of application element:

<activity
            android:name="com.in.test.MainActivity" />

但结果还是一样.我会尽量遵循你的建议(使用意图过滤器).

but the result is still the same. I'll try to follow your suggestion (using intent filter).

推荐答案

要像您一样(通过在构造函数中使用活动类)以显式意图启动活动,必须在清单中为您的活动声明活动应用程序,并且必须符合您的应用程序.您不能为此使用单独的 apk 文件.

To start an activity with an explicit intent like you are doing (by using the activity class in the constructor), the activity must be declared in the manifest for your app and must be complied into your app. You cannot use a separate apk file for that.

做您想做的事情的方法是在 test.apk 中为活动声明一个意图过滤器,并使用适当的意图启动它.请参阅指南主题意图和意图过滤器以及有关Intent 类,了解有关如何执行此操作的更多信息.

The way to do what you want is to declare an intent filter for the activity in test.apk and to launch it using an appropriate intent. See the guide topic Intents and Intent Filters and the documentation for the Intent class for more information about how to do this.

这篇关于Android,如何在我的应用程序中使用外部 APK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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