當我點擊按鈕,它調用setProximityAlert()
函數,然後將顯示Toast。我不明白問題出在哪裏,當我點擊接近響應的開始按鈕它崩潰我的應用程序
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locations);
Button start = (Button) findViewById(R.id.startl);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setProximityAlert();
Toast.makeText(getBaseContext(), "Started", Toast.LENGTH_LONG).show();
}
});
}
private static final String MMH_PROXIMITY_ALERT = "com.example.ProximityAlert";
private void setProximityAlert() {
Cursor c = db.rawQuery("SELECT * from locations", null);
Double lng = c.getDouble(c.getColumnIndex("longitude"));
c.moveToNext();
Double lat = c.getDouble(c.getColumnIndex("latitude"));
c.moveToNext();
Float rds = c.getFloat(c.getColumnIndex("radius"));
c.moveToNext();
String locService = Context.LOCATION_SERVICE;
LocationManager locationManager;
locationManager = (LocationManager)getSystemService(locService);
long expiration = -1; // do not expire
Intent intent = new Intent(MMH_PROXIMITY_ALERT);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, -1, intent, 0);
locationManager.addProximityAlert(lat, lng, rds, expiration, proximityIntent);
c.close();
locationManager.addProximityAlert(
lat, // the latitude of the central point of the alert region
lng, // the longitude of the central point of the alert region
rds, // the radius of the central point of the alert region, in meters
expiration, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
);
IntentFilter filter = new IntentFilter(MMH_PROXIMITY_ALERT);
registerReceiver(new ProximityIntentReceiver(), filter);
}
logcat窗口中的錯誤是什麼? –
你能否在這裏提供你的清單文件內容? –
如何發佈日誌貓plz幫助它是太大的意見 – sarfraz