久久久久久久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(模擬;使用列表調用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 午夜无码国产理论在线 | 自拍偷拍欧美 | 狠狠视频 | 视频精品一区二区三区 | 精品国产成人 | 中文字幕 视频一区 | 色婷婷亚洲一区二区三区 | 国产精品日韩欧美一区二区三区 | 亚洲高清在线 | 日本不卡一区二区三区 | 亚洲国产高清高潮精品美女 | 欧美在线观看一区 | 日韩欧美精品 | 亚洲一区二区久久久 | 国产精品色哟哟网站 | 国产视频福利一区 | 久久久久久亚洲精品 | 欧美午夜精品理论片a级按摩 | 97热在线 | avhd101在线成人播放 | 欧美成人一区二区三区 | 精品国产乱码久久久久久牛牛 | 精品99在线 | 在线视频一区二区 | www性色| 精品久久久久久久久久久久久久久久久 | 99热精品在线 | 亚洲电影免费 | 在线观看亚洲专区 | 91在线观 | 波多野结衣一区二区 | 成人一区二区电影 | 亚洲一区二区三区四区视频 | 欧美国产视频 | 成人网在线 | 日韩欧美三区 | 国产精品一区二区不卡 | 国产视频一区二区 | 亚洲精品一区二区三区 | 九九热在线视频免费观看 | 一级毛毛片|