Android - 如何拦截“安装应用程序"意图 [英] Android - How to intercept the 'Install application' intent

查看:41
本文介绍了Android - 如何拦截“安装应用程序"意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

1) 从网上下载 APK 并在市场上启动安装程序

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

是否有可能拦截并提示这些事件,或者谷歌是否已经将这些内容锁定得非常严密?

解决方案

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

<预><代码>...<receiver android:name=".IntentReceiver"><意图过滤器><action android:name="android.intent.action.PACKAGE_ADDED"/><action android:name="android.intent.action.PACKAGE_REMOVED"/><data android:scheme="package"/></意图过滤器></接收器>...

IntentReciever.java:

public class IntentReceiver extends BroadcastReceiver {@覆盖public void onReceive(上下文上下文,意图意图){context.startService(new Intent(context, YourService.class));}}

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

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?

解决方案

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.

这篇关于Android - 如何拦截“安装应用程序"意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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