Android 与目标组件的显式意图
是否可以激发明确的意图,但不是针对我的项目中的活动,而是针对其他应用程序中的活动。
我确信这段代码并且我知道它正在运行
Intent i=new Intent(this,MyActivity.class);
但是是否可以做这样的事情
Intent i=new Intent(this,com.bzz.bla.bla.SomeActivity.class);
我的意思是从其他应用程序显式启动活动的确切方法是什么(其他apk中包含的活动), 这有可能吗?
我尝试过,但它让我强制关闭消息。
Is it possible to fire explicit intent but not for an activity from my project but for activity in some other application.
I am sure of this code and I know it is running
Intent i=new Intent(this,MyActivity.class);
But is it possible to do something like this
Intent i=new Intent(this,com.bzz.bla.bla.SomeActivity.class);
I mean what is the exact way of explicitly starting activity from other application (activity that is contained in other apk),
is this possible at all ?
I tried but it drops me force close message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,这是可能的。但意图的创建是不同的。试试这个:
Yes it's possible. But creation of intent is different.Try this:
是的,这是可能的。但意图创建有点不同。
但是,您就无法调用任何随机应用程序的任何活动。该特定活动应该有一个带有 MAIN 操作的意图过滤器。
Yes it's possible. But the intent creation is a little different.
But, then you just can't call any activity of any random app. That particular activity should have an intent-filter with a MAIN action.
您可以通过意图启动任何组件,只需要知道操作或目标组件(pkg,cls)名称即可。
考虑我开发了两个应用程序 app1 & app2 app1 pkg 名称为 com.xyz.app1 & app2 pkg 名称为
com.xyz.app2.
app1 有两个活动
App1MainActivity
&App1XyzActivity
,app2 只有一个 ActivityApp2MainActivity
现在我想从 启动 app1 的 Activity app2 App2MainActivityapp2 App2MainActivity 有两个按钮 b1 和 b1 b2 单击 b1 我想启动 App1MainActivity &单击 b2 我想启动
App1XyzActivity
然后 App2MainActivity 中按钮 b1 和 b2 的代码现在是我安装了两个应用程序 app1 和 app1 app2 并运行 app2。
当我单击按钮 b1 时,app1 App1MainActivity 启动,但如果我单击按钮 b2 则会发生异常,原因是我们无法随机启动另一个应用程序的任何活动,即使您知道包名称及其类名称,但您可以启动另一个应用程序的主要活动,如果它有带有操作 MAIN 的意图过滤器,并且您知道它的包名称和类名称。
You can start any component through intent only need to know either action or target component (pkg,cls) name.
Consider I developed two apps app1 & app2 app1 pkg name is com.xyz.app1 & app2 pkg name is
com.xyz.app2.
app1 having two activities
App1MainActivity
&App1XyzActivity
,app2 has only one activityApp2MainActivity
now I want to start both the activity of app1 from app2 App2MainActivityapp2 App2MainActivity have two buttons b1 & b2 on click b1 I want to start App1MainActivity & on click b2 I want to start
App1XyzActivity
then the code for button b1 and b2 within App2MainActivity isnow I install both apps app1 & app2 and run the app2.
When I click on the button b1 then app1 App1MainActivity is start but if I click on button b2 an exception occur the reason is we can not start randomly any activity of another app even if you know the package name and its class name but you can start another app main activity if it have intent filter with action MAIN and if you know its package name and class name.
我建议连接包 &带点的类名;
这可以加快复制速度粘贴,例如。在编写 jUnit 测试时。
I'd suggest to concatenate the package & class name with a dot;
this speeds up copy & paste, eg. while writing jUnit tests.