Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

broadcastreceiver - Broadcast receiver for PACKAGE_ADDED not working from Android 3.1 onwards

I am not able to launch my Broadcast receiver which is part of a STOPPED Application, I had registered for PACKAGE_ADDED event in the broadcast receiver, The application works properly till 3.0 but above 3.1 I am facing this issue. I used the below lines to send the intent.

    Intent intent = new Intent(MY_INTENT_ACTION);
    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    sendBroadcast(intent);

Please let me know if I need to do anything more.


Adding More Info:

My Intention is i wanted to listen for PACKAGE_ADDED Broadcast event and Perfrom some processing in my OnReceive, Please let me know if there is any possiblity to listen for this event with out launching application. A sample code to achive this would be helpful. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The docs for PACKAGE_ADDED state:

This is a protected intent that can only be sent by the system.

You can't modify it, or try to add flags to it. From the release notes for 3.1:

Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents.

and from the docs for FLAG_EXCLUDE_STOPPED_PACKAGES

If set, this intent will not match any components in packages that are currently stopped. If this is not set, then the default behavior is to include such applications in the result.

All this means that your app won't work the same way as it used to. You'll have to make sure your app is started in order to receive PACKAGE_ADDED.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...