Java Code Examples for android.net.Uri#getSchemeSpecificPart()

The following examples show how to use android.net.Uri#getSchemeSpecificPart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    synchronized (mCache) {
        if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
            mCache.clear();
        } else {
            final Uri data = intent.getData();
            if (data != null) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                        UserHandle.USER_NULL);
                final String packageName = data.getSchemeSpecificPart();
                invalidateCacheLocked(userId, packageName, null);
            }
        }
    }
}
 
Example 2
Source File: ToolsDownloader.java    From Beats with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.unzipper);
	Tools.setContext(this);
	
	// Download
	Intent downloadIntent = getIntent();
	Uri data = downloadIntent.getData();
	if (data != null &&
		(url = data.getScheme() + ":" + data.getSchemeSpecificPart()) != null &&
		Tools.isStepfilePack(url))
		{
		this.setTitle(
				Tools.getString(R.string.ToolsDownloader_download) + 
				downloadIntent.getData().getLastPathSegment()
				);
		path = Tools.getBeatsDir() + "/" + downloadIntent.getData().getLastPathSegment();
		ToolsTracker.data("Download song", "url", url);
		download();
	} else {
		errorMessage = Tools.getString(R.string.ToolsDownloader_unsupported);
		downloadFail();
	}
}
 
Example 3
Source File: CordovaResourceApi.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
private OpenForReadResult readDataUri(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    String contentType = null;
    boolean base64 = false;
    if (mimeParts.length > 0) {
        contentType = mimeParts[0];
    }
    for (int i = 1; i < mimeParts.length; ++i) {
        if ("base64".equalsIgnoreCase(mimeParts[i])) {
            base64 = true;
        }
    }
    String dataPartAsString = uriAsString.substring(commaPos + 1);
    byte[] data = base64 ? Base64.decode(dataPartAsString, Base64.DEFAULT) : EncodingUtils.getBytes(dataPartAsString, "UTF-8");
    InputStream inputStream = new ByteArrayInputStream(data);
    return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
 
Example 4
Source File: PackageReceiver.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final ContentResolver resolver = context.getContentResolver();

    final String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
        resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE, null, null);

    } else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(action)) {
        final Uri data = intent.getData();
        if (data != null) {
            final String packageName = data.getSchemeSpecificPart();
            resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE_PACKAGE,
                    packageName, null);
        }
    }
}
 
Example 5
Source File: NoteActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void getName(){
    Uri uri = getIntent().getData();
    if(null == uri){
        return;
    }
    String name = "";
    String scheme = uri.getScheme();
    if (!TextUtils.isEmpty(scheme) && scheme.startsWith(ContentResolver.SCHEME_CONTENT)) {
        String part = uri.getSchemeSpecificPart();
        final int splitIndex = part.indexOf(':', 1);
        if(splitIndex != -1) {
            name = part.substring(splitIndex + 1);
        }
        if(TextUtils.isEmpty(name)){
            name = uri.getLastPathSegment();
        }
    }
    else if (!TextUtils.isEmpty(scheme) && scheme.startsWith(ContentResolver.SCHEME_FILE)) {
        name = uri.getLastPathSegment();
    } else {
        CrashReportingManager.log(TAG, uri.toString()); //incomplete
    }
    getSupportActionBar().setTitle(FileUtils.getName(name));
    getSupportActionBar().setSubtitle("");
}
 
Example 6
Source File: NoteActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void getName(){
    Uri uri = getIntent().getData();
    if(null == uri){
        return;
    }
    String name = "";
    String scheme = uri.getScheme();
    if (!TextUtils.isEmpty(scheme) && scheme.startsWith(ContentResolver.SCHEME_CONTENT)) {
        String part = uri.getSchemeSpecificPart();
        final int splitIndex = part.indexOf(':', 1);
        if(splitIndex != -1) {
            name = part.substring(splitIndex + 1);
        }
        if(TextUtils.isEmpty(name)){
            name = uri.getLastPathSegment();
        }
    }
    else if (!TextUtils.isEmpty(scheme) && scheme.startsWith(ContentResolver.SCHEME_FILE)) {
        name = uri.getLastPathSegment();
    } else {
        Crashlytics.log(Log.ERROR, "Error", "URI Error"); //incomplete
    }
    getSupportActionBar().setTitle(FileUtils.getName(name));
    getSupportActionBar().setSubtitle("");
}
 
Example 7
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    synchronized (mCache) {
        if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
            mCache.clear();
        } else {
            final Uri data = intent.getData();
            if (data != null) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                        UserHandle.USER_NULL);
                final String packageName = data.getSchemeSpecificPart();
                invalidateCacheLocked(userId, packageName, null);
            }
        }
    }
}
 
