0

I am trying to catch an Intent from installing a USB device. That is I want to start a Service. But, if the Service is started by other means, I would like to take a different course of action. However, my test to see if the Intent is from installing a USB device is passing even when I think is should not. For example, I can start the Service from a different Android application.

So I'm wondering. Can there be a bunch of Intents waiting to be processed? It would explain why I see my Intent test pass even if I think I didn't do anything to cause it to pass.

I am trying to test for an Intent using Try / Catch code. I dropped extra code that is not related:

try{
     Log.d(TAG, "Checking Intent to see if service started due to Intent");
     extras = getUSBAccessoryIntentExtras(intent);
     Log.d(TAG, "Service started due to Intent");
   }
   catch(NoUSBIntentFoundException nuife){
     Log.d(TAG, "Exception Caught: No intent found error.");
   } 
st2000
  • 286
  • 1
  • 16
  • Whats in `getUSBAccessoryIntentExtras`? – Henry Aug 09 '13 at 05:44
  • Yes, that was my bad. I tried to reduce the code just for this question and skipped over that part. It is a method that checks if the intent is 1) null, 2) if the intent's extras are null and 3) if there are certain extras.keySet() values. In forcing me to say this I realize there is nothing here that can tell the difference between an intent from a USB insertion and one from another program. – st2000 Aug 09 '13 at 14:21
  • Android has a concept of SticyBroadcast. If intent is sent using sticybroadcast, then it remains cached in system: Follow this link for details: https://stackoverflow.com/questions/3490913/what-is-a-sticky-intent-android – Sushil Aug 09 '13 at 05:46

0 Answers0