Android,用户何时安装应用程序?

标签 android android-intent broadcastreceiver

我想知道用户何时安装新应用。我用过广播接收器。

<receiver android:name=".NewInstallReceiver">
    <intent-filter>
        <action android:name="android.intent.action.package_added" />
        <data android:scheme="package" />
    </intent-filter>
</receiver>

代码:

public class NewInstallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String act = intent.getAction();
        Log.e("ee", "new install" + intent);
        if (Intent.ACTION_PACKAGE_ADDED.equals(act) || Intent.ACTION_PACKAGE_REMOVED.equals(act)) {
            /* ContentResolver contentResolver = context.getContentResolver();
            contentResolver.query()*/
        }
    }
}

当我从 Playstore 安装应用时,我看不到任何日志。

我应该使用服务吗?如果是,那么我怎样才能让它无限次运行?

最佳答案

我猜你的 intent 过滤器有错字,试试下面的 intent 过滤器

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

关于Android,用户何时安装应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28362307/

相关文章:

android - 蓝牙连接状态更改时防止onDestroy

android - Intent PACKAGE_ADDED 未注册

android - 从转换为彩信的设备发送多部分短信

ANDROID - ExpandableListView

JavaMail 错误 : javax. mail.AuthenticationFailedException

java - 打开新 Activity 并更改微调器?

android - 使用起始值开始新 Activity

android - Android 应用程序中 Flutter View 的 Release模式下,当设备尺寸发生变化时,如何重建 Flutter 小部件?

android - 在没有新 Intent 的情况下,我应该如何从通知返回到 Activity

android - 如何找出broadcastReceiver调用的地方?