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

The following examples show how to use android.net.Uri#getEncodedSchemeSpecificPart() . 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: MainActivity.java    From minx with MIT License 6 votes vote down vote up
public void getPublicIntent() {
    String url = null;
    Intent intent = getIntent();
    try {
        if (intent != null) {
            Uri data = intent.getData();
            String scheme = data.getScheme();
            String fullPath = data.getEncodedSchemeSpecificPart();
            fullPath = fullPath.replace("//", "");
            url = scheme + "://" + fullPath;
        }
        if (url != null) {
            loadSearchType = 1;
            search_txt.setText(url);
            showSearchTxt();
        } else {
            Toast.makeText(MainActivity.this, "Invalid Url", Toast.LENGTH_SHORT).show();
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: AppStateReceiver.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceive(Context context, Intent intent) {
        try {
            String action = intent.getAction();
            // 打印当前触发的广播
            LogPrintUtils.dTag(TAG, "onReceive Action: " + action);
            // 被操作应用包名
            String packageName = null;
            Uri uri = intent.getData();
            if (uri != null) {
//                packageName = uri.toString();
                packageName = uri.getEncodedSchemeSpecificPart();
            }
            // 判断类型
            switch (action) {
                case Intent.ACTION_PACKAGE_ADDED: // 应用安装
                    if (sListener != null) {
                        sListener.onAdded(packageName);
                    }
                    break;
                case Intent.ACTION_PACKAGE_REPLACED: // 应用更新
                    if (sListener != null) {
                        sListener.onReplaced(packageName);
                    }
                    break;
                case Intent.ACTION_PACKAGE_REMOVED: // 应用卸载
                    if (sListener != null) {
                        sListener.onRemoved(packageName);
                    }
                    break;
            }
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "onReceive");
        }
    }
 
Example 3
Source File: ShowLocationActivity.java    From PocketMaps with MIT License 5 votes vote down vote up
private boolean getLocationFromParsingValues(Properties prop, Uri uri)
{
  log("Input-uri has no parameters, try parsing values!");
  String schemePart = uri.getEncodedSchemeSpecificPart();
  if (schemePart == null) { return false; }
  String latLon[] = schemePart.split(",");
  if (latLon.length != 2 && latLon.length != 3) { return false; } // lat,lon[,alt]
  prop.put("lat", latLon[0]);
  prop.put("lon", latLon[1]);
  return checkLocationParameters(prop);
}
 
Example 4
Source File: MainActivity.java    From hack.chat-android with MIT License 5 votes vote down vote up
/**
 * Returns the chatroom name from the referred URI data provided.
 */
private String extractReferredChatroomName(Uri data) {
    String url = data.getEncodedSchemeSpecificPart();
    if (url.indexOf('?') != -1) {
        return url.substring(url.lastIndexOf('?') + 1);
    }
    return "";
}
 
Example 5
Source File: CallActivity.java    From yiim_v2 with GNU General Public License v2.0 5 votes vote down vote up
public void parseUri(Uri uri) {
	if (!"xmpp".equals(uri.getScheme()))
		throw new IllegalArgumentException();
	String enduri = uri.getEncodedSchemeSpecificPart();
	mJID = StringUtils.parseBareAddress(enduri);
	String res = StringUtils.parseResource(enduri);
	mSelectedRes = res;
}
 
Example 6
Source File: MainActivity.java    From open-location-code with Apache License 2.0 5 votes vote down vote up
/**
 * Handles intent URIs, extracts the query part and sends it to the search function.
 * <p/>
 * URIs may be of the form:
 * <ul>
 * <li>{@code geo:37.802,-122.41962}
 * <li>{@code geo:37.802,-122.41962?q=7C66CM4X%2BC34&z=20}
 * <li>{@code geo:0,0?q=WF59%2BX67%20Praia}
 * </ul>
 * <p/>
 * Only the query string is used. Coordinates and zoom level are ignored. If the query string
 * is not recognised by the search function (say, it's a street address), it will fail.
 */
private void handleGeoIntent(Intent intent) {
    Uri uri = intent != null ? intent.getData() : null;
    if (uri == null) {
        return;
    }
    String schemeSpecificPart = uri.getEncodedSchemeSpecificPart();
    if (schemeSpecificPart == null || schemeSpecificPart.isEmpty()) {
        return;
    }
    // Get everything after q=
    int queryIndex = schemeSpecificPart.indexOf(URI_QUERY_SEPARATOR);
    if (queryIndex == -1) {
        return;
    }
    String searchQuery = schemeSpecificPart.substring(queryIndex + 2);
    if (searchQuery.contains(URI_ZOOM_SEPARATOR)) {
        searchQuery = searchQuery.substring(0, searchQuery.indexOf(URI_ZOOM_SEPARATOR));
    }
    final String searchString = Uri.decode(searchQuery);
    Log.i(TAG, "Search string is " + searchString);

    // Give the map some time to get ready.
    Handler h = new Handler();
    Runnable r = new Runnable() {
        @Override
        public void run() {
            if (mMainPresenter.getSearchActionsListener().searchCode(searchString)) {
                mMainPresenter.getSearchActionsListener().setSearchText(searchString);
            }
        }
    };
    h.postDelayed(r, 2000);
}
 
Example 7
Source File: InstallPackagesService.java    From FreezeYou with Apache License 2.0 4 votes vote down vote up
private void uninstall(Intent intent, Notification.Builder builder, NotificationManager notificationManager) {

        final Uri packageUri = intent.getParcelableExtra("packageUri");
        String packageName = packageUri.getEncodedSchemeSpecificPart(); // 应用包名
        String willBeUninstalledName = getApplicationLabel(this, null, null, packageName); // 应用名称
        try {
            if (packageName == null) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        showToast(getApplicationContext(), getString(R.string.invalidArguments) + " " + packageUri);
                    }
                });
                return;
            }

            Drawable willBeUninstalledIcon =
                    getApplicationIcon(
                            this,
                            packageName,
                            ApplicationInfoUtils.getApplicationInfoFromPkgName(packageName, this),
                            false);

            builder.setContentTitle(String.format(getString(R.string.uninstalling_app), willBeUninstalledName));
            builder.setLargeIcon(getBitmapFromDrawable(willBeUninstalledIcon));
            notificationManager.notify((packageName + "@InstallPackagesNotification").hashCode(), builder.getNotification());

            if (Build.VERSION.SDK_INT >= 21 && DevicePolicyManagerUtils.isDeviceOwner(this)) {
                getPackageManager().getPackageInstaller().uninstall(packageName,
                        PendingIntent.getBroadcast(this, packageName.hashCode(),
                                new Intent(
                                        this,
                                        InstallPackagesFinishedReceiver.class)
                                        .putExtra("name", willBeUninstalledName)
                                        .putExtra("pkgName", packageName)
                                        .putExtra("install", false), PendingIntent.FLAG_UPDATE_CURRENT)
                                .getIntentSender());
            } else {
                // Root Mode
                Process process = Runtime.getRuntime().exec("su");
                DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
                outputStream.writeBytes("pm uninstall -k \"" + packageName + "\"\n");
                outputStream.writeBytes("exit\n");
                outputStream.flush();
                process.waitFor();
                destroyProcess(outputStream, process);
                InstallPackagesUtils
                        .notifyFinishNotification(
                                this, notificationManager, builder,
                                false,
                                packageName,
                                String.format(
                                        getString(R.string.app_uninstallFinished),
                                        willBeUninstalledName),
                                null,
                                true);
            }
        } catch (final Exception e) {
            e.printStackTrace();
            InstallPackagesUtils
                    .notifyFinishNotification(
                            this, notificationManager, builder,
                            false,
                            packageName,
                            getString(R.string.uninstallFailed),
                            e.getLocalizedMessage(),
                            false);
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    showToast(getApplicationContext(), String.format(getString(R.string.errorUninstallToast), e.getLocalizedMessage()));
                }
            });
        }
    }