Android/Java 新手,我正在玩 AddProximityAlert()。我在下面有以下代码块,并且不断收到错误。有人可以解释 Eclipse 在说什么,以及如何解决我为 getBroadcast 和 registerReceiver 遇到的错误吗?
在 SecondaryActivity.java 文件中,我有 2 个广播接收器,这可能是原因吗?
SecondaryActivity.java:
public class SecondaryActivity extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
.
.
.
lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
float radius = 100f;
long expiration = -1;
final String PROX_ALERT_INTENT = "com.example.test";
Intent intent = new Intent(PROX_ALERT_INTENT);
PendingIntent proximityIntent = PendingIntent.**getBroadcast**(this, 0, intent, 0);
lm.addProximityAlert(latitude, longitude, radius, expiration, proximityIntent);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
**registerReceiver**(new ProximityIntentReceiver(), filter);
.
.
.
private class ProximityIntentReceiver extends BroadcastReceiver {
...
getBroadcast : PendingIntent 类型中的方法 getBroadcast(Context, int, Intent, int) 不适用于参数 (SecondaryActivity, int, Intent, int)
registerReceiver:方法 registerReceiver(SecondaryActivity.ProximityIntentReceiver, IntentFilter) 未定义为 SecondaryActivity 类型