Android - 如何拦截“安装应用程序”意图

发布于 2024-09-14 16:44:27 字数 183 浏览 2 评论 0原文

好的,所以不完全确定这是可能的......

但尝试编写一个应用程序,以便我可以在执行以下任何活动之前运行一些代码。

1) 从网络下载 APK,市场启动安装程序

2) 在 Android 市场上按下安装按钮

是否可以拦截并提示这些事件,或者 Google 是否已将这些内容锁定得相当严密?

OK, so not entirely sure this is possible...

But trying to write an application so that I can run some code before any of the following activities are performed.

1) APK is downloaded from web and market launches installer

2) Install button is pressed on android market

Is it possible to intercept and prompt on these events, or has Google locked that stuff down quite tightly?

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

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

发布评论

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

评论(2

梦回旧景 2024-09-21 16:44:27

这本身不是答案,但我在这里找不到任何评论工具。对不起。
我也有这个问题。我希望能够检测新的应用程序安装。我知道这是可能的 - 例如,当您安装新应用程序时,应用程序“Apps to SD”会发布一条通知,单击该通知会打开一个对话框,将该新应用程序移动到 SD 卡。
到目前为止,我所能想到的就是这样:
manifest.xml:

...
<receiver android:name=".IntentReceiver">
  <intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <action android:name="android.intent.action.PACKAGE_REMOVED" />
    <data android:scheme="package" />
  </intent-filter>
</receiver>
...

IntentReciever.java:

public class IntentReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    context.startService(new Intent(context, YourService.class));
  }
}

然后创建 YourService 并调用 onCreate(),然后调用 onStartCommand()。但是,我无法对此进行调试或成功显示来自服务类的任何通知,因此我不完全确定这是否有效。我已经让它适用于其他接收器,例如 android.intent.action.BOOT_COMPLETED。

This isn't an answer per se, but I can't find any commenting tool here. Sorry.
I'm having this issue as well. I would like to be able to detect new application installs. I know it is possible - for example, the app Apps to SD posts a notification when you install a new app that when clicked opens a dialog to move that new app to the sd card.
So far, all I've been able to figure is like this:
manifest.xml:

...
<receiver android:name=".IntentReceiver">
  <intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <action android:name="android.intent.action.PACKAGE_REMOVED" />
    <data android:scheme="package" />
  </intent-filter>
</receiver>
...

IntentReciever.java:

public class IntentReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    context.startService(new Intent(context, YourService.class));
  }
}

YourService is then created and calls onCreate() then onStartCommand(). However, I haven't been able to debug this or successfully display any notifications from the service class, so I'm not entirely sure this works. I have gotten this to work for other Receivers like android.intent.action.BOOT_COMPLETED.

你穿错了嫁妆 2024-09-21 16:44:27

使用 BroadcastReceiver 您可以过滤 android.intent.action.PACKAGE_ADDED 意图。然而,这只发生在您描述的两个操作之后,而不是之前。并且它不会停止或中断安装。

AFAIK 没有办法在市场之前做任何事情或中断市场。当然,我们甚至谈论的是另一个应用程序,而不是正在安装的应用程序。

Using a BroadcastReceiver you can filter the android.intent.action.PACKAGE_ADDED intent. However this will only be after the two actions you describe, not before. And it will not stop or interrupt the installation.

AFAIK there is no way to do anything before or to interrupt the Market. And then we're even talking about another app than the one that's being installed ofcourse.

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