Android 模拟分配的问题
我试图为我所有的应用程序建立一个伪造的GPS,但是我的apk没有出现在模拟分配应用程序中 我创建了一个包含服务的主活动,该服务位于清单中 我能做什么 编辑:我把我的源代码(我是Android的新编程,谢谢你的帮助!) Manifest.xmlAndroid 模拟分配的问题,android,mocking,allocation,Android,Mocking,Allocation,我试图为我所有的应用程序建立一个伪造的GPS,但是我的apk没有出现在模拟分配应用程序中 我创建了一个包含服务的主活动,该服务位于清单中 我能做什么 编辑:我把我的源代码(我是Android的新编程,谢谢你的帮助!) Manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.fakegps">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCES_MOCK_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".mockLocationService" />
</application>
</manifest>
mockLocationService.java
package com.example.fakegps;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.FusedLocationProviderApi;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.model.LatLng;
public class mockLocationService extends Service implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener
{
public static LatLng LAT_LNG;
private String locationProviderName = "FakeGPS";
private GoogleApiClient apiClient = null;
private Location loc;
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
String latlong = intent.getParcelableExtra(MainActivity.latlong.toString());
if(latlong == null)
{
this.stopSelf();
return Service.START_REDELIVER_INTENT;
}
createApi();
apiClient.connect();
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
pepareProvider(lm);
lm.isProviderEnabled(locationProviderName);
actualizarLocalizacion(lm);
return Service.START_REDELIVER_INTENT;
}
private void createApi()
{
apiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
void pepareProvider(LocationManager lm)
{
lm.addTestProvider(locationProviderName, false, false, false, false, true, true, true, 0, 0);
lm.setTestProviderEnabled(locationProviderName, true);
}
public void addConnectionCallbacks()
{
}
@Override
public void onConnected(Bundle bundle)
{
LocationServices api = (LocationServices) LocationServices.FusedLocationApi;
((FusedLocationProviderApi) api).setMockMode(apiClient,true);
loc = createLocation();
((FusedLocationProviderApi) api).setMockLocation(apiClient, loc);
}
@Override
public void onConnectionSuspended(int i) {}
private Location createLocation()
{
loc = new Location(locationProviderName);
loc.setLatitude(LAT_LNG.latitude);
loc.setLongitude(LAT_LNG.longitude);
loc.setAccuracy(0);
loc.setTime(SystemClock.elapsedRealtimeNanos());
return loc;
}
private void actualizarLocalizacion(LocationManager lm)
{
lm.setTestProviderLocation(locationProviderName, loc);
}
@Override
public void onLocationChanged(Location location) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {}
}
格雷德尔先生
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fakegps"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-maps:8.1.0'
implementation 'com.google.android.gms:play-services:8.1.0'
}
你能给我们分享一些代码吗?就像你的活动,你的服务和你的清单?代码现在可用你能给我们分享一些代码吗?像您的活动、服务和清单?代码一样,现在可用
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fakegps"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-maps:8.1.0'
implementation 'com.google.android.gms:play-services:8.1.0'
}