当前位置: 首页>>代码示例>>Java>>正文


Java ContentProvider类代码示例

本文整理汇总了Java中android.content.ContentProvider的典型用法代码示例。如果您正苦于以下问题:Java ContentProvider类的具体用法?Java ContentProvider怎么用?Java ContentProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentProvider类属于android.content包,在下文中一共展示了ContentProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import android.content.ContentProvider; //导入依赖的package包/类
@Override
public Bundle call(String method, String arg, Bundle extras) {
    Log.d(TAG, "call " + method + " with extras : " + extras);

    if (extras == null || extras.getString(KEY_WRAPPER_URI) == null) {
        return null;
    }

    Uri uri = Uri.parse(extras.getString(KEY_WRAPPER_URI));
    ContentProvider provider = getContentProvider(uri);
    if (provider != null) {
        return provider.call(method, arg, extras);
    }

    return null;
}
 
开发者ID:didi,项目名称:VirtualAPK,代码行数:17,代码来源:RemoteContentProvider.java

示例2: applyBatch

import android.content.ContentProvider; //导入依赖的package包/类
@NonNull
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    try {
        Field uriField = ContentProviderOperation.class.getDeclaredField("mUri");
        uriField.setAccessible(true);
        for (ContentProviderOperation operation : operations) {
            Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI));
            uriField.set(operation, pluginUri);
        }
    } catch (Exception e) {
        return new ContentProviderResult[0];
    }

    if (operations.size() > 0) {
        ContentProvider provider = getContentProvider(operations.get(0).getUri());
        if (provider != null) {
            return provider.applyBatch(operations);
        }
    }

    return new ContentProviderResult[0];
}
 
开发者ID:didi,项目名称:VirtualAPK,代码行数:24,代码来源:RemoteContentProvider.java

示例3: 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
	}
}
 
开发者ID:Microsoft,项目名称:healthvault-java-sdk,代码行数:18,代码来源:ContentProviderTest.java

示例4: resolveContext

import android.content.ContentProvider; //导入依赖的package包/类
@Override
@Nullable
public Context resolveContext(Object object) throws Exception {
	if (object instanceof View) {
		return ((View) object).getContext();
	} else if (object instanceof Fragment) {
		return ((Fragment) object).getActivity();
	} else if (object instanceof Context) {
		return (Context) object;
	} else if (object instanceof ContentProvider) {
		return ((ContentProvider) object).getContext();
	} else if (object instanceof ContextProvider) {
		return ((ContextProvider) object).getContext();
	} else if (object instanceof ViewProvider) {
		return ((ViewProvider) object).getView().getContext();
	} else {
		return null;
	}
}
 
开发者ID:ByteWelder,项目名称:Spork,代码行数:20,代码来源:DefaultContextResolver.java

示例5: getAuthority

import android.content.ContentProvider; //导入依赖的package包/类
public String getAuthority(Context context, Class<? extends ContentProvider> providerClass) {
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_PROVIDERS);
        ProviderInfo[] providers = packageInfo.providers;
        if (providers.length > 0) {
            for (int i = 0; i < providers.length; i++) {
                ProviderInfo provider = providers[i];
                if (provider.name.contains(providerClass.getSimpleName())) {
                    return provider.authority;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:nrudenko,项目名称:dora,代码行数:19,代码来源:MetaDataParser.java

示例6: getIContentProvider

import android.content.ContentProvider; //导入依赖的package包/类
private IContentProvider getIContentProvider(@NonNull PluginInfo pluginInfo, @NonNull ProviderInfo providerInfo) {
    if (pluginInfo != null && providerInfo != null) {
        ContentProvider contentProvider;
        synchronized (mContentProviderMap) {
            contentProvider = mContentProviderMap.get(providerInfo.name);
        }

        if (contentProvider == null) {
            contentProvider = installProvider(pluginInfo, providerInfo);
        }

        if (contentProvider != null) {
            return ContentProviderCompat.getIContentProvider(contentProvider);
        } else {
            throw new RuntimeException("CAN NOT get IContentProvider for " + providerInfo);
        }
    }

    return null;
}
 
开发者ID:xyxyLiu,项目名称:PluginM,代码行数:21,代码来源:PluginStubMainProvider.java

示例7: installProvider

import android.content.ContentProvider; //导入依赖的package包/类
private ContentProvider installProvider(PluginInfo pluginInfo, ProviderInfo providerInfo) {
    try {
        Logger.d(TAG, "installProvider() providerInfo = " + providerInfo);
        Class clazz = pluginInfo.classLoader.loadClass(providerInfo.name);
        ContentProvider contentProvider = (ContentProvider) clazz.newInstance();
        contentProvider.attachInfo(pluginInfo.baseContext, providerInfo);

        synchronized (mContentProviderMap) {
            ContentProvider cp = mContentProviderMap.get(providerInfo.name);
            if (cp != null) {
                Logger.d(TAG, "installProvider() lose race!");
                contentProvider = cp;
            } else {
                mContentProviderMap.put(providerInfo.name, contentProvider);
                PluginManager.getInstance(getContext()).callProviderOnCreate(contentProvider, mStubInfo, providerInfo);
            }
        }

        Logger.d(TAG, "installProvider() providerInfo -> " + contentProvider);
        return contentProvider;
    } catch (Exception e) {
        Logger.e(TAG, "installProvider() error! providerInfo = " + providerInfo, e);
    }

    return null;
}
 
开发者ID:xyxyLiu,项目名称:PluginM,代码行数:27,代码来源:PluginStubMainProvider.java

示例8: 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());
        }
    }
}
 
