Search in sources :

Example 1 with VPackageManager

use of com.lody.virtual.client.ipc.VPackageManager in project VirtualApp by asLody.

the class VirtualCore method getLaunchIntent.

public Intent getLaunchIntent(String packageName, int userId) {
    VPackageManager pm = VPackageManager.get();
    Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
    intentToResolve.addCategory(Intent.CATEGORY_INFO);
    intentToResolve.setPackage(packageName);
    List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
    // Otherwise, try to find a main launcher activity.
    if (ris == null || ris.size() <= 0) {
        // reuse the intent instance
        intentToResolve.removeCategory(Intent.CATEGORY_INFO);
        intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
        intentToResolve.setPackage(packageName);
        ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
    }
    if (ris == null || ris.size() <= 0) {
        return null;
    }
    Intent intent = new Intent(intentToResolve);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name);
    return intent;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) VPackageManager(com.lody.virtual.client.ipc.VPackageManager) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)1 ResolveInfo (android.content.pm.ResolveInfo)1 VPackageManager (com.lody.virtual.client.ipc.VPackageManager)1