简体   繁体   中英

Receiving Intent from a non-Activity class

Is it possible to handle Intent ACTION_SEND outside of an Activity class?

I was to receive Intent that doesn't open an Activity, where the class creates a Notification to show that the Intent is being processed as opposed to opening the app.

I'm sure this could be achieved with a Service that's always running, but I only want a Service to run immediately prior to creating the Notification, above. (In other words, processing of the ACTION_SEND Intent needs to be transparent other than presenting the Notification.)

The task, as best I can figure, is establishing a Context in a non-Activity class to feed to getSystemService() , though I'm at a loss how to achieve this.

If you just want to avoid UI then in fact, extending Activity does not mean you have to show any. So if you do not need to open any vUI in your class, then once your onCreate() is called just init it as usual by caling super.onCreate(bundle) , then do what you want to do there, but do not call any setContentView() . Then at the end of your onCreate() jump to another activity or just kill that one with finish() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM