小编Fol*_*lli的帖子

仅在前台访问设备位置的权限

我的应用程序仅在前台使用位置数据。因为Android 10区分了后台和前台的位置,所以我想把manifest.xml中的权限设置的尽量少,以免打扰用户。

发行说明 ( https://developer.android.com/about/versions/10/privacy/changes ) 声明如下:如果我将目标 SDK 放到 Android 10 (29) 并且只在清单中请求 ACCESS_FINE_LOCATION(故意排除新的 ACCESS_BACKGROUND_LOCATION 权限),我应该只获得前台访问权限(这就是我想要的)。

在成绩文件中:

compileSdkVersion 29
    defaultConfig {
        applicationId "com.genewarrior.sunlocator"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 70
        versionName "3.10"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
Run Code Online (Sandbox Code Playgroud)

在清单文件中:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
Run Code Online (Sandbox Code Playgroud)

但是,与预期的“仅在使用应用程序时允许”不同,仍然可以在“位置”权限中选择“始终允许”。

也时不时弹出通知“应用程序在后台获取了您的位置”,这正是我想要避免的。

在此处输入图片说明

android android-permissions

7
推荐指数
1
解决办法
5889
查看次数

在AuthenticationSuccessHandler中设置会话范围对象

(编辑澄清)我有一个POJO(SessionStorage)来存储会话特定数据,我想在成功验证后填充它.因为我将Scope设置为"session",所以我期望MainController和AuthenticationSuccesshandler使用相同的对象实例.

当我运行WebApp时,主控制器启动一个实例(如预期的那样),但是当我登录时,AuthenticationSuccesshandler似乎没有自动装配SessionStorage对象,因为它会抛出NullPointerException.

我如何让它做我想要的?以下是我的代码的摘录:

@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class SessionStorage implements Serializable{
    long id;
    public int getId() {
    return id;
    }

    public SessionStorage() {
        System.out.println("New Session Storage");
        id = System.currentTimeMillis();
    }
}
Run Code Online (Sandbox Code Playgroud)

主控制器如下所示:

@Controller
@Scope("request")
@RequestMapping("/")
public class MainController {
    @Autowired
    private SessionStorage sessionStorage;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login(
            @RequestParam(value = "error", required = false) String error,
            @RequestParam(value = "logout", required = false) String logout) {

        System.out.println(sessionStorage.getId()); //Works fine

        ModelAndView model = new …
Run Code Online (Sandbox Code Playgroud)

java spring scope spring-security pojo

5
推荐指数
1
解决办法
635
查看次数

如何将我的 Google Maps Time Zone API 密钥限制为 Android 应用程序?

是否可以将时区 API 密钥限制为 Android 应用程序?

通过定义包名称和 SHA-1 哈希值,可以将 Google Maps Android API 和 Google Places API 密钥限制为某些 Android 应用程序。

这对于 Maps and Places API 来说没有问题,但对 Time Zone API 使用完全相同的设置会不断返回“ REQUEST_DENIED”。将应用程序限制设置回“无”会导致查询成功,但我不想让我的 API 密钥不受保护。

我调用API的方式如下:

double lat = 51.1789;
double lon = -1.8262;
long time = 1523092938; 
String Api_key = "#API_KEY#";

String query = "https://maps.googleapis.com/maps/api/timezone/json?location="+String.format(Locale.ROOT, "%.4f",lat)+","+String.format(Locale.ROOT, "%.4f",lon)+"&timestamp="+time+"&key="+ Api_key;

protected JSONObject doInBackground(String... params) {
        HttpURLConnection connection = null;
        BufferedReader reader = null;

        try {
            URL url = new URL(query);
            connection = (HttpURLConnection) …
Run Code Online (Sandbox Code Playgroud)

android api-key google-cloud-console google-api-timezone

5
推荐指数
1
解决办法
396
查看次数