Back to Vassonic

SonicRuntime (sdk 3.0.0 API)

sonic-android/docs/javadoc/com/tencent/sonic/sdk/SonicRuntime.html

3.1.113.2 KB
Original Source

跳过导航链接

com.tencent.sonic.sdk

类 SonicRuntime

  • java.lang.Object

    • com.tencent.sonic.sdk.SonicRuntime

public abstract classSonicRuntimeextends java.lang.Object

SonicRuntime is a class which interacts with the overall running information in the system, including Context, UA, ID (which is the unique identification for the saved data) and other information.

字段概要

字段 | 限定符和类型 | 字段和说明 | | --- | --- | | protected android.content.Context | context A context for this runtime, it's expected to be ApplicationContext | | protected static android.os.HandlerThread | fileHandlerThread This handle thread use to save sonic cache. |

构造器概要

构造器 | 构造器和说明 | | --- | | SonicRuntime(android.content.Context context) |

方法概要

所有方法 实例方法 抽象方法 具体方法 | 限定符和类型 | 方法和说明 | | --- | --- | | abstract java.lang.Object | createWebResourceResponse(java.lang.String mimeType, java.lang.String encoding, java.io.InputStream data, java.util.Map<java.lang.String,java.lang.String> headers) We add this method to decoupling webview since some application may use x5 webview or others. | | android.content.Context | getContext() | | abstract java.lang.String | getCookie(java.lang.String url) Get cookies of the input url, this method will be called before sonic session make a session connection to request data. | | abstract java.lang.String | getCurrentUserAccount() Get the current user account, this method will be called when makeSessionId's params is account related. | | android.os.Looper | getFileThreadLooper() Return the looper of HandleThread which use to save sonic cache. | | java.lang.String | getHostDirectAddress(java.lang.String url) Get the direct address of a url(host),format as[ip:port],the default http port is 80 and 443 for https. | | java.util.Set<java.lang.String> | getQueryParameterNames(android.net.Uri uri) Returns a set of the unique names of all query parameters. | | java.io.File | getSonicCacheDir() The sonic cache root dir which sonic cache such like .html/.template/.data will be storage. | | java.io.File | getSonicResourceCacheDir() The resource cache root dir which resource cache will be storage. | | android.content.SharedPreferences | getSonicSharedPreferences() get SharedPreferences of sonic. | | abstract java.lang.String | getUserAgent() Get user agent of current runtime, this method will be called before sonic session make a session connection to request data. | | abstract boolean | isNetworkValid() This method is used to judge is network valid or not | | abstract boolean | isSonicUrl(java.lang.String url) This method is used to judge the input url is support sonic or not, when this method return true, it means it's allow to create a sonic session for this url. | | abstract void | log(java.lang.String tag, int level, java.lang.String message) | | java.lang.String | makeSessionId(java.lang.String url, boolean isAccountRelated) Make a unique session id for the url, it can be account related. | | abstract void | notifyError(SonicSessionClient client, java.lang.String url, int errorCode) Notify error for host application to do report or statics | | void | postTaskToMainThread(java.lang.Runnable task, long delayMillis) Post a task in main thread | | void | postTaskToSessionThread(java.lang.Runnable task) Post a task to session thread(a high priority thread is better) | | abstract void | postTaskToThread(java.lang.Runnable task, long delayMillis) Post a task to the thread(a io thread is better) which used to separate template and data. | | abstract boolean | setCookie(java.lang.String url, java.util.List<java.lang.String> cookies) Set cookies to webview after session connection response with cookies in it's headers. | | boolean | shouldLog(int level) Logger function | | abstract void | showToast(java.lang.CharSequence text, int duration) Show toast |

- 

从类继承的方法 java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

字段详细资料

- 

context

protected final android.content.Context context

A context for this runtime, it's expected to be ApplicationContext

- 

fileHandlerThread

protected static volatile android.os.HandlerThread fileHandlerThread

This handle thread use to save sonic cache.

构造器详细资料

- 

SonicRuntime

public SonicRuntime(android.content.Context context)

方法详细资料

- 

getContext

public android.content.Context getContext()
- 

makeSessionId

public java.lang.String makeSessionId(java.lang.String url,
                                      boolean isAccountRelated)

Make a unique session id for the url, it can be account related. 参数:url - Url which need to make session idisAccountRelated - Is account related or not返回:A unique session id

- 

getQueryParameterNames

public java.util.Set<java.lang.String> getQueryParameterNames(android.net.Uri uri)

Returns a set of the unique names of all query parameters. Iterating over the set will return the names in order of their first occurrence. 参数:uri - The uri返回:A set of decoded names抛出:java.lang.UnsupportedOperationException - if this isn't a hierarchical URI

