Most visited

Recently visited

Added in API level 1
Deprecated since API level 24

RenamingDelegatingContext

public class RenamingDelegatingContext
extends ContextWrapper

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.test.RenamingDelegatingContext


此类在API级别24中已被弃用。
新的测试应该使用Android Testing Support Library编写

这是一个授予给定上下文的类,但是使用重命名的数据库/文件名(前缀带有给定前缀的默认名称)执行数据库和文件操作。

Summary

Inherited constants

From class android.content.Context

Public constructors

RenamingDelegatingContext(Context context, String filePrefix)
RenamingDelegatingContext(Context context, Context fileContext, String filePrefix)

Public methods

String[] databaseList()

返回一个字符串数组,命名与此Context的应用程序包关联的专用数据库。

boolean deleteDatabase(String name)

删除与此Context的应用程序包关联的现有私有SQLiteDatabase。

boolean deleteFile(String name)

删除与此Context的应用程序包关联的给定私人文件。

String[] fileList()

返回一个字符串数组,命名与此Context的应用程序包关联的私有文件。

File getCacheDir()

为了支持对getCacheDir()的调用,我们创建了一个临时缓存dir(在真正的缓存中)并返回它。

File getDatabasePath(String name)

返回存储使用 openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory)创建的数据库的文件系统上的绝对路径。

String getDatabasePrefix()
File getFileStreamPath(String name)

返回存储使用 openFileOutput(String, int)创建的文件的文件系统上的绝对路径。

void makeExistingFilesAndDbsAccessible()

使可访问所有文件和数据库的名称与传递给构造函数的filePrefix匹配。

FileInputStream openFileInput(String name)

打开与此Context的应用程序包关联的私人文件以供阅读。

FileOutputStream openFileOutput(String name, int mode)

打开与此Context的应用程序包关联的私有文件以进行写入。

SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory)

打开与此Context的应用程序包关联的新私有SQLiteDatabase。

SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)

打开与此Context的应用程序包关联的新私有SQLiteDatabase。

static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)
static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix)

Inherited methods

From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object

Public constructors

RenamingDelegatingContext

Added in API level 1
RenamingDelegatingContext (Context context, 
                String filePrefix)

Parameters
context Context: : the context that will be delegated.
filePrefix String: : a prefix with which database and file names will be prefixed.

RenamingDelegatingContext

Added in API level 1
RenamingDelegatingContext (Context context, 
                Context fileContext, 
                String filePrefix)

Parameters
context Context: : the context that will be delegated.
fileContext Context: : the context that file and db methods will be delegated to
filePrefix String: : a prefix with which database and file names will be prefixed.

Public methods

databaseList

Added in API level 1
String[] databaseList ()

返回一个字符串数组,命名与此Context的应用程序包关联的专用数据库。

Returns
String[] Array of strings naming the private databases.

deleteDatabase

Added in API level 1
boolean deleteDatabase (String name)

删除与此Context的应用程序包关联的现有私有SQLiteDatabase。

Parameters
name String: The name (unique in the application package) of the database.
Returns
boolean true if the database was successfully deleted; else false.

deleteFile

Added in API level 1
boolean deleteFile (String name)

删除与此Context的应用程序包关联的给定私人文件。

Parameters
name String: The name of the file to delete; can not contain path separators.
Returns
boolean true if the file was successfully deleted; else false.

fileList

Added in API level 1
String[] fileList ()

返回一个字符串数组,命名与此Context的应用程序包关联的私有文件。

Returns
String[] Array of strings naming the private files.

getCacheDir

Added in API level 1
File getCacheDir ()

为了支持对getCacheDir()的调用,我们创建了一个临时缓存dir(在真正的缓存中)并返回它。 该代码基本上是getCacheDir(),除了它使用真正的缓存目录作为父目录并在其中创建测试缓存目录。

Returns
File The path of the directory holding application cache files.

getDatabasePath

Added in API level 1
File getDatabasePath (String name)

返回存储使用 openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory)创建的数据库的文件系统上的绝对路径。

如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而改变,因此只应保留相对路径。

Parameters
name String: The name of the database for which you would like to get its path.
Returns
File An absolute path to the given database.

