Android通知应用

Aja*_*ngh 15 notifications android android-activity

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

Java文件

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

表现

    <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>
Run Code Online (Sandbox Code Playgroud)

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

这是解决方案:

我在Manifest文件中做了一些小改动.

    <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>
Run Code Online (Sandbox Code Playgroud)

现在它工作正常.. :)再次感谢@willytate

Wil*_*ate 8

阿贾伊,

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


War*_*ith 6

看看意图文档.您正在寻找ACTION_PACKAGE_INSTALL(似乎从未使用过,请参阅评论)和ACTION_PACKAGE_REMOVED.

  • 不,试着实施willytate提到的.没有人会为你编写代码.如果你卡住了,请问一个新问题(不要在那里要求代码,提供你所拥有的......) (3认同)