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

使用模擬位置而不在設置中設置它

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

問題描述

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

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

我想要實現的是模擬我的位置,而不在開發人員選項中設置允許模擬位置"標志.

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

我知道這是可能的,因為它適用于這個應用程序: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 權限的情況.

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.

但這一切都導致了這個例外:
RuntimeException:無法啟動 Activity:SecurityException:需要 ACCESS_MOCK_LOCATION 安全設置

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

推薦答案

我已經反編譯了你提到的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
}

由于這些代碼的執行時間很短,其他應用很難檢測到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. 需要對您的設備進行 root 訪問
2. 將您的應用移動到 /system/app/system/priv-app

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

I tried it in my project and it works fine.

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

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

相關文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數據庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 在线播放国产一区二区三区 | 亚洲一区二区在线 | 国产成人一区二区 | 91欧美精品成人综合在线观看 | 天天操天天射天天舔 | 91成人| 久久伊人一区 | 国产精品久久久久久久久久 | 日日噜| 丝袜美腿一区二区三区 | 亚洲综合伊人 | 人人看人人草 | 91成人免费观看 | 亚洲va国产日韩欧美精品色婷婷 | jav成人av免费播放 | 亚洲精品欧美 | 91久久电影 | 欧美日韩亚洲国产综合 | 国产高清免费视频 | 免费a级毛片在线播放 | 九九九色| 在线观看午夜视频 | www.99久久.com| 亚洲精品国产电影 | 国产美女自拍视频 | 99精品视频免费在线观看 | 成人精品鲁一区一区二区 | 做a视频在线观看 | 一区二区在线 | 免费国产一区二区 | 久草视频在线播放 | 在线超碰 | 国产剧情一区 | 91伊人 | 自拍偷拍中文字幕 | 人人干人人玩 | 波多野结衣精品在线 | 人人鲁人人莫人人爱精品 | 东方伊人免费在线观看 | 欧美一级免费观看 | 综合色在线 |