Example usage for android.content Intent hashCode

List of usage examples for android.content Intent hashCode

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:Main.java

public static Intent createShortcutIntent(String url) {
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
    shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    return shortcutIntent;
}

From source file:org.wso2.emm.agent.api.ApplicationManager.java

/**
 * Creates a webclip on the device home screen.
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 *//*from w  ww.j  a v  a 2  s . c  o  m*/
public void manageWebAppBookmark(String url, String title, String operationType) throws AndroidAgentException {
    final Intent bookmarkIntent = new Intent();
    final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();

    actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_bookmark));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AndroidAgentException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcast(bookmarkIntent);
}

From source file:org.wso2.app.catalog.api.ApplicationManager.java

/**
 * Creates a webclip on the device home screen.
 *
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 *///  w  w w .j av a 2  s  .  c om
public void manageWebAppBookmark(String url, String title, String operationType) throws AppCatalogException {
    final Intent bookmarkIntent = new Intent();
    final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();

    actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_bookmark));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AppCatalogException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcast(bookmarkIntent);
}

From source file:com.packpublishing.asynchronousandroid.chapter6.SMSDispatcher.java

void processDelivered(Context context, Intent intent) {

    String to = intent.getStringExtra(TO_KEY);
    String text = intent.getStringExtra(TEXT_KEY);
    String title = null;// ww  w  .  j  a v a 2 s  . co  m

    switch (getResultCode()) {
    case Activity.RESULT_OK:
        title = "Message Delivered to " + to;
        break;
    default:
        title = "Message Delivery failed to " + to;
        break;
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(text).setSmallIcon(android.R.drawable.stat_notify_chat)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    nm.notify(intent.hashCode(), builder.build());

}

From source file:com.packpublishing.asynchronousandroid.chapter6.SMSDispatcherAsync.java

void processDelivered(Context context, Intent intent) {

    String to = intent.getStringExtra(TO_KEY);
    String text = intent.getStringExtra(TEXT_KEY);
    String title = null;/*  w  ww. j  a  va2 s  .  c  o m*/

    switch (getResultCode()) {
    case Activity.RESULT_OK:
        title = "Message Delivered to " + to;
        break;
    default:
        title = "Message Delivery failed to " + to;
        break;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(text).setSmallIcon(android.R.drawable.stat_notify_chat)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(intent.hashCode(), builder.build());

}

From source file:org.wso2.iot.agent.api.ApplicationManager.java

/**
 * Creates a webclip on the device home screen.
 *
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 */// www . jav  a2 s  . c  o  m
public void manageWebAppBookmark(String url, String title, String operationType) throws AndroidAgentException {
    final Intent bookmarkIntent = new Intent();
    final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();

    actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_bookmark));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AndroidAgentException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcastAsUser(bookmarkIntent, android.os.Process.myUserHandle());
}

From source file:com.playtech.ezpush.gcm.GcmIntentService.java

private void showNotification(Bundle extras) {

    Intent intent = new Intent(getApplicationContext(), MainActivity.class);

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(this.NOTIFICATION_SERVICE);
    CharSequence message = extras.getString(EXTRA_MESSAGE);
    intent.putExtra(NOTIFICATION_MESSAGE, message);

    CharSequence title = extras.getString(EXTRA_HEADER);
    if (title == null)
        title = NOTIFICATION_TITLE;/*w  ww .j  ava  2  s.  co  m*/

    String aid = extras.getString("application_id");
    intent.putExtra("APP_ID", aid);

    String nid = extras.getString("nid");
    intent.putExtra("NOTIFICATION_ID", nid);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    Notification.InboxStyle style = new Notification.InboxStyle();
    style.addLine(message);

    for (String s : extras.keySet()) {
        if (!containsKey(s)) {
            style.addLine(s + ":" + extras.getString(s));
        }
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, intent.hashCode(), intent,
            PendingIntent.FLAG_ONE_SHOT);
    Notification.Builder nb = new Notification.Builder(this).setContentTitle(title).setContentText(message)
            .setSmallIcon(R.mipmap.ezpush_logo)
            .setLargeIcon(loadBitmap("http://ursynoteka.pl/wp-content/uploads/2012/04/message_new.png"))
            .setStyle(style).setContentIntent(pendingIntent).setAutoCancel(true);

    if (extras.containsKey(EXTRA_SOUND)) {
        nb.setSound(Uri.parse(extras.getString(EXTRA_SOUND)));
    }
    if (extras.containsKey(EXTRA_BANNER)) {
        Bitmap bitmap = loadBitmap(extras.getString(EXTRA_BANNER));
        if (bitmap != null) {
            NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
                    .setBigContentTitle(NOTIFICATION_TITLE).setSummaryText(message).bigPicture(bitmap);
        }
    }
    if (extras.containsKey(EXTRA_ICON)) {
        String iconUrl = extras.getString(EXTRA_ICON);
        Bitmap bitmap = loadBitmap(iconUrl);
        if (bitmap != null) {
            nb.setLargeIcon(bitmap);
        }
    }

    Notification notification = nb.build();

    notificationManager.notify(notification.hashCode(), notification);
}

From source file:org.mozilla.gecko.FilePickerResultHandler.java

@Override
public void onActivityResult(int resultCode, Intent intent) {
    if (resultCode != Activity.RESULT_OK) {
        sendResult("");
        return;//from w  ww . j  av a  2s .c o  m
    }

    // Camera results won't return an Intent. Use the file name we passed to the original intent.
    // In Android M, camera results return an empty Intent rather than null.
    if (intent == null || (intent.getAction() == null && intent.getData() == null)) {
        if (mImageName != null) {
            File file = new File(Environment.getExternalStorageDirectory(), mImageName);
            sendResult(file.getAbsolutePath());
        } else {
            sendResult("");
        }
        return;
    }

    Uri uri = intent.getData();
    if (uri == null) {
        sendResult("");
        return;
    }

    // Some file pickers may return a file uri
    if ("file".equals(uri.getScheme())) {
        String path = uri.getPath();
        sendResult(path == null ? "" : path);
        return;
    }

    final FragmentActivity fa = (FragmentActivity) GeckoAppShell.getGeckoInterface().getActivity();
    final LoaderManager lm = fa.getSupportLoaderManager();
    // Finally, Video pickers and some file pickers may return a content provider.
    Cursor cursor = null;
    try {
        // Try a query to make sure the expected columns exist
        final ContentResolver cr = fa.getContentResolver();
        cursor = cr.query(uri, new String[] { MediaStore.Video.Media.DATA }, null, null, null);

        int index = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
        if (index >= 0) {
            lm.initLoader(intent.hashCode(), null, new VideoLoaderCallbacks(uri));
            return;
        }
    } catch (Exception ex) {
        // We'll try a different loader below
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    lm.initLoader(uri.hashCode(), null, new FileLoaderCallbacks(uri, cacheDir, tabId));
}