Example usage for android.content Intent parseUri

List of usage examples for android.content Intent parseUri

Introduction

In this page you can find the example usage for android.content Intent parseUri.

Prototype

public static Intent parseUri(String uri, @UriFlags int flags) throws URISyntaxException 

Source Link

Document

Create an intent from a URI.

Usage

From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(CapptainNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {//from w  w w.ja  v a  2  s  .c om
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && CapptainActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.mods.grx.settings.utils.Utils.java

public static void delete_grx_icon_file_from_uri_string(String uri) {
    String file_name = null;/*  ww  w.  j a v  a  2s  . co m*/
    Intent intent = null;
    try {
        intent = Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
    }
    if (intent != null)
        file_name = intent.getStringExtra(Common.EXTRA_URI_ICON);
    if (file_name != null) {
        File f_ico = new File(file_name);
        if (f_ico != null && f_ico.exists()) {
            f_ico.delete();
        }
    }
}

From source file:com.google.android.apps.dashclock.api.ExtensionData.java

/**
 * Deserializes the given {@link Bundle} representation of extension data, populating this
 * object./* w  w w.  j a v  a2s .  co  m*/
 */
public void fromBundle(Bundle src) {
    this.mVisible = src.getBoolean(KEY_VISIBLE, true);
    this.mIcon = src.getInt(KEY_ICON);
    String iconUriString = src.getString(KEY_ICON_URI);
    this.mIconUri = TextUtils.isEmpty(iconUriString) ? null : Uri.parse(iconUriString);
    this.mStatus = src.getString(KEY_STATUS);
    this.mExpandedTitle = src.getString(KEY_EXPANDED_TITLE);
    this.mExpandedBody = src.getString(KEY_EXPANDED_BODY);
    try {
        this.mClickIntent = Intent.parseUri(src.getString(KEY_CLICK_INTENT), 0);
    } catch (URISyntaxException ignored) {
    }
    this.mContentDescription = src.getString(KEY_CONTENT_DESCRIPTION);
}

From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(EngagementNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {/*from   w w w . j  a v a 2s . co m*/
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && EngagementActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.mods.grx.settings.utils.Utils.java

public static void delete_grx_icon_file_from_uri_string(String uri, String starts_with) {
    String file_name = null;/*from w w w  . ja  v  a 2  s.  c om*/
    Intent intent = null;
    try {
        intent = Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
    }
    if (intent != null)
        file_name = intent.getStringExtra(Common.EXTRA_URI_ICON);
    if (file_name != null) {
        File f_ico = new File(file_name);
        if (f_ico != null && f_ico.exists() && f_ico.getName().startsWith(starts_with)) {
            f_ico.delete();
        }
    }
}

From source file:com.google.android.apps.dashclock.api.ExtensionData.java

private ExtensionData(Parcel in) {
    int parcelableVersion = in.readInt();
    int parcelableSize = in.readInt();
    int startPosition = in.dataPosition();
    if (parcelableVersion >= 1) {
        this.mVisible = (in.readInt() != 0);
        this.mIcon = in.readInt();
        this.mStatus = in.readString();
        if (TextUtils.isEmpty(this.mStatus)) {
            this.mStatus = null;
        }/*from w ww  . ja v a 2 s  .  c  o m*/
        this.mExpandedTitle = in.readString();
        if (TextUtils.isEmpty(this.mExpandedTitle)) {
            this.mExpandedTitle = null;
        }
        this.mExpandedBody = in.readString();
        if (TextUtils.isEmpty(this.mExpandedBody)) {
            this.mExpandedBody = null;
        }
        try {
            this.mClickIntent = Intent.parseUri(in.readString(), 0);
        } catch (URISyntaxException ignored) {
        }
    }
    if (parcelableVersion >= 2) {
        this.mContentDescription = in.readString();
        if (TextUtils.isEmpty(this.mContentDescription)) {
            this.mContentDescription = null;
        }
        String iconUriString = in.readString();
        this.mIconUri = TextUtils.isEmpty(iconUriString) ? null : Uri.parse(iconUriString);
    }
    // Only advance the data position if the parcelable version is >= 2. In v1 of the
    // parcelable, there was an awful bug where the parcelableSize was complete nonsense.
    if (parcelableVersion >= 2) {
        in.setDataPosition(startPosition + parcelableSize);
    }
}

From source file:com.mods.grx.settings.utils.Utils.java

public static String get_file_name_from_uri_string(String uri) {
    String file_name = null;// w  w w .  jav a 2  s.c om
    Intent intent;
    try {
        intent = Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
        return file_name;
    }
    if (intent != null) {
        file_name = intent.getStringExtra(Common.EXTRA_URI_ICON);
    }
    return file_name;
}

From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java

private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {//from ww w.j a  v a2  s  .  c  om
        JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue();
        Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);

        if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
            // The is an internal launcher target shortcut.
            UserHandleCompat user = UserManagerCompat.getInstance(context)
                    .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY));
            if (user == null) {
                return null;
            }

            LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context)
                    .resolveActivity(launcherIntent, user);
            return info == null ? null : new PendingInstallShortcutInfo(info, context);
        }

        Intent data = new Intent();
        data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
        data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY));

        String iconBase64 = object.optString(ICON_KEY);
        String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
        String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
        if (iconBase64 != null && !iconBase64.isEmpty()) {
            byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
            Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
        } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
            Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
            iconResource.resourceName = iconResourceName;
            iconResource.packageName = iconResourcePackageName;
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        }

        return new PendingInstallShortcutInfo(data, context);
    } catch (JSONException | URISyntaxException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
}

From source file:com.mods.grx.settings.utils.Utils.java

public static String get_short_file_name_from_uri_string(String uri) {

    String file_name = null;//from  w  ww  .  ja v  a 2  s  .  c o m
    Intent intent;
    try {
        intent = Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
        return file_name;
    }
    if (intent != null) {
        file_name = intent.getStringExtra(Common.EXTRA_URI_ICON);
    }

    if (file_name != null) {
        File file = new File(file_name);
        if (file.exists())
            return file.getName();
    }
    return file_name;

}

From source file:com.android.launcher3.InstallShortcutReceiver.java

private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {//from w ww . j  ava 2s.c o  m
        JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue();
        Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);

        if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
            // The is an internal launcher target shortcut.
            UserHandleCompat user = UserManagerCompat.getInstance(context)
                    .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY));
            if (user == null) {
                return null;
            }

            LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context)
                    .resolveActivity(launcherIntent, user);
            return info == null ? null : new PendingInstallShortcutInfo(info, context);
        }

        Intent data = new Intent();
        data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
        data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY));

        String iconBase64 = object.optString(ICON_KEY);
        String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
        String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
        if (iconBase64 != null && !iconBase64.isEmpty()) {
            byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
            Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
        } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
            Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
            iconResource.resourceName = iconResourceName;
            iconResource.packageName = iconResourcePackageName;
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        }

        return new PendingInstallShortcutInfo(data, context);
    } catch (JSONException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    } catch (URISyntaxException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
}