2009-05-25 6 views
4

電話が近くに来たときに取得して更新しようとしています。 は、私は両方addProximityAlertとrequestLocationUpdatesaddProximityAlertが動作しません(どちらもrequestLocationUpdatesを実行していません) - Android

LocationManager lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    Location l = lm.getLastKnownLocation("gps"); 
    Intent intent = new Intent("eu.mauriziopz.gps.ProximityAlert"); 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
    lm.addProximityAlert(12, 12, 100, 1000000, pIntent); 

(私は手動でそれを起動することができますので、私は作品を知っている)この1は意図を発射することはありませんを使用してみました。 リスナーを使ってみましたが、一度だけ実行されます。どんなに私は、GPSの更新回数には再び

ProximityListener pl = new ProximityListener(); 
    lm. requestLocationUpdates("gps", 2000, 10, pl); 

これはこれは、リスナー

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()); 

} 

@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 

} 
} 
である(最初のケースで呼び出さ)活動のコード

public class ProximityAlert extends Activity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    Log.d("intent", "Hi"); 
    finish(); 
} 

で呼ばれることは決してありません

ありがとうございました

答えて

0

私はあなたのアクティビティをonCreate meth od(finish()を呼び出して)。

+0

に有効期限を設定しようとしていますずいぶん変わる。 回答ありがとうございます –

5

私はあなたがIntent/PendingIntentを定義する方法が問題だと思います。インテントを使用してアクティビティを開始するには2通りの方法があり、含まれているコードは2つの間のクロスのように見えます。

活動を開始する標準的な方法は、現在のコンテキストとアクティビティのクラスを取る意向コンストラクタを使用してPendingIntent作成するPendingIntentgetActivity方法を使用することです。また

Intent intent = new Intent(this, ProximityAlert.class); 
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 

を、あなたが追加することができます特定のアクション(「eu.mauriziopz.gps.ProximityAlert」など)をリッスンするIntentFilterを使用して、マニフェスト内のアクティビティにIntentReceiverを追加します。ただし、その場合は、PendingIntent.getBroadcastを使用してPendingIntentを作成する必要があります。むしろ文字列を使用するよりも

<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"/> 

、 ":あなたはあなたのマニフェストで定義されたロケーションベースのサービスのための適切な権限を持っていることを確認する必要があるすべての場合において

Intent intent = new Intent("eu.mauriziopz.gps.ProximityAlert"); 
PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0); 

静的定数LocationManager.GPS_PROVIDERの使用を検討するとよいでしょう。

1
Intent intent = new Intent("com.sccp.fourgdummy.REQUEST_DFGS"); 
intent.putExtra("launch_tab", "otp"); 
PendingIntent proximityIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 

これは重要である:Intent.FLAG_ACTIVITY_NEW_TASK

1

APIは、緯度、長い、半径、有効期限、意図であることがaddProximityAlertのパラメータを定義します。あなただけのデバッグ活動だったと私はdoesnの活動を終え、それがログに書き込まれた場合に見ることに興味があったことが-1ではなく100000

lm.addProximityAlert(12, 12, 100, 1000000, pIntent);

lm.addProximityAlert(12, 12, 100, -1, pIntent);