Example usage for android.content Intent getExtras

List of usage examples for android.content Intent getExtras

Introduction

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

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Retrieves a map of extended data from the intent.

Usage

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    Log.i("PEP", "in addTaintInformationToIntent(Intent i, HashSet<String> taintCategories)");

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();//w w  w. j  a  va  2 s . com

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:Main.java

public static void intentToAndroidLayoutMapper(Class<?> classObj, Intent intent, String prefixStr,
        Activity view) {// www.j  av a  2 s .com

    Bundle map = intent.getExtras();

    for (Object keyObj : map.keySet().toArray()) {
        String keyStr = keyObj.toString();
        Field fieldObj = null;
        try {
            fieldObj = classObj.getField(prefixStr + "_" + keyStr);
        } catch (NoSuchFieldException e) {
            continue;
        }
        Object layoutObj = null;
        try {
            layoutObj = fieldObj.get(fieldObj);
        } catch (IllegalAccessException e) {
            continue;
        }
        Integer layoutIntvalue = (Integer) layoutObj;

        View selectedView = view.findViewById(layoutIntvalue);

        if (selectedView instanceof TextView) {
            TextView textView = (TextView) selectedView;
            textView.setText((String) map.get(keyStr));
        } else if (selectedView instanceof ImageView) {
            ImageView imageView = (ImageView) selectedView;

        }

    }

}

From source file:Main.java

public static void dumpBundleKeys(Intent intent) {
    if (intent == null) {
        Log.d(TAG, "intent is null");
        return;//from ww w  .  jav  a  2s.  c  o m
    }
    dumpBundleKeys(intent.getExtras());
}

From source file:com.freshplanet.nativeExtensions.Extension.java

