@Override public Cursor queryPath(Context context, Uri uri){ String videoId = uri.getLastPathSegment(); return context.getContentResolver().query( MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, PATH_PROJECTION, PATH_SELECTION, new String[] { videoId }, null/*sortOrder*/); } }
staticclassThumbnailStreamOpenerFactory{
public ThumbnailStreamOpener build(Uri uri, int width, int height){ if (!isMediaStoreUri(uri) || width > MINI_WIDTH || height > MINI_HEIGHT) { returnnull; } elseif (isMediaStoreVideo(uri)) { returnnew ThumbnailStreamOpener(new VideoThumbnailQuery()); } else { returnnew ThumbnailStreamOpener(new ImageThumbnailQuery()); } } } }
根据代码我们开一看出来在这里Glide是使用Cursor和ContentResolver去获取路径对应的缩略图,属于官方推荐的方法。但是坏处是它只能传入content:这种格式的路径,不支持传入绝对路径。但是无论如何这个思路输入官方推荐的思路,而且以后为了兼容Android N 恐怕我们项目里相关的代码都要这么写,我提供的这个方案只能作为临时的应急方案。
IntentService is a base class for {@link Service}s that handle asynchronous requests (expressed as {@link Intent}s) on demand. Clients send requests through {@link android.content.Context#startService(Intent)} calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
A call is a request that has been prepared for execution. A call can be canceled. As this object represents a single request/response pair (stream), it cannot be executed twice.
HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.
OkHttp is an HTTP client that’s efficient by default:
HTTP/2 support allows all requests to the same host to share a socket.
Response caching avoids the network completely for repeat requests.
Supports both synchronous blocking calls and async calls with callbacks.
OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses OkHttp will attempt alternate addresses if the first connect fails. This is necessary for IPv4+IPv6 and for services hosted in redundant data centers. OkHttp initiates new connections with modern TLS features (SNI, ALPN), and falls back to TLS 1.0 if the handshake fails.
Using OkHttp is easy. Its request/response API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks.
OkHttp supports Android 2.3 and above. For Java, the minimum requirement is 1.7.
Provides a simple {@link ClassLoader} implementation that operates on a list of files and directories in the local file system, but does not attempt to load classes from the network. Android uses this class for its system class loader and for its application class loader(s).
DexClassLoader.
A class loader that loads classes from {@code .jar} and {@code .apk} files containing a {@code classes.dex} entry. This can be used to execute code not installed as part of an application.
public Class findClass(String name){ for (Element element : dexElements) { DexFile dex = element.dexFile; if (dex != null) { Class clazz = dex.loadClassBinaryName(name, definingContext); if (clazz != null) { return clazz; } } } returnnull; }
再看DexFile的相关源码:
1 2 3 4 5
public Class loadClassBinaryName(String name, ClassLoader loader){ return defineClass(name, loader, mCookie); } privatenativestatic Class defineClass(String name, ClassLoader loader, int cookie);
Error:Execution failed for task ‘:app:processProductDebugManifest’.
Manifest merger failed : uses-sdk : minSdkVersion 14 cannot be smaller than version 18 declared in library......
Suggestion: use tools:overrideLibrary=”xx.xxx.xx” to force usage