本文整理汇总了Java中com.localytics.android.LocalyticsProvider.ApiKeysDbColumns类的典型用法代码示例。如果您正苦于以下问题:Java ApiKeysDbColumns类的具体用法?Java ApiKeysDbColumns怎么用?Java ApiKeysDbColumns使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApiKeysDbColumns类属于com.localytics.android.LocalyticsProvider包,在下文中一共展示了ApiKeysDbColumns类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: if
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Gets the creation time for an API key.
*
* @param provider Localytics database provider. Cannot be null.
* @param key Localytics API key. Cannot be null.
* @return The time in seconds since the Unix Epoch when the API key entry was created in the database.
* @throws RuntimeException if the API key entry doesn't exist in the database.
*/
/* package */static long getApiKeyCreationTime(final LocalyticsProvider provider, final String key)
{
Cursor cursor = null;
try
{
cursor = provider.query(ApiKeysDbColumns.TABLE_NAME, null, String.format("%s = ?", ApiKeysDbColumns.API_KEY), new String[] { key }, null); //$NON-NLS-1$
if (cursor.moveToFirst())
{
return Math.round((float) cursor.getLong(cursor.getColumnIndexOrThrow(ApiKeysDbColumns.CREATED_TIME)) / DateUtils.SECOND_IN_MILLIS);
}
/*
* This should never happen
*/
throw new RuntimeException("API key entry couldn't be found"); //$NON-NLS-1$
}
finally
{
if (null != cursor)
{
cursor.close();
}
}
}
示例2: if
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Set the opt-in/out-out state for all sessions using the current API key.
* <p>
* This method must only be called after {@link #init()} is called.
* <p>
* Note: This method is a private implementation detail. It is only made package accessible for unit testing purposes. The
* public interface is to send {@link #MESSAGE_OPT_OUT} to the Handler.
* <p>
* If a session is already open when an opt-out request is made, then data for the remainder of that session will be
* collected. For example, calls to {@link #tagEvent(String, Map)} and {@link #tagScreen(String)} will be recorded until
* {@link #close(Map)} is called.
* <p>
* If a session is not already open when an opt-out request is made, a new session is opened and closed by this method in
* order to cause the opt-out event to be uploaded.
*
* @param isOptingOut true if the user is opting out. False if the user is opting back in.
* @see #MESSAGE_OPT_OUT
*/
/* package */void optOut(final boolean isOptingOut)
{
if (Constants.IS_LOGGABLE)
{
Log.v(Constants.LOG_TAG, String.format("Requested opt-out state is %b", Boolean.valueOf(isOptingOut))); //$NON-NLS-1$
}
// Do nothing if opt-out is unchanged
if (isOptedOut(mProvider, mApiKey) == isOptingOut)
{
return;
}
if (null == getOpenSessionId(mProvider))
{
/*
* Force a session to contain the opt event
*/
open(true, null);
tagEvent(isOptingOut ? OPT_OUT_EVENT : OPT_IN_EVENT, null);
close(null);
}
else
{
tagEvent(isOptingOut ? OPT_OUT_EVENT : OPT_IN_EVENT, null);
}
final ContentValues values = new ContentValues();
values.put(ApiKeysDbColumns.OPT_OUT, Boolean.valueOf(isOptingOut));
mProvider.update(ApiKeysDbColumns.TABLE_NAME, values, SELECTION_OPT_IN_OUT, new String[]
{ Long.toString(mApiKeyId) });
}
示例3: if
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Set the opt-in/out-out state for all sessions using the current API key.
* <p>
* This method must only be called after {@link #init()} is called.
* <p>
* Note: This method is a private implementation detail. It is only made package accessible for unit testing purposes. The
* public interface is to send {@link #MESSAGE_OPT_OUT} to the Handler.
* <p>
* If a session is already open when an opt-out request is made, then data for the remainder of that session will be
* collected. For example, calls to {@link #tagEvent(String, Map)} and {@link #tagScreen(String)} will be recorded until
* {@link #close(Map)} is called.
* <p>
* If a session is not already open when an opt-out request is made, a new session is opened and closed by this method in
* order to cause the opt-out event to be uploaded.
*
* @param isOptingOut true if the user is opting out. False if the user is opting back in.
* @see #MESSAGE_OPT_OUT
*/
/* package */void optOut(final boolean isOptingOut)
{
if (Constants.IS_LOGGABLE)
{
Log.v(Constants.LOG_TAG, String.format("Requested opt-out state is %b", Boolean.valueOf(isOptingOut))); //$NON-NLS-1$
}
// Do nothing if opt-out is unchanged
if (isOptedOut(mProvider, mApiKey) == isOptingOut)
{
return;
}
if (null == getOpenSessionId(mProvider))
{
/*
* Force a session to contain the opt event
*/
open(true, null);
tagEvent(isOptingOut ? OPT_OUT_EVENT : OPT_IN_EVENT, null);
close(null);
}
else
{
tagEvent(isOptingOut ? OPT_OUT_EVENT : OPT_IN_EVENT, null);
}
final ContentValues values = new ContentValues();
values.put(ApiKeysDbColumns.OPT_OUT, Boolean.valueOf(isOptingOut));
mProvider.update(ApiKeysDbColumns.TABLE_NAME, values, SELECTION_OPT_IN_OUT, new String[]
{ Long.toString(mApiKeyId) });
}
示例4: getInstallationId
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Gets the installation ID of the API key.
*/
private static String getInstallationId(final LocalyticsProvider provider, final String apiKey)
{
Cursor cursor = null;
try
{
cursor = provider.query(ApiKeysDbColumns.TABLE_NAME, PROJECTION_GET_INSTALLATION_ID, SELECTION_GET_INSTALLATION_ID, new String[]
{ apiKey }, null);
if (cursor.moveToFirst())
{
return cursor.getString(cursor.getColumnIndexOrThrow(ApiKeysDbColumns.UUID));
}
}
finally
{
if (null != cursor)
{
cursor.close();
cursor = null;
}
}
/*
* This error case shouldn't normally happen
*/
if (Constants.IS_LOGGABLE)
{
Log.w(Constants.LOG_TAG, "Installation ID couldn't be found"); //$NON-NLS-1$
}
return null;
}
示例5: openNewSession
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Opens a new session. This is a helper method to {@link #open(boolean, Map)}.
*
* @effects Updates the database by creating a new entry in the {@link SessionsDbColumns} table.
* @param attributes Attributes to attach to the session. May be null. Cannot contain null or empty keys or values.
*/
private void openNewSession(final Map<String, String> attributes)
{
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final ContentValues values = new ContentValues();
values.put(SessionsDbColumns.API_KEY_REF, Long.valueOf(mApiKeyId));
values.put(SessionsDbColumns.SESSION_START_WALL_TIME, Long.valueOf(System.currentTimeMillis()));
values.put(SessionsDbColumns.UUID, UUID.randomUUID().toString());
values.put(SessionsDbColumns.APP_VERSION, DatapointHelper.getAppVersion(mContext));
values.put(SessionsDbColumns.ANDROID_SDK, Integer.valueOf(Constants.CURRENT_API_LEVEL));
values.put(SessionsDbColumns.ANDROID_VERSION, VERSION.RELEASE);
// Try and get the deviceId. If it is unavailable (or invalid) use the installation ID instead.
String deviceId = DatapointHelper.getAndroidIdHashOrNull(mContext);
if (null == deviceId)
{
Cursor cursor = null;
try
{
cursor = mProvider.query(ApiKeysDbColumns.TABLE_NAME, null, SELECTION_OPEN_NEW_SESSION, new String[]
{ mApiKey }, null);
if (cursor.moveToFirst())
{
deviceId = cursor.getString(cursor.getColumnIndexOrThrow(ApiKeysDbColumns.UUID));
}
}
finally
{
if (null != cursor)
{
cursor.close();
cursor = null;
}
}
}
values.put(SessionsDbColumns.DEVICE_ANDROID_ID_HASH, deviceId);
values.put(SessionsDbColumns.DEVICE_ANDROID_ID, DatapointHelper.getAndroidIdOrNull(mContext));
values.put(SessionsDbColumns.DEVICE_COUNTRY, telephonyManager.getSimCountryIso());
values.put(SessionsDbColumns.DEVICE_MANUFACTURER, DatapointHelper.getManufacturer());
values.put(SessionsDbColumns.DEVICE_MODEL, Build.MODEL);
values.put(SessionsDbColumns.DEVICE_SERIAL_NUMBER_HASH, DatapointHelper.getSerialNumberHashOrNull());
values.put(SessionsDbColumns.DEVICE_TELEPHONY_ID, DatapointHelper.getTelephonyDeviceIdOrNull(mContext));
values.putNull(SessionsDbColumns.DEVICE_TELEPHONY_ID_HASH);
values.put(SessionsDbColumns.DEVICE_WIFI_MAC_HASH, DatapointHelper.getWifiMacHashOrNull(mContext));
values.put(SessionsDbColumns.LOCALE_COUNTRY, Locale.getDefault().getCountry());
values.put(SessionsDbColumns.LOCALE_LANGUAGE, Locale.getDefault().getLanguage());
values.put(SessionsDbColumns.LOCALYTICS_LIBRARY_VERSION, Constants.LOCALYTICS_CLIENT_LIBRARY_VERSION);
values.put(SessionsDbColumns.LOCALYTICS_INSTALLATION_ID, getInstallationId(mProvider, mApiKey));
values.putNull(SessionsDbColumns.LATITUDE);
values.putNull(SessionsDbColumns.LONGITUDE);
values.put(SessionsDbColumns.NETWORK_CARRIER, telephonyManager.getNetworkOperatorName());
values.put(SessionsDbColumns.NETWORK_COUNTRY, telephonyManager.getNetworkCountryIso());
values.put(SessionsDbColumns.NETWORK_TYPE, DatapointHelper.getNetworkType(mContext, telephonyManager));
long sessionId = mProvider.insert(SessionsDbColumns.TABLE_NAME, values);
if (sessionId == -1)
{
throw new AssertionError("session insert failed"); //$NON-NLS-1$
}
tagEvent(OPEN_EVENT, attributes);
/*
* This is placed here so that the DatapointHelper has a chance to retrieve the old UUID before it is deleted.
*/
LocalyticsProvider.deleteOldFiles(mContext);
}
示例6: openNewSession
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Opens a new session. This is a helper method to {@link #open(boolean, Map)}.
*
* @effects Updates the database by creating a new entry in the {@link SessionsDbColumns} table.
* @param attributes Attributes to attach to the session. May be null. Cannot contain null or empty keys or values.
*/
private void openNewSession(final Map<String, String> attributes)
{
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final ContentValues values = new ContentValues();
values.put(SessionsDbColumns.API_KEY_REF, Long.valueOf(mApiKeyId));
values.put(SessionsDbColumns.SESSION_START_WALL_TIME, Long.valueOf(System.currentTimeMillis()));
values.put(SessionsDbColumns.UUID, UUID.randomUUID().toString());
values.put(SessionsDbColumns.APP_VERSION, DatapointHelper.getAppVersion(mContext));
values.put(SessionsDbColumns.ANDROID_SDK, Integer.valueOf(Constants.CURRENT_API_LEVEL));
values.put(SessionsDbColumns.ANDROID_VERSION, VERSION.RELEASE);
// Try and get the deviceId. If it is unavailable (or invalid) use the installation ID instead.
String deviceId = DatapointHelper.getAndroidIdHashOrNull(mContext);
if (null == deviceId)
{
Cursor cursor = null;
try
{
cursor = mProvider.query(ApiKeysDbColumns.TABLE_NAME, null, SELECTION_OPEN_NEW_SESSION, new String[]
{ mApiKey }, null);
if (cursor.moveToFirst())
{
deviceId = cursor.getString(cursor.getColumnIndexOrThrow(ApiKeysDbColumns.UUID));
}
}
finally
{
if (null != cursor)
{
cursor.close();
cursor = null;
}
}
}
values.put(SessionsDbColumns.DEVICE_ANDROID_ID_HASH, deviceId);
values.put(SessionsDbColumns.DEVICE_COUNTRY, telephonyManager.getSimCountryIso());
values.put(SessionsDbColumns.DEVICE_MANUFACTURER, DatapointHelper.getManufacturer());
values.put(SessionsDbColumns.DEVICE_MODEL, Build.MODEL);
values.put(SessionsDbColumns.DEVICE_SERIAL_NUMBER_HASH, DatapointHelper.getSerialNumberHashOrNull());
values.put(SessionsDbColumns.DEVICE_TELEPHONY_ID, DatapointHelper.getTelephonyDeviceIdOrNull(mContext));
values.put(SessionsDbColumns.DEVICE_TELEPHONY_ID_HASH, DatapointHelper.getTelephonyDeviceIdHashOrNull(mContext));
values.put(SessionsDbColumns.DEVICE_WIFI_MAC_HASH, DatapointHelper.getWifiMacHashOrNull(mContext));
values.put(SessionsDbColumns.LOCALE_COUNTRY, Locale.getDefault().getCountry());
values.put(SessionsDbColumns.LOCALE_LANGUAGE, Locale.getDefault().getLanguage());
values.put(SessionsDbColumns.LOCALYTICS_LIBRARY_VERSION, Constants.LOCALYTICS_CLIENT_LIBRARY_VERSION);
values.put(SessionsDbColumns.LOCALYTICS_INSTALLATION_ID, getInstallationId(mProvider, mApiKey));
values.putNull(SessionsDbColumns.LATITUDE);
values.putNull(SessionsDbColumns.LONGITUDE);
values.put(SessionsDbColumns.NETWORK_CARRIER, telephonyManager.getNetworkOperatorName());
values.put(SessionsDbColumns.NETWORK_COUNTRY, telephonyManager.getNetworkCountryIso());
values.put(SessionsDbColumns.NETWORK_TYPE, DatapointHelper.getNetworkType(mContext, telephonyManager));
long sessionId = mProvider.insert(SessionsDbColumns.TABLE_NAME, values);
if (sessionId == -1)
{
throw new AssertionError("session insert failed"); //$NON-NLS-1$
}
tagEvent(OPEN_EVENT, attributes);
/*
* This is placed here so that the DatapointHelper has a chance to retrieve the old UUID before it is deleted.
*/
LocalyticsProvider.deleteOldFiles(mContext);
}
示例7: init
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Initialize the handler post construction.
* <p>
* This method must only be called once.
* <p>
* Note: This method is a private implementation detail. It is only made public for unit testing purposes. The public
* interface is to send {@link #MESSAGE_INIT} to the Handler.
*
* @see #MESSAGE_INIT
*/
public void init()
{
mProvider = LocalyticsProvider.getInstance(mContext, mApiKey);
/*
* Check whether this session key is opted out
*/
Cursor cursor = null;
try
{
cursor = mProvider.query(ApiKeysDbColumns.TABLE_NAME, new String[]
{
ApiKeysDbColumns._ID,
ApiKeysDbColumns.OPT_OUT }, String.format("%s = ?", ApiKeysDbColumns.API_KEY), new String[] //$NON-NLS-1$
{ mApiKey }, null);
if (cursor.moveToFirst())
{
// API key was previously created
if (Constants.IS_LOGGABLE)
{
Log.v(Constants.LOG_TAG, String.format("Loading details for API key %s", mApiKey)); //$NON-NLS-1$
}
mApiKeyId = cursor.getLong(cursor.getColumnIndexOrThrow(ApiKeysDbColumns._ID));
mIsOptedOut = cursor.getInt(cursor.getColumnIndexOrThrow(ApiKeysDbColumns.OPT_OUT)) != 0;
}
else
{
// perform first-time initialization of API key
if (Constants.IS_LOGGABLE)
{
Log.v(Constants.LOG_TAG, String.format("Performing first-time initialization for new API key %s", mApiKey)); //$NON-NLS-1$
}
final ContentValues values = new ContentValues();
values.put(ApiKeysDbColumns.API_KEY, mApiKey);
values.put(ApiKeysDbColumns.UUID, UUID.randomUUID().toString());
values.put(ApiKeysDbColumns.OPT_OUT, Boolean.FALSE);
values.put(ApiKeysDbColumns.CREATED_TIME, Long.valueOf(System.currentTimeMillis()));
mApiKeyId = mProvider.insert(ApiKeysDbColumns.TABLE_NAME, values);
}
}
finally
{
if (cursor != null)
{
cursor.close();
cursor = null;
}
}
if (!sIsUploadingMap.containsKey(mApiKey))
{
sIsUploadingMap.put(mApiKey, Boolean.FALSE);
}
/*
* Perform lazy initialization of the UploadHandler
*/
mUploadHandler = new UploadHandler(mContext, this, mApiKey, sUploadHandlerThread.getLooper());
}
示例8: openNewSession
import com.localytics.android.LocalyticsProvider.ApiKeysDbColumns; //导入依赖的package包/类
/**
* Opens a new session. This is a helper method to {@link #open(boolean)}.
*
* @effects Updates the database by creating a new entry in the {@link SessionsDbColumns} table.
*/
private void openNewSession()
{
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final ContentValues values = new ContentValues();
values.put(SessionsDbColumns.API_KEY_REF, Long.valueOf(mApiKeyId));
values.put(SessionsDbColumns.SESSION_START_WALL_TIME, Long.valueOf(System.currentTimeMillis()));
values.put(SessionsDbColumns.UUID, UUID.randomUUID().toString());
values.put(SessionsDbColumns.APP_VERSION, DatapointHelper.getAppVersion(mContext));
values.put(SessionsDbColumns.ANDROID_SDK, Integer.valueOf(Constants.CURRENT_API_LEVEL));
values.put(SessionsDbColumns.ANDROID_VERSION, VERSION.RELEASE);
// Try and get the deviceId. If it is unavailable (or invalid) use the installation ID instead.
String deviceId = DatapointHelper.getAndroidIdHashOrNull(mContext);
if (deviceId == null)
{
Cursor cursor = null;
try
{
cursor = mProvider.query(ApiKeysDbColumns.TABLE_NAME, null, String.format("%s = ?", ApiKeysDbColumns.API_KEY), new String[] { mApiKey }, null); //$NON-NLS-1$
if (cursor.moveToFirst())
{
deviceId = cursor.getString(cursor.getColumnIndexOrThrow(ApiKeysDbColumns.UUID));
}
}
finally
{
if (null != cursor)
{
cursor.close();
cursor = null;
}
}
}
values.put(SessionsDbColumns.DEVICE_ANDROID_ID_HASH, deviceId);
values.put(SessionsDbColumns.DEVICE_COUNTRY, telephonyManager.getSimCountryIso());
values.put(SessionsDbColumns.DEVICE_MANUFACTURER, DatapointHelper.getManufacturer());
values.put(SessionsDbColumns.DEVICE_MODEL, Build.MODEL);
values.put(SessionsDbColumns.DEVICE_SERIAL_NUMBER_HASH, DatapointHelper.getSerialNumberHashOrNull());
values.put(SessionsDbColumns.DEVICE_TELEPHONY_ID_HASH, DatapointHelper.getTelephonyDeviceIdHashOrNull(mContext));
values.put(SessionsDbColumns.LOCALE_COUNTRY, Locale.getDefault().getCountry());
values.put(SessionsDbColumns.LOCALE_LANGUAGE, Locale.getDefault().getLanguage());
values.put(SessionsDbColumns.LOCALYTICS_LIBRARY_VERSION, Constants.LOCALYTICS_CLIENT_LIBRARY_VERSION);
values.putNull(SessionsDbColumns.LATITUDE);
values.putNull(SessionsDbColumns.LONGITUDE);
values.put(SessionsDbColumns.NETWORK_CARRIER, telephonyManager.getNetworkOperatorName());
values.put(SessionsDbColumns.NETWORK_COUNTRY, telephonyManager.getNetworkCountryIso());
values.put(SessionsDbColumns.NETWORK_TYPE, DatapointHelper.getNetworkType(mContext, telephonyManager));
mProvider.runBatchTransaction(new Runnable()
{
@Override
public void run()
{
mSessionId = mProvider.insert(SessionsDbColumns.TABLE_NAME, values);
if (mSessionId == -1)
{
throw new RuntimeException("session insert failed"); //$NON-NLS-1$
}
tagEvent(OPEN_EVENT, null);
}
});
/*
* This is placed here so that the DatapointHelper has a chance to retrieve the old UUID before it is deleted.
*/
LocalyticsProvider.deleteOldFiles(mContext);
}