getDatabasePrefix

Added in API level 1
String getDatabasePrefix ()

Returns
String

getFileStreamPath

Added in API level 1
File getFileStreamPath (String name)

返回存储使用 openFileOutput(String, int)创建的文件的文件系统上的绝对路径。

如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而改变,因此只应保留相对路径。

Parameters
name String: The name of the file for which you would like to get its path.
Returns
File An absolute path to the given file.

makeExistingFilesAndDbsAccessible

Added in API level 1
void makeExistingFilesAndDbsAccessible ()

使可访问所有文件和数据库的名称与传递给构造函数的filePrefix匹配。 通常只有通过此上下文创建的文件和数据库才可访问。

openFileInput

Added in API level 1
FileInputStream openFileInput (String name)

打开与此Context的应用程序包关联的私人文件以供阅读。

Parameters
name String: The name of the file to open; can not contain path separators.
Returns
FileInputStream The resulting FileInputStream.
Throws
FileNotFoundException

openFileOutput

Added in API level 1
FileOutputStream openFileOutput (String name, 
                int mode)

打开与此Context的应用程序包关联的私有文件以进行写入。 如果该文件不存在,则创建该文件。

调用应用程序无需额外的权限来读取或写入返回的文件。

Parameters
name String: The name of the file to open; can not contain path separators.
mode int: Operating mode. Use 0 or MODE_PRIVATE for the default operation. Use MODE_APPEND to append to an existing file.
Returns
FileOutputStream The resulting FileOutputStream.
Throws
FileNotFoundException

openOrCreateDatabase

Added in API level 1
SQLiteDatabase openOrCreateDatabase (String name, 
                int mode, 
                SQLiteDatabase.CursorFactory factory)

打开与此Context的应用程序包关联的新私有SQLiteDatabase。 如果数据库文件不存在,请创建它。

Parameters
name String: The name (unique in the application package) of the database.
mode int: Operating mode. Use 0 or MODE_PRIVATE for the default operation. Use MODE_ENABLE_WRITE_AHEAD_LOGGING to enable write-ahead logging by default. Use MODE_NO_LOCALIZED_COLLATORS to disable localized collators.
factory SQLiteDatabase.CursorFactory: An optional factory class that is called to instantiate a cursor when query is called.
Returns
SQLiteDatabase The contents of a newly created database with the given name.

openOrCreateDatabase

Added in API level 11
SQLiteDatabase openOrCreateDatabase (String name, 
                int mode, 
                SQLiteDatabase.CursorFactory factory, 
                DatabaseErrorHandler errorHandler)

打开与此Context的应用程序包关联的新私有SQLiteDatabase。 如果数据库文件不存在,则创建该文件。

接受输入参数:当sqlite报告数据库损坏时,用于处理腐败的具体实例 DatabaseErrorHandler

Parameters
name String: The name (unique in the application package) of the database.
mode int: Operating mode. Use 0 or MODE_PRIVATE for the default operation. Use MODE_ENABLE_WRITE_AHEAD_LOGGING to enable write-ahead logging by default. Use MODE_NO_LOCALIZED_COLLATORS to disable localized collators.
factory SQLiteDatabase.CursorFactory: An optional factory class that is called to instantiate a cursor when query is called.
errorHandler DatabaseErrorHandler: the DatabaseErrorHandler to be used when sqlite reports database corruption. if null, DefaultDatabaseErrorHandler is assumed.
Returns
SQLiteDatabase The contents of a newly created database with the given name.

providerWithRenamedContext

Added in API level 1
T providerWithRenamedContext (Class<T> contentProvider, 
                Context c, 
                String filePrefix, 
                boolean allowAccessToExistingFilesAndDbs)

Parameters
contentProvider Class
c Context
filePrefix String
allowAccessToExistingFilesAndDbs boolean
Returns
T
Throws
IllegalAccessException
InstantiationException

providerWithRenamedContext

Added in API level 1
T providerWithRenamedContext (Class<T> contentProvider, 
                Context c, 
                String filePrefix)

Parameters
contentProvider Class
c Context
filePrefix String
Returns
T
Throws
IllegalAccessException
InstantiationException

Hooray!