Android addProximityAlert不会开火

Android addProximityAlert不会开火,android,Android,我试图实现addProximityAlert方法,但它没有启动。这是我的密码: 取样管 近亲 近米特里斯腾纳 XML清单 抱歉,我选择的代码不完整。当您添加代理服务器时,您必须向LocationManager传递PendingEvent,这些PendingEvent将在broadcastIntent上启动,我在您的代码中看不到您为该PendingEvent注册接收器的时间、地点 现在有个问题。。。如果在活动上添加ProximityAlert,为什么要编写服务 public class Sampl

我试图实现addProximityAlert方法,但它没有启动。这是我的密码:

取样管

近亲

近米特里斯腾纳

XML清单


抱歉,我选择的代码不完整。

当您添加代理服务器时,您必须向LocationManager传递PendingEvent,这些PendingEvent将在broadcastIntent上启动,我在您的代码中看不到您为该PendingEvent注册接收器的时间、地点

现在有个问题。。。如果在活动上添加ProximityAlert,为什么要编写服务

public class SampleProximityAlert extends Activity {
 /** Called when the activity is first created. */

 protected LocationManager locationManager;
 protected Location location;
 public static Location pLocation;
 protected Intent intent;
 protected PendingIntent pIntent;
 protected GeoPoint point;
 public float distance;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  locationManager = (LocationManager) this
    .getSystemService(Context.LOCATION_SERVICE);
  location = locationManager
    .getLastKnownLocation(LocationManager.GPS_PROVIDER);

  try {
   locationManager.requestLocationUpdates(
     LocationManager.GPS_PROVIDER, 1000, 1,
     new ProximityListener());
  } catch (RuntimeException e) {
   e.printStackTrace();
  }
  // point = new GeoPoint(49868004, 8626971);
  try {
   pLocation = new Location(location.getProvider());
  } catch (RuntimeException e) {
   e.printStackTrace();
  }
  Log.i("PROVIDER", location.getProvider());

  pLocation.setLatitude(49.868004);
  pLocation.setLongitude(8.626971);

  distance = methodeDistance(pLocation);

  Log.i("DISTANCE", String.valueOf(distance));

  Log.i("POSITION",
    String.valueOf(location.getLatitude()) + ","
      + String.valueOf(location.getLongitude()));
  intent = new Intent(this, ProximityAlert.class);
  intent.setAction("ProximityAlert");
  pIntent = PendingIntent.getService(this, 0, intent, 0);

  locationManager.addProximityAlert(49.868004, 8.626971, 429, 50000,
    pIntent);
 }

 public float methodeDistance(Location mLocation) {
  float mDistance = location.distanceTo(pLocation);
  return mDistance;
 }
}
public class ProximityAlert extends Service {
 @Override
 public IBinder onBind(Intent intent) {
  // TODO Auto-generated method stub
  Log.i("Alert", "fired");
  return null;
 }

 @Override
 public void onCreate() {
  super.onCreate();
  Log.i("ONCREATE", "create ProximityAlert as Service");
 }

 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
  Log.i("ONSTARTCOMMAND", "OnStartCommand");
  return super.onStartCommand(intent, flags, startId);
 }
}
public class ProximityListener implements LocationListener {
 String DEBUG_TAG = "ProximityListener";

 @Override
 public void onLocationChanged(Location location) {
  // TODO Auto-generated method stub
  Log.d(DEBUG_TAG, location.toString());
  // tvD.setText(String.valueOf(location.distanceTo(pLocation)));
 }

 @Override
 public void onProviderDisabled(String provider) {
  // TODO Auto-generated method stub
 }

 @Override
 public void onProviderEnabled(String provider) {
  // TODO Auto-generated method stub
 }

 @Override
 public void onStatusChanged(String provider, int status, Bundle extras) {
  // TODO Auto-generated method stub
 }
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tsystems.proximityAlert"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SampleProximityAlert"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".ProximityAlert">
            <intent-filter>
                <action android:name="ProximityAlert"/>
                <category android:name="com.proaktiveOrtung"/>
            </intent-filter>
        </service>
        <service android:name=".ProximityAlert"></service>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tsystems.proximityAlert"
      android:versionCode="1"
      android:versionName="1.0">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SampleProximityAlert"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".ProximityAlert">
            <intent-filter>
                <action android:name="ProximityAlert"/>
                <category android:name="com.proaktiveOrtung"/>
            </intent-filter>
        </service>
        <service android:name=".ProximityAlert"></service>
    </application>
    <uses-sdk android:minSdkVersion="8" />

</manifest>