小编dae*_*tus的帖子

Android Geofencing - 没有即将到来的意图?

我有一个奇怪的问题.

我使用Google服务实施了地理围栏.(以下实施)在我的设备(三星Galaxy S和Moto X)上,它们的工作非常完美.在其他一些设备(HTC Incredible S,Galaxy Note)上,我没有收到转换意图.决不.通过精确的GPS定位,站在栅栏中间.没有.日志中没有任何可疑之处.没有错误,没有警告.没有迭代,服务无法启动.

有没有人见过这样的事情?(这很奇怪,因为我看不到工作的设备和没有的设备之间的任何连接.它不是制造商,它不是Android版本,Play服务是所有这些都是最新的.)

执行:

表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.package"
android:installLocation="auto"
android:versionCode="17"
android:versionName="1.1" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="test.package.MainActivity"
        android:label="Compass"
        android:screenOrientation="portrait" />

    <service android:name="test.package.services.geofences.ShowNotificationService"
            android:label="@string/app_name"
            android:exported="false"/>

    <receiver android:name="test.package.services.geofences.UpdateGeofences">
        <intent-filter>
            <action android:name="test.package.updateGeofecnes"/>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

更新地理围栏:

 public class UpdateGeofences extends BroadcastReceiver implements
        GooglePlayServicesClient.ConnectionCallbacks, …
Run Code Online (Sandbox Code Playgroud)

android android-intent geofencing android-pendingintent android-geofence

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

Retrofit + OkHTTP - 响应缓存无法正常工作

我知道有很多类似的问题,但我已经阅读了所有这些问题,但没有一个真正有用.

所以,这是我的问题:

我正在使用retrofit + okhttp从API获取一些数据,我想缓存它们.不幸的是,我没有API服务器的管理员权限,因此我无法修改服务器返回的标头.(目前,服务器返回Cache-control:private)

所以我决定使用okhttp标头欺骗来插入适当的缓存标头.可悲的是,无论我做什么,缓存似乎都不起作用.

我初始化这样的api服务:

int cacheSize = 10 * 1024 * 1024; // 10 MiB
File cacheFile = new File(context.getCacheDir(), "thumbs");
final Cache cache = new Cache(cacheFile, cacheSize);

OkHttpClient client = new OkHttpClient();
client.setCache(cache);
client.interceptors().add(new Interceptor() {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        return originalResponse.newBuilder()
                .removeHeader("Access-Control-Allow-Origin")
                .removeHeader("Vary")
                .removeHeader("Age")
                .removeHeader("Via")
                .removeHeader("C3-Request")
                .removeHeader("C3-Domain")
                .removeHeader("C3-Date")
                .removeHeader("C3-Hostname")
                .removeHeader("C3-Cache-Control")
                .removeHeader("X-Varnish-back")
                .removeHeader("X-Varnish")
                .removeHeader("X-Cache")
                .removeHeader("X-Cache-Hit")
                .removeHeader("X-Varnish-front")
                .removeHeader("Connection")
                .removeHeader("Accept-Ranges")
                .removeHeader("Transfer-Encoding")
                .header("Cache-Control", "public, max-age=60")
              //.header("Expires", "Mon, 27 Apr 2015 08:15:14 …
Run Code Online (Sandbox Code Playgroud)

android caching cache-control retrofit okhttp

4
推荐指数
2
解决办法
3859
查看次数