Hi. I am an Android beginner trying to make an IntentFilter that can filter multiple actions. Unfortunately, when I begin using the addAction method, Eclipse throws an error:
“Syntax error on token “addAction”,
Identifier expected after this token”
even though I have imported the required file. This is probably a settings issue even though I am unsure why rest of the code doesnt show any problems.
Here is my code stub:
import android.content.Intent;
import android.content.Context;
import android.content.IntentFilter;
...
private Context mContext;
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.SCREEN_OFF");
I observed one more thing–as I type ‘ filter.’ nothing shows up, just the message “No Default Proposals”
Can anybody help me?
Reading your comment above in the question (“Multiple markers at this line – Syntax error on token “)”, delete this token, etc.), I still think it is a bracket (or parenthesis) mismatch problem that does not let Eclipse understand the code. It could be in another method. Check carefully all your file. You may try to remove most of your code (just copy it to notepad) until you narrow the issue.
From the dev guide (emphasis mine):
I would add this to your manifest instead: