Java Code Examples for android.content.pm.PackageManager.resolveContentProvider()

The following are Jave code examples for showing how to use resolveContentProvider() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kognitivo   File: Validate.java   View Source Code Vote up 5 votes
public static void hasContentProvider(Context context) {
    Validate.notNull(context, "context");
    String appId = Validate.hasAppID();
    PackageManager pm = context.getPackageManager();
    if (pm != null) {
        String providerName = CONTENT_PROVIDER_BASE + appId;
        if (pm.resolveContentProvider(providerName, 0) == null) {
            throw new IllegalStateException(
                    String.format(CONTENT_PROVIDER_NOT_FOUND_REASON, providerName));
        }
    }
}
 
Example 2
Project: easyfilemanager   File: IconUtils.java   View Source Code Vote up 5 votes
public static Drawable loadPackageIcon(Context context, String authority, int icon) {
    if (icon != 0) {
        if (authority != null) {
            final PackageManager pm = context.getPackageManager();
            final ProviderInfo info = pm.resolveContentProvider(authority, 0);
            if (info != null) {
                return pm.getDrawable(info.packageName, icon, info.applicationInfo);
            }
        } else {
            return ContextCompat.getDrawable(context, icon);
        }
    }
    return null;
}
 
Example 3
Project: FireFiles   File: IconUtils.java   View Source Code Vote up 5 votes
public static Drawable loadPackageIcon(Context context, String authority, int icon) {
    if (icon != 0) {
        if (authority != null) {
            final PackageManager pm = context.getPackageManager();
            final ProviderInfo info = pm.resolveContentProvider(authority, 0);
            if (info != null) {
                return pm.getDrawable(info.packageName, icon, info.applicationInfo);
            }
        } else {
            return ContextCompat.getDrawable(context, icon);
        }
    }
    return null;
}
 
Example 4
Project: simple-share-android   File: IconUtils.java   View Source Code Vote up 5 votes
public static Drawable loadPackageIcon(Context context, String authority, int icon) {
    if (icon != 0) {
        if (authority != null) {
            final PackageManager pm = context.getPackageManager();
            final ProviderInfo info = pm.resolveContentProvider(authority, 0);
            if (info != null) {
                return pm.getDrawable(info.packageName, icon, info.applicationInfo);
            }
        } else {
            return ContextCompat.getDrawable(context, icon);
        }
    }
    return null;
}
 
Example 5
Project: react-native-videoplayer   File: APEZProvider.java   View Source Code Vote up 4 votes
private boolean initIfNecessary() {
    if ( !mInit ) {
           Context ctx = getContext();
           PackageManager pm = ctx.getPackageManager();
           ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
           PackageInfo packInfo;
           try {
               packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
           } catch (NameNotFoundException e1) {
               e1.printStackTrace();
               return false;
           }
           int patchFileVersion;
           int mainFileVersion;
           int appVersionCode = packInfo.versionCode;
           String[] resourceFiles = null;
           if ( null != pi.metaData ) {
               mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
               patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
               String mainFileName = pi.metaData.getString("mainFilename", NO_FILE);
               if ( NO_FILE != mainFileName ) {
                   String patchFileName = pi.metaData.getString("patchFilename", NO_FILE);
                   if ( NO_FILE != patchFileName ) {
                       resourceFiles = new String[] { mainFileName, patchFileName };
                   } else {
                       resourceFiles = new String[] { mainFileName };
                   }
               }
           } else {
               mainFileVersion = patchFileVersion = appVersionCode;
           }
           try {
               if ( null == resourceFiles ) {
                   mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
               } else {
                   mAPKExtensionFile = APKExpansionSupport.getResourceZipFile(resourceFiles);
               }
               mInit = true;
               return true;
           } catch (IOException e) {
               e.printStackTrace();                
           }
    }
       return false;	    
}
 
Example 6
Project: SlotNSlot_Android   File: APEZProvider.java   View Source Code Vote up 4 votes
private boolean initIfNecessary() {
    if ( !mInit ) {
           Context ctx = getContext();
           PackageManager pm = ctx.getPackageManager();
           ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
           PackageInfo packInfo;
           try {
               packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
           } catch (NameNotFoundException e1) {
               e1.printStackTrace();
               return false;
           }
           int patchFileVersion;
           int mainFileVersion;
           int appVersionCode = packInfo.versionCode;
           String[] resourceFiles = null;
           if ( null != pi.metaData ) {
               mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
               patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
               String mainFileName = pi.metaData.getString("mainFilename", NO_FILE);
               if ( NO_FILE != mainFileName ) {
                   String patchFileName = pi.metaData.getString("patchFilename", NO_FILE);
                   if ( NO_FILE != patchFileName ) {
                       resourceFiles = new String[] { mainFileName, patchFileName };
                   } else {
                       resourceFiles = new String[] { mainFileName };
                   }
               }
           } else {
               mainFileVersion = patchFileVersion = appVersionCode;
           }
           try {
               if ( null == resourceFiles ) {
                   mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
               } else {
                   mAPKExtensionFile = APKExpansionSupport.getResourceZipFile(resourceFiles);
               }
               mInit = true;
               return true;
           } catch (IOException e) {
               e.printStackTrace();                
           }
    }
       return false;	    
}