當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。