本文整理汇总了Java中android.content.ContentProvider.insert方法的典型用法代码示例。如果您正苦于以下问题:Java ContentProvider.insert方法的具体用法?Java ContentProvider.insert怎么用?Java ContentProvider.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentProvider
的用法示例。
在下文中一共展示了ContentProvider.insert方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBadViewUri
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testBadViewUri() throws Exception {
ContentProvider provider = this.getProvider();
ContentValues values = new ContentValues();
values.put("query", "this is a test");
values.put("date_synced", "1/1/1970");
try
{
provider.insert(
Uri.withAppendedPath(HVContentContract.CONTENT_URI, "records/42/views/43/this-semgment-is-bad"),
values);
Assert.fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
//ignore
}
}
示例2: syncData
import android.content.ContentProvider; //导入方法依赖的package包/类
/**
* Syncs a list of IData items with the ContentProvider
* @param provider A ContentProvider for querying the database in an API like fashion
* @param models The data items that need syncing
* @throws RemoteException
* @see be.ana.nmct.multimania.model.IData
*/
public static void syncData(ContentProvider provider,List<IData> models) throws RemoteException {
for(IData model: models){
boolean exists = false;
if(model.getId()!=-1){
exists = provider.query(model.getContentUriWithId(),null,null,null,null).getCount()>0;
}
if(exists){
provider.update(model.getContentUri(),
model.getContentValues(),
BaseColumns._ID+"="+model.getId(),
null);
}else{
provider.insert(model.getContentUri(),
model.getContentValues());
}
}
}
示例3: insert
import android.content.ContentProvider; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues values) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.insert(pluginUri, values);
}
return uri;
}
示例4: insert
import android.content.ContentProvider; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues values) {
PluginProviderHelper.PluginUri pu = mHelper.toPluginUri(uri);
if (pu == null) {
return null;
}
ContentProvider cp = mHelper.getProvider(pu);
if (cp == null) {
return null;
}
return cp.insert(pu.transferredUri, values);
}
示例5: insert
import android.content.ContentProvider; //导入方法依赖的package包/类
@Override
public Uri insert(Uri uri, ContentValues contentValues) {
ContentProvider mContentProvider = getContentProvider();
if (mContentProvider != null) {
return mContentProvider.insert(uri, contentValues);
}
return null;
}
示例6: insert
import android.content.ContentProvider; //导入方法依赖的package包/类
@Implementation
public final Uri insert(Uri url, ContentValues values) {
ContentProvider provider = getProvider(url);
if (provider != null) {
return provider.insert(url, values);
} else {
InsertStatement insertStatement = new InsertStatement(url, new ContentValues(values));
insertStatements.add(insertStatement);
return Uri.parse(url.toString() + "/" + ++nextDatabaseIdForInserts);
}
}
示例7: testInsertAndRead
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testInsertAndRead() {
ContentProvider provider = getProvider();
// Data
SmsLog vo = new SmsLog()//
.setPhone("0601020304") //
.setAction(SmsMessageActionEnum.GEOPING_REQUEST)//
.setTime(java.lang.System.currentTimeMillis()) //
.setMessage("th7lhawmo,z31,y1e14h,xt3jbc,aa,s0,pg,b1p") //
.setSmsLogType(SmsLogTypeEnum.SEND_ACK);
ContentValues values = SmsLogHelper.getContentValues(vo);
// Insert
Uri uri = provider.insert(CONTENT_URI, values);
// Select
Cursor cursor = provider.query(uri, null, null, null, null);
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
SmsLogHelper helper = new SmsLogHelper().initWrapper(cursor);
SmsLog voDb = helper.getEntity(cursor);
assertEquals(Long.valueOf(uri.getLastPathSegment()).longValue(), voDb.id);
assertEquals(vo.phone, voDb.phone);
assertEquals(vo.action, voDb.action);
assertEquals(vo.time, voDb.time);
assertEquals(vo.message, voDb.message);
assertEquals(vo.smsLogType, voDb.smsLogType);
} finally {
cursor.close();
}
}
示例8: testInsertAndRead
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testInsertAndRead() {
ContentProvider provider = getProvider();
// Data
Pairing vo = new Pairing()//
.setPhone("0601020304") //
.setShowNotification(true)//
.setPairingTime(System.currentTimeMillis())
.setAuthorizeType(PairingAuthorizeTypeEnum.AUTHORIZE_ALWAYS);
ContentValues values = PairingHelper.getContentValues(vo);
// Insert
Uri uri = provider.insert(CONTENT_URI, values);
// Select
Cursor cursor = provider.query(uri, null, null, null, null);
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
PairingHelper helper = new PairingHelper().initWrapper(cursor);
Pairing voDb = helper.getEntity(cursor);
assertEquals(Long.valueOf(uri.getLastPathSegment()).longValue(), voDb.id);
assertEquals(vo.phone, voDb.phone);
assertEquals(vo.showNotification, voDb.showNotification);
assertEquals(vo.authorizeType, voDb.authorizeType);
assertEquals(vo.pairingTime, voDb.pairingTime);
} finally {
cursor.close();
}
}
示例9: testInsertAndSearchForPhone
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testInsertAndSearchForPhone() {
ContentProvider provider = getProvider();
// Data
Pairing vo = new Pairing()//
.setPhone("0601020304") //
.setShowNotification(true)//
.setPairingTime(System.currentTimeMillis())
.setAuthorizeType(PairingAuthorizeTypeEnum.AUTHORIZE_ALWAYS);
ContentValues values = PairingHelper.getContentValues(vo);
// Insert
Uri uri = provider.insert(CONTENT_URI, values);
// Select
Uri searchPhoneUri01 = Uri.withAppendedPath(PairingProvider.Constants.CONTENT_URI_PHONE_FILTER, Uri.encode("+33601020304"));
Uri searchPhoneUri02 = Uri.withAppendedPath(PairingProvider.Constants.CONTENT_URI_PHONE_FILTER, Uri.encode("0601020304"));
for (Uri searchPhoneUri : new Uri[] { searchPhoneUri01, searchPhoneUri02 }) {
Cursor cursor = provider.query(searchPhoneUri, null, null, null, null);
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
PairingHelper helper = new PairingHelper().initWrapper(cursor);
Pairing voDb = helper.getEntity(cursor);
assertEquals(Long.valueOf(uri.getLastPathSegment()).longValue(), voDb.id);
assertEquals(vo.phone, voDb.phone);
assertEquals(vo.showNotification, voDb.showNotification);
assertEquals(vo.pairingTime, voDb.pairingTime);
assertEquals(vo.authorizeType, voDb.authorizeType);
} finally {
cursor.close();
}
}
}
示例10: testInsertAndRead
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testInsertAndRead() {
ContentProvider provider = getProvider();
// Data
for (GeoTrack vo : new GeoTrack[] { getGeoTrack01(PROVIDER_GPS), getGeoTrack01(PROVIDER_NETWORK)}) {
GeoTrackHelper helper = new GeoTrackHelper();
ContentValues values = helper.getContentValues(vo);
// Insert
Uri uri = provider.insert(CONTENT_URI, values);
// Select
Cursor cursor = provider.query(uri, null, null, null, null);
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
helper.initWrapper(cursor);
GeoTrack voDb = helper.getEntity(cursor);
assertEquals(Long.valueOf(uri.getLastPathSegment()).longValue(), voDb.id);
assertEquals(vo.phone, voDb.phone);
assertEquals(vo.getTime(), voDb.getTime());
assertEquals(vo.getLatitudeE6(), voDb.getLatitudeE6());
assertEquals(vo.getLongitude(), voDb.getLongitude());
assertEquals(vo.getAccuracy(), voDb.getAccuracy());
assertEquals(vo.getAltitude(), voDb.getAltitude());
assertEquals(vo.getSpeed(), voDb.getSpeed());
assertEquals(vo.getBearing(), voDb.getBearing());
assertEquals(vo.address, voDb.address);
} finally {
cursor.close();
}
}
}
示例11: testInsertAndRead
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testInsertAndRead() {
ContentProvider provider = getProvider();
// Data
Person vo = new Person()//
.setPhone("0601020304") //
.setColor(Color.GREEN)//
.setPairingTime(System.currentTimeMillis())
.setDisplayName("Lena Sj��blom");
ContentValues values = PersonHelper.getContentValues(vo);
// Insert
Uri uri = provider.insert(CONTENT_URI, values);
// Select
Cursor cursor = provider.query(uri, null, null, null, null);
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
PersonHelper helper = new PersonHelper().initWrapper(cursor);
Person voDb = helper.getEntity(cursor);
assertEquals(Long.valueOf(uri.getLastPathSegment()).longValue(), voDb.id);
assertEquals(vo.phone, voDb.phone);
assertEquals(vo.color, voDb.color);
assertEquals(vo.displayName, voDb.displayName);
assertEquals(vo.pairingTime, voDb.pairingTime);
} finally {
cursor.close();
}
}
示例12: testInsertAndSearchForPhone
import android.content.ContentProvider; //导入方法依赖的package包/类
public void testInsertAndSearchForPhone() {
ContentProvider provider = getProvider();
// Data
Person vo = new Person()//
.setPhone("0601020304") //
.setColor(Color.GREEN)//
.setPairingTime(System.currentTimeMillis())
.setDisplayName("Lena Sj��blom");
ContentValues values = PersonHelper.getContentValues(vo);
// Insert
Uri uri = provider.insert(CONTENT_URI, values);
// Select
Uri searchPhoneUri01 = Uri.withAppendedPath(PersonProvider.Constants.CONTENT_URI_PHONE_FILTER, Uri.encode("+33601020304"));
Uri searchPhoneUri02 = Uri.withAppendedPath(PersonProvider.Constants.CONTENT_URI_PHONE_FILTER, Uri.encode("0601020304"));
for (Uri searchPhoneUri : new Uri[] { searchPhoneUri01, searchPhoneUri02 }) {
Cursor cursor = provider.query(searchPhoneUri, null, null, null, null);
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
PersonHelper helper = new PersonHelper().initWrapper(cursor);
Person voDb = helper.getEntity(cursor);
assertEquals(Long.valueOf(uri.getLastPathSegment()).longValue(), voDb.id);
assertEquals(vo.phone, voDb.phone);
assertEquals(vo.color, voDb.color);
assertEquals(vo.pairingTime, voDb.pairingTime);
assertEquals(vo.displayName, voDb.displayName);
} finally {
cursor.close();
}
}
}