Example 8
Source File: ApiDispatcher.java    From island with Apache License 2.0 6 votes vote down vote up
private static String processPackageUri(final Intent intent, final Predicate<String> dealer) {
	final Uri uri = intent.getData();
	final String ssp;
	if (uri == null || (ssp = uri.getSchemeSpecificPart()) == null) return "Invalid data in Intent: " + intent;
	final String scheme = uri.getScheme();
	final Stream<String> pkgs;
	final boolean single;
	if (single = "package".equals(scheme)) pkgs = Stream.of(ssp);
	else if ("packages".equals(scheme)) pkgs = StreamSupport.stream(Arrays.asList(ssp.split(","))).filter(Objects::nonNull).map(String::trim);
	else return "Unsupported intent data scheme: " + intent;	// Should never happen

	try {
		final List<String> failed_pkgs = pkgs.filter(t -> ! dealer.test(t)).collect(Collectors.toList());
		if (failed_pkgs.isEmpty()) return null;
		if (single) return "Failed: " + ssp;
		return "Failed: " + failed_pkgs;
	} catch (final SecurityException e) {
		return "Internal exception: " + e;		// Island might be have been deactivated or not set up yet.
	}
}
 
Example 9
Source File: CordovaResourceApi.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
private OpenForReadResult readDataUri(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    String contentType = null;
    boolean base64 = false;
    if (mimeParts.length > 0) {
        contentType = mimeParts[0];
    }
    for (int i = 1; i < mimeParts.length; ++i) {
        if ("base64".equalsIgnoreCase(mimeParts[i])) {
            base64 = true;
        }
    }
    String dataPartAsString = uriAsString.substring(commaPos + 1);
    byte[] data = base64 ? Base64.decode(dataPartAsString, Base64.DEFAULT) : EncodingUtils.getBytes(dataPartAsString, "UTF-8");
    InputStream inputStream = new ByteArrayInputStream(data);
    return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
 
Example 10
Source File: CordovaResourceApi.java    From keemob with MIT License 5 votes vote down vote up
private String getDataUriMimeType(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    if (mimeParts.length > 0) {
        return mimeParts[0];
    }
    return null;
}
 
Example 11
Source File: CordovaResourceApi.java    From pychat with MIT License 5 votes vote down vote up
private String getDataUriMimeType(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    if (mimeParts.length > 0) {
        return mimeParts[0];
    }
    return null;
}
 
Example 12
Source File: AppLauncher.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG) log("Broadcast received: " + intent.toString());

    Uri data = intent.getData();
    String pkgName = data == null ? null : data.getSchemeSpecificPart();
    if (pkgName != null) {
        for (AppInfo ai : mAppSlots) {
            if (pkgName.equals(ai.getPackageName())) {
                ai.initAppInfo(null);
                if (DEBUG) log("Removed package: " + pkgName);
            }
        }
    }
}
 
