安卓通知应用 [英] Android Notification App

查看:29
本文介绍了安卓通知应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个 android 应用程序.每当用户安装/下载新的第三方应用程序时,我都必须记录任何新安装的应用程序名称.如果用户正在安装新应用程序,我如何获得通知.提前致谢.

I'm currently working on an android application. I have to log any new installed app name whenever the user is installing/downloading a new third party app. How can I get the notification if the user is installing a new app. Thanks in advance.

public class ApplicationBroadcastService extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        System.out.print("-------");
    }
}

清单

    <receiver android:name=".applicationlog.ApplicationBroadcastService">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED"  />
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
        </intent-filter>
     </receiver>

但是当我安装/卸载任何应用程序时,我仍然没有进入 onReceive 方法.

But still I do not enter the onReceive method, when I am installing/uninstalling any app.

解决办法如下:

我对 Manifest 文件做了一个小改动.

I did a small change in my Manifest file.

    <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.PACKAGE_ADDED"  />
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package" />
        </intent-filter>

现在一切正常.. :)再次感谢@willytate

Now it's working fine.. :) Thanks again @willytate

推荐答案

Ajay,

您需要使用 Intent 过滤器设置 BroadcastReceiver 以接收以下操作:ACTION_PACKAGE_ADDED 然后从 BroadcastReceiver 的 onReceive() 方法你可以启动一个 Notification.

You will need to setup a BroadcastReceiver with an intent filter to receive the following Action: ACTION_PACKAGE_ADDED then from the onReceive() method of the BroadcastReceiver you can launch a Notification.

这篇关于安卓通知应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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