public static String getParametersFromIntent(Intent intent) {
    JSONObject paramsJson = new JSONObject();
    Bundle bundle = intent.getExtras();
    String parameters = intent.getStringExtra("parameters");
    try {/* w ww  .  j  a v  a 2 s  . c  o  m*/
        for (String key : bundle.keySet()) {
            paramsJson.put(key, bundle.getString(key));
        }

        if (parameters != null) {
            paramsJson.put("parameters", new JSONObject(parameters));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return paramsJson.toString();
}

From source file:de.da_sense.moses.client.com.C2DMReceiver.java

private static void handleNotifications(Context context, Intent intent) {
    try {/*  w  w w  . ja va 2  s  . c  om*/
        JSONObject message = new JSONObject(intent.getExtras().getString("message"));
        Log.v(LOG_TAG, "handleNotifications() message=" + message);
        String messagetype = message.getString(GCM_MESSAGETYPE_FIELD);
        if (messagetype.equals(GCM_PUSH_MESSAGTYPE_USERSTUDY)) {
            String apkidString = message.getString(GCM_USERSTUDY_APKID_FIELD);
            Log.i(LOG_TAG, "User study notification received!! APK ID = " + apkidString);
            UserstudyNotificationManager.userStudyNotificationArrived(context, apkidString);
        } else if (messagetype.equals(GCM_PUSH_MESSAGTYPE_UPDATE)) {
            String apkidString = message.getString(GCM_UPDATE_APKID_FIELD);
            Log.i(LOG_TAG, "update notification received!! APK ID = " + apkidString);
            Log.i(LOG_TAG, "update incoming: " + apkidString);
            InstalledExternalApplicationsManager.updateArrived(apkidString);
        } else if (messagetype.equals(GCM_PUSH_MESSAGTYPE_QUEST)) {
            String apkidString = message.getString(GCM_QUEST_APKID_FIELD);
            Log.i(LOG_TAG, "update incoming: " + apkidString);
            if (InstalledExternalApplicationsManager.getInstance().getAppForId(apkidString) != null) {
                // show a notification to user only if the app is still installed
                // the data on the server may be inconsistent
                InstalledExternalApplicationsManager.getInstance().getAppForId(apkidString)
                        .setEndDateReached(true);
                UserstudyNotificationManager.questionnaireNotificationArrived(context, apkidString);
            }

        } else {
            Log.w("MoSeS.C2DM", "Unhandled C2DM Message from type: " + messagetype);
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage());
    }

}

From source file:Main.java

public static String toString(Intent intent) {
    StringBuilder sb = new StringBuilder();
    sb.append(intent.getAction()).append(" ");

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Set<String> sets = bundle.keySet();
        for (String key : sets) {
            if (bundle.get(key) instanceof Integer) {
                sb.append(key).append(":").append(bundle.getInt(key)).append("\n");
            } else if (bundle.get(key) instanceof ArrayList) {
                sb.append(key).append(":").append(Arrays.toString(bundle.getIntegerArrayList(key).toArray()))
                        .append("\n");
            } else if (bundle.get(key) instanceof Parcelable) {
                sb.append(key).append(":").append(bundle.getParcelable(key).toString()).append("\n");
            } else {
                sb.append(key).append(":").append(bundle.getString(key)).append("\n");
            }//w  ww.ja  v  a2 s .  c om
        }

    }

    return sb.toString();
}

From source file:Main.java

public static void dumpIntent(Intent intent) {
    System.out.println("action: " + intent.getAction());
    System.out.println("data: " + intent.getData());
    System.out.println("extras:");
    Bundle bundle = intent.getExtras();
    for (String key : bundle.keySet()) {
        Object object = bundle.get(key);
        System.out.println(key + "->" + object + "(" + object.getClass().getName() + ")");
    }/* w  w w.j  a  v a 2 s.  c  o  m*/
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateNotification(Context context, Intent intent, Handler handler) {
    Bundle extras = intent.getExtras();
    if (extras == null) {
        return;/*from ww  w . ja  v  a  2 s. co m*/
    }

    extras.putBoolean("foregroud", GeneralUtils.isAppOnForeground(context));

    String title = (String) extras.get("title");
    String link = (String) extras.get("l");

    // empty message with no data
    Intent notifyIntent;
    if (link != null) {
        // we want main app class to be launched
        notifyIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        notifyIntent = new Intent(context, PushHandlerActivity.class);
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        // pass all bundle
        notifyIntent.putExtra("pushBundle", extras);
    }

    // first string will appear on the status bar once when message is added
    CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo());
    if (null == appName) {
        appName = "";
    }

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

    NotificationFactory notificationFactory;

    //is this banner notification?
    String bannerUrl = (String) extras.get("b");

    //also check that notification layout has been placed in layout folder
    int layoutId = context.getResources().getIdentifier(BannerNotificationFactory.sNotificationLayout, "layout",
            context.getPackageName());

    if (layoutId != 0 && bannerUrl != null) {
        notificationFactory = new BannerNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    } else {
        notificationFactory = new SimpleNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    }
    notificationFactory.generateNotification();
    notificationFactory.addSoundAndVibrate();
    notificationFactory.addCancel();

    Notification notification = notificationFactory.getNotification();

    notification.contentIntent = PendingIntent.getActivity(context, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (mSimpleNotification) {
        manager.notify(PushManager.MESSAGE_ID, notification);
    } else {
        manager.notify(PushManager.MESSAGE_ID++, notification);
    }

    generateBroadcast(context, extras);
}

From source file:Main.java

public static long interceptLongParam(Bundle savedInstanceState, Intent intent, String paramName) {
    long ret = 0;

    if (savedInstanceState != null) {
        ret = savedInstanceState.getLong(paramName);
    } else {//ww w. j a  va 2 s . c  o  m
        if (intent != null) {
            Bundle incomming = intent.getExtras();
            if (incomming != null) {
                ret = incomming.getLong(paramName);
            }
        }
    }

    return ret;
}

From source file:Main.java

public static int interceptIntParam(Bundle savedInstanceState, Intent intent, String paramName) {
    int ret = -1;

    if (savedInstanceState != null) {
        ret = savedInstanceState.getInt(paramName, -1);
    } else {/*from  ww w  . j  a va 2  s.c  o  m*/
        if (intent != null) {
            Bundle incomming = intent.getExtras();
            if (incomming != null) {
                ret = incomming.getInt(paramName, -1);
            }
        }
    }

    return ret;
}