Example 13
Source File: CordovaResourceApi.java    From cordova-plugin-app-update-demo with MIT License 5 votes vote down vote up
private OpenForReadResult readDataUri(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    String contentType = null;
    boolean base64 = false;
    if (mimeParts.length > 0) {
        contentType = mimeParts[0];
    }
    for (int i = 1; i < mimeParts.length; ++i) {
        if ("base64".equalsIgnoreCase(mimeParts[i])) {
            base64 = true;
        }
    }
    String dataPartAsString = uriAsString.substring(commaPos + 1);
    byte[] data;
    if (base64) {
        data = Base64.decode(dataPartAsString, Base64.DEFAULT);
    } else {
        try {
            data = dataPartAsString.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            data = dataPartAsString.getBytes();
        }
    }
    InputStream inputStream = new ByteArrayInputStream(data);
    return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
 
Example 14
Source File: CordovaResourceApi.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
private String getDataUriMimeType(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    if (mimeParts.length > 0) {
        return mimeParts[0];
    }
    return null;
}
 
Example 15
Source File: CordovaResourceApi.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
private String getDataUriMimeType(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    if (mimeParts.length > 0) {
        return mimeParts[0];
    }
    return null;
}
 
Example 16
Source File: CordovaResourceApi.java    From keemob with MIT License 5 votes vote down vote up
private OpenForReadResult readDataUri(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    String contentType = null;
    boolean base64 = false;
    if (mimeParts.length > 0) {
        contentType = mimeParts[0];
    }
    for (int i = 1; i < mimeParts.length; ++i) {
        if ("base64".equalsIgnoreCase(mimeParts[i])) {
            base64 = true;
        }
    }
    String dataPartAsString = uriAsString.substring(commaPos + 1);
    byte[] data;
    if (base64) {
        data = Base64.decode(dataPartAsString, Base64.DEFAULT);
    } else {
        try {
            data = dataPartAsString.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            data = dataPartAsString.getBytes();
        }
    }
    InputStream inputStream = new ByteArrayInputStream(data);
    return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
 
Example 17
Source File: CordovaResourceApi.java    From reader with MIT License 5 votes vote down vote up
private String getDataUriMimeType(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    if (mimeParts.length > 0) {
        return mimeParts[0];
    }
    return null;
}
 
Example 18
Source File: CordovaResourceApi.java    From react-native-cordova with MIT License 5 votes vote down vote up
private OpenForReadResult readDataUri(Uri uri) {
    String uriAsString = uri.getSchemeSpecificPart();
    int commaPos = uriAsString.indexOf(',');
    if (commaPos == -1) {
        return null;
    }
    String[] mimeParts = uriAsString.substring(0, commaPos).split(";");
    String contentType = null;
    boolean base64 = false;
    if (mimeParts.length > 0) {
        contentType = mimeParts[0];
    }
    for (int i = 1; i < mimeParts.length; ++i) {
        if ("base64".equalsIgnoreCase(mimeParts[i])) {
            base64 = true;
        }
    }
    String dataPartAsString = uriAsString.substring(commaPos + 1);
    byte[] data;
    if (base64) {
        data = Base64.decode(dataPartAsString, Base64.DEFAULT);
    } else {
        try {
            data = dataPartAsString.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            data = dataPartAsString.getBytes();
        }
    }
    InputStream inputStream = new ByteArrayInputStream(data);
    return new OpenForReadResult(uri, inputStream, contentType, data.length, null);
}
 
Example 19
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final int userId  = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
    if (userId == UserHandle.USER_NULL) {
        Slog.w(TAG, "Intent broadcast does not contain user handle: " + intent);
        return;
    }

    final String action = intent.getAction();

    // This is normally called on Handler, so clearCallingIdentity() isn't needed,
    // but we still check it in unit tests.
    final long token = injectClearCallingIdentity();
    try {
        synchronized (mLock) {
            if (!isUserUnlockedL(userId)) {
                if (DEBUG) {
                    Slog.d(TAG, "Ignoring package broadcast " + action
                            + " for locked/stopped user " + userId);
                }
                return;
            }

            // Whenever we get one of those package broadcasts, or get
            // ACTION_PREFERRED_ACTIVITY_CHANGED, we purge the default launcher cache.
            final ShortcutUser user = getUserShortcutsLocked(userId);
            user.clearLauncher();
        }
        if (Intent.ACTION_PREFERRED_ACTIVITY_CHANGED.equals(action)) {
            // Nothing farther to do.
            return;
        }

        final Uri intentUri = intent.getData();
        final String packageName = (intentUri != null) ? intentUri.getSchemeSpecificPart()
                : null;
        if (packageName == null) {
            Slog.w(TAG, "Intent broadcast does not contain package name: " + intent);
            return;
        }

        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        switch (action) {
            case Intent.ACTION_PACKAGE_ADDED:
                if (replacing) {
                    handlePackageUpdateFinished(packageName, userId);
                } else {
                    handlePackageAdded(packageName, userId);
                }
                break;
            case Intent.ACTION_PACKAGE_REMOVED:
                if (!replacing) {
                    handlePackageRemoved(packageName, userId);
                }
                break;
            case Intent.ACTION_PACKAGE_CHANGED:
                handlePackageChanged(packageName, userId);

                break;
            case Intent.ACTION_PACKAGE_DATA_CLEARED:
                handlePackageDataCleared(packageName, userId);
                break;
        }
    } catch (Exception e) {
        wtf("Exception in mPackageMonitor.onReceive", e);
    } finally {
        injectRestoreCallingIdentity(token);
    }
}
 
Example 20
Source File: OverlayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
    final Uri data = intent.getData();
    if (data == null) {
        Slog.e(TAG, "Cannot handle package broadcast with null data");
        return;
    }
    final String packageName = data.getSchemeSpecificPart();

    final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

    final int[] userIds;
    final int extraUid = intent.getIntExtra(Intent.EXTRA_UID, UserHandle.USER_NULL);
    if (extraUid == UserHandle.USER_NULL) {
        userIds = mUserManager.getUserIds();
    } else {
        userIds = new int[] { UserHandle.getUserId(extraUid) };
    }

    switch (intent.getAction()) {
        case ACTION_PACKAGE_ADDED:
            if (replacing) {
                onPackageUpgraded(packageName, userIds);
            } else {
                onPackageAdded(packageName, userIds);
            }
            break;
        case ACTION_PACKAGE_CHANGED:
            onPackageChanged(packageName, userIds);
            break;
        case ACTION_PACKAGE_REMOVED:
            if (replacing) {
                onPackageUpgrading(packageName, userIds);
            } else {
                onPackageRemoved(packageName, userIds);
            }
            break;
        default:
            // do nothing
            break;
    }
}