Android-自定义内置组件?
假设我创建了一个查看 Google 地图的意图,如下所示:
Intent intent = new Intent("android.intent.ACTION_VIEW");
intent.setComponent(ComponentName.unflattenFromString("com.google.android.apps.maps/com.google.android.maps.MapsActivity"));
intent.addCategory(android.intent.category.LAUNCHER);
intent.setData("Your Google My Map URL HERE");
startActivity(intent);
有没有办法自定义这个 MapsActivity 组件,或者只是获取其中的句柄来控制/查询它,或者我可以要从头开始做这件事吗?
Let's say I create an intent to view a Google map like so:
Intent intent = new Intent("android.intent.ACTION_VIEW");
intent.setComponent(ComponentName.unflattenFromString("com.google.android.apps.maps/com.google.android.maps.MapsActivity"));
intent.addCategory(android.intent.category.LAUNCHER);
intent.setData("Your Google My Map URL HERE");
startActivity(intent);
Is there any way to customize this MapsActivity
component, or just get a handle in it to control/query it at all, or would I have to start from scratch to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以。您无权侵入其他应用程序,就像他们无权侵入您的应用程序一样。使用
MapView
。顺便说一句,你的示例代码很可怕。切勿通过组件名称引用第三方应用程序,因为如果该应用程序重构其代码,您的代码将会中断。切勿将
LAUNCHER
类别添加到Intent
中,除非您实际上是启动器(例如主屏幕)。请记住,这个食谱既没有被谷歌记录,也没有得到谷歌的支持。No. You have no right to hack into other apps, any more than they have the right to hack into yours. Use
MapView
.BTW, your example code there is scary. Never reference third-party apps by component name, as your code will break if that app refactors its code. Never add the
LAUNCHER
category to anIntent
unless you are actually a launcher (e.g., a home screen). And bear in mind that this recipe is neither documented nor supported by Google.