Java Code Examples for android.content.Intent.toUri()

The following are Jave code examples for showing how to use toUri() of the android.content.Intent 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: SmingZZick_App   File: MainActivity.java   View Source Code Vote up 9 votes
@Override
@TargetApi(21)
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        String uri = data.toUri(0);
        MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Activity.MEDIA_PROJECTION_SERVICE);
        MediaProjection mediaProjection = projectionManager.getMediaProjection(resultCode, data);

        ScreenCaptureService.setMediaProjection(mediaProjection);

        startService(new Intent(ScreenCaptureService.ACTION_START, null, this, ScreenCaptureService.class));
        fab.setSelected(true);
    }

    if (requestCode == REQUEST_CODE_MAKE_SMING && resultCode == RESULT_OK) {
        loadSmings();
        checkEmpty();
    }
}
 
Example 2
Project: GravityBox   File: AppPickerPreference.java   View Source Code Vote up 7 votes
private String convertOldValueFormat(String oldValue) {
    try {
        String[] splitValue = oldValue.split(SEPARATOR);
        ComponentName cn = new ComponentName(splitValue[0], splitValue[1]);
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(cn);
        intent.putExtra("mode", MODE_APP);
        String newValue = intent.toUri(0);
        setValue(newValue);
        Log.d(TAG, "Converted old AppPickerPreference value: " + newValue);
        return newValue;
    } catch (Exception e) {
        Log.e(TAG, "Error converting old AppPickerPreference value: " + e.getMessage());
        return null;
    }
}
 
Example 3
Project: LaunchEnr   File: AddWorkspaceItemsTask.java   View Source Code Vote up 6 votes
/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
private boolean shortcutExists(BgDataModel dataModel, Intent intent, UserHandle user) {
    final String intentWithPkg, intentWithoutPkg;
    if (intent == null) {
        // Skip items with null intents
        return true;
    }
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        String packageName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(packageName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }

    synchronized (dataModel) {
        for (ItemInfo item : dataModel.itemsIdMap) {
            if (item instanceof ShortcutInfo) {
                ShortcutInfo info = (ShortcutInfo) item;
                if (item.getIntent() != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(item.getIntent());
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 4
Project: FlickLauncher   File: LauncherModel.java   View Source Code Vote up 6 votes
/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
@Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) {
    assertWorkspaceLoaded();
    final String intentWithPkg, intentWithoutPkg;
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        String packageName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(packageName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }

    synchronized (sBgLock) {
        for (ItemInfo item : sBgItemsIdMap) {
            if (item instanceof ShortcutInfo) {
                ShortcutInfo info = (ShortcutInfo) item;
                Intent targetIntent = info.promisedIntent == null
                        ? info.intent : info.promisedIntent;
                if (targetIntent != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(targetIntent);
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 5
Project: SimpleUILauncher   File: LauncherModel.java   View Source Code Vote up 6 votes
/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
@Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) {
    assertWorkspaceLoaded();
    final String intentWithPkg, intentWithoutPkg;
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        String packageName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(packageName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }

    synchronized (sBgLock) {
        for (ItemInfo item : sBgItemsIdMap) {
            if (item instanceof ShortcutInfo) {
                ShortcutInfo info = (ShortcutInfo) item;
                Intent targetIntent = info.promisedIntent == null
                        ? info.intent : info.promisedIntent;
                if (targetIntent != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(targetIntent);
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}