倾斜"的addAction"以IntentFilter的android系统 [英] cant "addAction" to IntentFilter in android

查看:382
本文介绍了倾斜"的addAction"以IntentFilter的android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我是一个Android的初学者试图让一个IntentFilter的,可以过滤多个动作。不幸的是,当我开始使用的addAction 方法时,Eclipse会抛出一个错误:

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:

语法错误令牌的addAction   标识此标记后,预计

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

尽管我已经导入所需的文件。这可能是尽管我不确定为什么code犯规休息出现任何问题设置的问题。

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.

下面是我的code存根:

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?

推荐答案

读您的评论上面的问题(多个标记在该行 - 上标记语法错误),删除此标记的等等),我仍然认为这是一个括号(或括号),这并不让Eclipse的了解code不匹配的问题,这可能是另一种方法,仔细检查所有的文件,你可以尝试删除大部分您的code(只是将其复制到记事本),直到你缩小的问题。

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):

这是意图过滤器是IntentFilter的类的实例。然而,由于Android系统必须了解一个组件的功能,才可以启动该组件,的意图过滤器,一般不成立的Java code,但在应用程序的清单文件(AndroidManifest的.xml)的元素。 (在一个例外将过滤器是通过调用Context.registerReceiver()动态注册的广播接收器。它们直接创建为IntentFilter的对象)

An intent filter is an instance of the IntentFilter class. However, since the Android system must know about the capabilities of a component before it can launch that component, intent filters are generally not set up in Java code, but in the application's manifest file (AndroidManifest.xml) as elements. (The one exception would be filters for broadcast receivers that are registered dynamically by calling Context.registerReceiver(); they are directly created as IntentFilter objects.)

我会添加到您的清单,而不是:

I would add this to your manifest instead:

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

这篇关于倾斜&QUOT;的addAction&QUOT;以IntentFilter的android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