Cant "addAction" for IntentFilter in android

Hey. I am new to Android trying to create an IntentFilter that can filter multiple actions. Unfortunately, when I start using the method addAction, Eclipse throws an error:

"Syntax error on token" addAction ", Identifier expected after this token"

although I imported the required file. This is probably a configuration issue, although I'm not sure if the rest of the code shows 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 noticed one more thing - how I type the filter. nothing is displayed, just the message "No default suggestions"

Can someone help me?

+5
source share
2

( " - " ), ..), , ( ), Eclipse . . . ( ), .


dev guide ( ):

IntentFilter. , Android , , Java-, (AndroidManifest.xml) . ( , , Context.registerReceiver(), IntentFilter.)

:

<intent-filter android:label="@string/screen_off">
  <action android:name="android.intent.action.SCREEN_OFF" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
+5

, Java ( ).

private Context mContext;
IntentFilter filter = new IntentFilter();
{
    filter.addAction("android.intent.action.SCREEN_OFF");
}

.

+4

All Articles