2012-03-06 3 views
1

モックの場所を表示するアプリケーションを作成しようとしています。しかし、ボタンをクリックして位置を表示するとすぐに、アプリケーションが予期せず停止したという例外が発生します。コードは次のとおりです。AndroidでrequestSingleUpdateを使用してモックの位置を表示する

public class AndroidLBS extends Activity { 

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

    final Button gpsButton = (Button) findViewById(R.id.gpsButton); 
    gpsButton.setOnClickListener(new Button.OnClickListener() { 
    public void onClick(View v){ 
    LoadCoords();} 
    }); 
} 

    public void LoadCoords() 
    { 
    latText = (TextView) findViewById(R.id.latText); 
    lngText = (TextView) findViewById(R.id.lngText); 
    Intent in=new Intent("LOC_OBTAINED"); 

    PendingIntent pi=PendingIntent.getBroadcast(this,0,in,0); 

    registerReceiver(new BroadcastReceiver(){ 
     public void onReceive(Context arg0, Intent arg1) 
     { 
       Bundle bundle=arg1.getExtras(); 
       Location loc=(Location)bundle.get(LocationManager.KEY_LOCATION_CHANGED); 

      Double lat=loc.getLatitude(); 
      Double longitude=loc.getLongitude(); 

      latText.setText(lat.toString()); 
      lngText.setText(longitude.toString()); 
     } 
     },new IntentFilter("LOC_OBTAINED")); 

                          LocationManager myManager=LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    myManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER,true); 

    Location loc=new Location(LocationManager.GPS_PROVIDER); 
    loc.setLatitude(12.9); 
    loc.setLongitude(72.9); 

    myManager.setTestProviderLocation(LocationManager.GPS_PROVIDER,loc); 
    myManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, pi); 

    } 
} 

誰でもこの手伝いできますか?前もって感謝します!

+0

例外を投稿できますか? – MahdeTo

+0

プロバイダ "gps"が不明 – ankit0311

+0

おそらく、許可がどのようになっていたのかについての情報がなくても、http://stackoverflow.com/questions/8298732/unable-to-start-service-requires-access-mock-location-secure-setting追加またはログ/スタックトレースを知ることは困難です。これが何歳であり、解決されなかったという事実を考えれば、それは閉鎖されるべきですか? – PaulR

答えて

0

マニフェストに許可ACCESS_MOCK_LOCATIONを追加してみてください。

+0

私はすでにそれをしています – ankit0311

関連する問題