开发者ID:SNiels,项目名称:Multi-Mania-app,代码行数:25,代码来源:SyncUtils.java

示例9: setUp

import android.content.ContentProvider; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    // Create test file
    final FileOutputStream os = getContext()
            .openFileOutput(TEST_FILE_NAME, Context.MODE_PRIVATE);
    os.write(TestFiles.TEST_DATA);
    os.close();

    // Replace IsolatedContext with the normal one
    try {
        final Field f = ContentProvider.class.getDeclaredField("mContext");
        f.setAccessible(true);
        f.set(getProvider(), getContext());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lemberg,项目名称:android-project-template,代码行数:20,代码来源:ContentResolverRequestQueueTest.java

示例10: setUpContentProvider

import android.content.ContentProvider; //导入依赖的package包/类
private void setUpContentProvider(ContentProvider targetProvider) throws Exception {
    mResolver = new ChangeRecordingMockContentResolver();

    final String filenamePrefix = this.getClass().getSimpleName() + ".";
    RenamingDelegatingContext targetContextWrapper =
            new RenamingDelegatingContext(
                new ContentProviderMockContext(),
                (Context)getActivity(),
                filenamePrefix);

    mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);

    targetProvider.attachInfo(mProviderContext, null);

    mProvider = new DelegatingTestContentProvider(targetProvider);
    mProvider.attachInfo(mProviderContext, null);

    mResolver.addProvider(mProviderAuthority, mProvider);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:20,代码来源:ContentProviderTest.java

示例11: getAuthority

import android.content.ContentProvider; //导入依赖的package包/类
public static String getAuthority(Context context, Class<? extends ContentProvider> providerClass) {
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_PROVIDERS);
        ProviderInfo[] providers = packageInfo.providers;
        if (providers.length > 0) {
            for (int i = 0; i < providers.length; i++) {
                ProviderInfo provider = providers[i];
                if (provider.name.contains(providerClass.getSimpleName())) {
                    return provider.authority;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:bobroalexandr,项目名称:GenericDao,代码行数:19,代码来源:MetaDataParser.java

示例12: query

import android.content.ContentProvider; //导入依赖的package包/类
@Implementation
public final Cursor query(Uri uri, String[] projection, String selection,
    String[] selectionArgs, String sortOrder) {
  ContentProvider provider = getProvider(uri);
  if (provider != null) {
    return provider.query(uri, projection, selection, selectionArgs, sortOrder);
  } else {
    TestCursor returnCursor = getCursor(uri);
    if (returnCursor == null) {
      return null;
    }

    returnCursor.setQuery(uri, projection, selection, selectionArgs,
        sortOrder);
    return returnCursor;
  }
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:18,代码来源:ShadowContentResolver.java

示例13: installProviderAuthoritiesLocked

import android.content.ContentProvider; //导入依赖的package包/类
private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider,
        ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) {
    final String auths[] = PATTERN_SEMICOLON.split(holder.info.authority);
    final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid);

    final ProviderClientRecord pcr = new ProviderClientRecord(
            auths, provider, localProvider, holder);
    for (String auth : auths) {
        final ProviderKey key = new ProviderKey(auth, userId);
        final ProviderClientRecord existing = mProviderMap.get(key);
        if (existing != null) {
            Slog.w(TAG, "Content provider " + pcr.mHolder.info.name
                    + " already published as " + auth);
        } else {
            mProviderMap.put(key, pcr);
        }
    }
    return pcr;
}
 
开发者ID:cuplv,项目名称:droidel,代码行数:20,代码来源:ActivityThread.java

示例14: clearDatabase

import android.content.ContentProvider; //导入依赖的package包/类
public void clearDatabase() {
    final String authority = AUTHORITY_REF.get();
    if (!TextUtils.isEmpty(authority)) {
        final ContentProviderClient providerClient = mResolver.acquireContentProviderClient(authority);
        if (providerClient != null) {
            try {
                final ContentProvider provider = providerClient.getLocalContentProvider();
                if (provider instanceof SQLiteProvider) {
                    ((SQLiteProvider) provider).clearDatabase();
                }
            } finally {
                providerClient.release();
            }
        }
    }
}
 
开发者ID:DanielSerdyukov,项目名称:droidkit-v4x,代码行数:17,代码来源:SQLite.java

示例15: DataUpdateService

import android.content.ContentProvider; //导入依赖的package包/类
public DataUpdateService(Context context, ContentProvider provider){
	this.context = context;
	this.provider = provider;
	lockCache = new LruCache<String, Lock>(200) {
        @Override
        protected int sizeOf(String key, Lock obj) {
            return 1;
        }
    };
    dataPath = context.getDatabasePath("lastUpdate.db");
    
    loadLastUpadte();
    syncTimer = new Timer();
    syncTimer.scheduleAtFixedRate(new TimerTask(){

		@Override
		public void run() {
			saveLastUpdate();
		}}, 1000, 1000 * 60);
    
}
 
开发者ID:emop,项目名称:EmopAndroid,代码行数:22,代码来源:DataUpdateService.java


注:本文中的android.content.ContentProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。