久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用模擬位置而不在設(shè)置中設(shè)置它

Use mock location without setting it in settings(使用模擬位置而不在設(shè)置中設(shè)置它)
本文介紹了使用模擬位置而不在設(shè)置中設(shè)置它的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在編寫一個應(yīng)用程序,它利用了 android 中的位置模擬可能性.

I am writing an App which makes use of the location mocking possibility in android.

我想要實現(xiàn)的是模擬我的位置,而不在開發(fā)人員選項中設(shè)置允許模擬位置"標志.

What I would like to achive is to mock my location without setting the "allow mock locations" flag in the developer options.

我知道這是可能的,因為它適用于這個應(yīng)用程序:https://play.google.com/store/apps/details?id=com.lexa.fakegps&hl=en

I know that it is possible, because is works with this app: https://play.google.com/store/apps/details?id=com.lexa.fakegps&hl=en

我嘗試了什么:

生成一個 apk,將其移至/system/app,然后重新啟動
而且我還嘗試了在清單中使用和不使用 ACCESS_MOCK_LOCATION 權(quán)限的情況.

Generate an apk, move it to /system/app, do a reboot
And I also tried it with and without the ACCESS_MOCK_LOCATION permission in the manifest.

但這一切都導(dǎo)致了這個例外:
RuntimeException:無法啟動 Activity:SecurityException:需要 ACCESS_MOCK_LOCATION 安全設(shè)置

But it all lead to this exception:
RuntimeException: Unable to start Activity: SecurityException: Requires ACCESS_MOCK_LOCATION secure setting

推薦答案

我已經(jīng)反編譯了你提到的com.lexa.fakegps,它的作用是這樣的:

I have decompiled com.lexa.fakegps you mentioned in question, and what it do like this:

private int setMockLocationSettings() {
    int value = 1;
    try {
        value = Settings.Secure.getInt(getContentResolver(),
                Settings.Secure.ALLOW_MOCK_LOCATION);
        Settings.Secure.putInt(getContentResolver(),
                Settings.Secure.ALLOW_MOCK_LOCATION, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return value;
}

private void restoreMockLocationSettings(int restore_value) {
    try {
        Settings.Secure.putInt(getContentResolver(),
                Settings.Secure.ALLOW_MOCK_LOCATION, restore_value);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

/* every time you mock location, you should use these code */
int value = setMockLocationSettings();//toggle ALLOW_MOCK_LOCATION on
try {
    mLocationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, fake_location);
} catch (SecurityException e) {
    e.printStackTrace();
} finally {
    restoreMockLocationSettings(value);//toggle ALLOW_MOCK_LOCATION off
}

由于這些代碼的執(zhí)行時間很短,其他應(yīng)用很難檢測到ALLOW_MOCK_LOCATION的變化.

Because the execution time of these code is very short, other apps can hardly detect the change of ALLOW_MOCK_LOCATION.

你也需要,
1. 需要對您的設(shè)備進行 root 訪問
2. 將您的應(yīng)用移動到 /system/app/system/priv-app

我在我的項目中嘗試過,效果很好.

I tried it in my project and it works fine.

這篇關(guān)于使用模擬位置而不在設(shè)置中設(shè)置它的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數(shù)據(jù)庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設(shè)置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調(diào)用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 国产精品国产三级国产aⅴ中文 | 青青草免费在线视频 | 亚洲视频免费观看 | 精品视频在线观看 | 欧美videosex性极品hd | av日日操 | 超碰欧美| 免费观看羞羞视频网站 | 亚洲国产精品一区二区第一页 | 欧美一区成人 | 国产1区2区 | 国产不卡在线 | 黄网站在线播放 | 日韩中文字幕网 | 欧美精品网 | 草久久| 久久精品久久久久久 | 国产成人综合av | 日本一区二区三区四区 | 久久久国产一区二区三区 | 日韩av资源站 | 狠狠躁18三区二区一区 | 午夜精品久久久久久久久久久久 | 久久综合久久自在自线精品自 | 久久久激情视频 | 在线色网| 国产精品.xx视频.xxtv | 久久精品日产第一区二区三区 | 精品一区在线看 | 欧美日韩精品一区二区三区视频 | 国产在线高清 | 91精品国产综合久久香蕉922 | 男女污网站 | 国产精品一区二 | 国产高清在线精品 | 国产视频二区 | 亚洲色欧美另类 | 日韩欧美一区二区三区在线播放 | 久久久www成人免费精品 | 久久爱一区| 日韩欧美一级片 |