- 

shouldLog

public boolean shouldLog(int level)

Logger function 参数:level - Level of this log,such like Log.DEBUG.返回:Should log or not

- 

log

public abstract void log(java.lang.String tag,
                         int level,
                         java.lang.String message)
- 

getCookie

public abstract java.lang.String getCookie(java.lang.String url)

Get cookies of the input url, this method will be called before sonic session make a session connection to request data. 参数:url - The url which need to get cookies返回:The cookies for current input url

- 

setCookie

public abstract boolean setCookie(java.lang.String url,
                                  java.util.List<java.lang.String> cookies)

Set cookies to webview after session connection response with cookies in it's headers. 参数:url - The url which need to set cookiescookies - The cookies for current input url返回:Set cookie success or not

- 

getUserAgent

public abstract java.lang.String getUserAgent()

Get user agent of current runtime, this method will be called before sonic session make a session connection to request data.(sonic sdk info such like "sonic-sdk-version/2.0.0" will be added to this user agent.) 返回:The user agent

- 

getSonicCacheDir

public java.io.File getSonicCacheDir()

The sonic cache root dir which sonic cache such like .html/.template/.data will be storage. it's expected to be a dir in /data dir for security. 返回:The root cache dir.

- 

getSonicResourceCacheDir

public java.io.File getSonicResourceCacheDir()

The resource cache root dir which resource cache will be storage. it's expected to be a dir in /sdcard dir for security. 返回:The root cache dir.

- 

getSonicSharedPreferences

public android.content.SharedPreferences getSonicSharedPreferences()

get SharedPreferences of sonic. 返回:the sp

- 

getCurrentUserAccount

public abstract java.lang.String getCurrentUserAccount()

Get the current user account, this method will be called when makeSessionId's params is account related. 返回:Current user account

- 

isSonicUrl

public abstract boolean isSonicUrl(java.lang.String url)

This method is used to judge the input url is support sonic or not, when this method return true, it means it's allow to create a sonic session for this url. e.g. In mobile QQ, it will judge url params contain sonic=1 or not, if contains it will return true, others return false. 参数:url - The url which need to judge返回:Return is sonic url or not

- 

createWebResourceResponse

public abstract java.lang.Object createWebResourceResponse(java.lang.String mimeType,
                                                           java.lang.String encoding,
                                                           java.io.InputStream data,
                                                           java.util.Map<java.lang.String,java.lang.String> headers)

We add this method to decoupling webview since some application may use x5 webview or others. e.g. If u use a system webview, just call new android.webkit.WebResourceResponse Constructs a resource response with the given MIME type, encoding, and input stream. Callers must implement InputStream.read(byte[]) for the input stream. 参数:mimeType - The resource response's MIME type, for example text/htmlencoding - The resource response's encodingdata - The input stream that provides the resource response's data. Must not be a StringBufferInputStream.headers - The headers返回:The response to kernel

- 

isNetworkValid

public abstract boolean isNetworkValid()

This method is used to judge is network valid or not 返回:Network valid or not

- 

getHostDirectAddress

public java.lang.String getHostDirectAddress(java.lang.String url)

Get the direct address of a url(host),format as[ip:port],the default http port is 80 and 443 for https. 参数:url - The input url which need to get direct address返回:Return a valid direct address or null.

- 

showToast

public abstract void showToast(java.lang.CharSequence text,
                               int duration)

Show toast 参数:text - Contentduration - See Toast.LENGTH_SHORT/Toast.LENGTH_LONG

- 

postTaskToThread

public abstract void postTaskToThread(java.lang.Runnable task,
                                      long delayMillis)

Post a task to the thread(a io thread is better) which used to separate template and data. 参数:task - A runnable taskdelayMillis - The delay (in milliseconds) until the Runnable will be executed.

- 

postTaskToSessionThread

public void postTaskToSessionThread(java.lang.Runnable task)

Post a task to session thread(a high priority thread is better) 参数:task - A runnable task

- 

postTaskToMainThread

public void postTaskToMainThread(java.lang.Runnable task,
                                 long delayMillis)

Post a task in main thread 参数:task - A runnable taskdelayMillis - Delay millis

- 

getFileThreadLooper

public android.os.Looper getFileThreadLooper()

Return the looper of HandleThread which use to save sonic cache. 返回:The looper of HandleThread which use to save sonic cache.

- 

notifyError

public abstract void notifyError([SonicSessionClient](../../../../com/tencent/sonic/sdk/SonicSessionClient.html "com.tencent.sonic.sdk中的类")client,
                                 java.lang.String url,
                                 int errorCode)

Notify error for host application to do report or statics 参数:client - The error clienturl - The error urlerrorCode - Error code

跳过导航链接