0
テストケースを模擬して正確性に基づいて結果を表示することで、フィールド内でうねりのある場所を生成するプログラムをデバッグしようとしています。gpsプロバイダーテストを実行するとモックロケーションへのアクセスが拒否されます
これは、ロケーションを取得するためのバックグラウンドサービスに依存しています。
結果は以下である:
エラー:
java.lang.SecurityException: com.vrin.location from uid 10168 not allowed to perform MOCK_LOCATION
のAndroidManifest.xml(デバッグ)
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" tools:ignore="MockLocation"/>
試験は、上記のエラーで失敗します。それは私が知っているモックの場所のアプリを選択して持っていないためかどうかは分かりません。エラーを生成するコード:
public void getMockLocation(Location location) {
mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
mLocationManager.addTestProvider
(
LocationManager.GPS_PROVIDER,
"requiresNetwork" == "",
"requiresSatellite" == "",
"requiresCell" == "",
"hasMonetaryCost" == "",
"supportsAltitude" == "",
"supportsSpeed" == "",
"supportsBearing" == "",
android.location.Criteria.POWER_LOW,
android.location.Criteria.ACCURACY_FINE
);
Location newLocation = new Location(LocationManager.GPS_PROVIDER);
newLocation.setLatitude (location.getLatitude());
newLocation.setLongitude(location.getLongitude());
newLocation.setAccuracy(500);
mLocationManager.setTestProviderEnabled
(
LocationManager.GPS_PROVIDER,
true
);
mLocationManager.setTestProviderStatus
(
LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null,
System.currentTimeMillis()
);
mLocationManager.setTestProviderLocation
(
LocationManager.GPS_PROVIDER,
newLocation
);
}
ありがとうございました!
ネイサン
テストするバージョンは? – AndroidHacker
ちょっと、私はバージョン23を使用しています –