Can't receive broadcasts for PACKAGE intents

后端 未结 3 1984
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 02:22

I am trying to register a Broadcast Receiver to receive broadcast events for the package events. Following is the code and my receiver in the manifest file. The log statment

相关标签:
3条回答
  • 2020-12-17 03:05

    It is possible that these Intents cannot be received by components registered in the manifest, but only by receivers registered in Java via registerReceiver().

    0 讨论(0)
  • 2020-12-17 03:07

    These three intents namely,

    Intent.ACTION_PACKAGE_ADDED
    Intent.ACTION_PACKAGE_REMOVED
    Intent.ACTION_PACKAGE_CHANGED
    

    when broadcasted by the system, have

    Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
    

    flag added so that only the registered receivers will receive the broadcasts and no broadcast receiver components will be launched. Refer Intent and PackageManagerService class of source for further details.

    0 讨论(0)
  • 2020-12-17 03:10

    This is my manifest, without

    <category android:name="android.intent.category.DEFAULT" />
    

    My app detects only the Android Market app install, but does not remove. Now it receives also the non-Android Market app broadcasts.

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SomeActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <receiver android:name="com.som.pakage.PackageInstallReceiver" >
            <intent-filter >
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>
    </application>
    
    0 讨论(0)
提交回复
热议问题