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:com.inbeacon.cordova.CordovaInbeaconManager.java

/**
 * Transform Android event data into JSON Object used by JavaScript
 * @param intent inBeacon SDK event data
 * @return a JSONObject with keys 'event', 'name' and 'data'
 *//*from ww  w.j  a va2 s.c  om*/
private JSONObject getEventObject(Intent intent) {
    String action = intent.getAction();
    String event = action.substring(action.lastIndexOf(".") + 1); // last part of action
    String message = intent.getStringExtra("message");
    Bundle extras = intent.getExtras();

    JSONObject eventObject = new JSONObject();
    JSONObject data = new JSONObject();

    try {
        if (extras != null) {
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                data.put(key, extras.get(key)); // Android API < 19
                //                    data.put(key, JSONObject.wrap(extras.get(key)));    // Android API >= 19
            }
        }
        data.put("message", message);

        eventObject.put("name", event);
        eventObject.put("data", data);

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
    }

    return eventObject;
}

From source file:edu.cloud.iot.reception.ocr.FaceRecognitionActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    // setContentView(R.layout.fragment_camera);
    Log.i("EDebug::FaceRecog OnCreate: ", "In OnCreate");
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
    }//  w ww . j  a  v a 2 s .c  om

    setUpCamera();
    Intent intent = getIntent();
    // String message = intent.getStringExtra("Check1");
    extras = intent.getExtras();
    // message = "Check1::"+ (String) extras.get("Check1");
    Bundle b = (Bundle) extras.get("list");
    // ArrayList<String> al = (ArrayList<String>) b.get("al");
    ocrResponse = (ArrayList<String>) b.get("ocrresponse");
    licenseBytes = (byte[]) b.get("licensebytes");
    licenseImgPath = (String) b.get("licenseImgPath");

    try {
        // ocrResponse = new ArrayList<String>();
        // ocrResponse.add("V& LIMITED TERM");
        // ocrResponse.add("IDENTIFICATION CARD");
        // ocrResponse.add("Lid 37998217");
        // ocrResponse.add("La iss 12/20/2013 4b Exp 10/30/2016");
        // ocrResponse.add("13 DOB 10/29/1991");
        // ocrResponse.add("1ARRABOLU");
        // ocrResponse.add("2 VEERA VENKATA RAVI TEJA");
        // ocrResponse.add("8 7777 MCCALLUM BLVD #316");
        // ocrResponse.add( "RICHARDSON TX 75252");
        // ocrResponse.add("16 Hgt 5-11   15   Sex   M   16   E");
        // ocrResponse.add("5 DD 01114301126250715756");

        // Bitmap baseImg =
        // BitmapFactory.decodeFile(String.valueOf(Environment.getExternalStoragePublicDirectory((
        // Environment.DIRECTORY_PICTURES + "/IOT/dule00.jpg"))));
        // ByteArrayOutputStream bos = new ByteArrayOutputStream();
        // baseImg.compress(Bitmap.CompressFormat.JPEG, 100, bos);
        // licenseBytes = bos.toByteArray();
        // bos.flush();
        // bos.close();
        // Log.i("EDebug::compareImageBytes = ",""+licenseBytes.length);
        //
        // Bitmap compImg =
        // BitmapFactory.decodeFile(String.valueOf(Environment.getExternalStoragePublicDirectory((
        // Environment.DIRECTORY_PICTURES + "/IOT/dule02.jpg"))));
        // ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
        // compImg.compress(Bitmap.CompressFormat.JPEG, 100, bos2);
        // compareImageBytes = bos2.toByteArray();
        // bos2.flush();
        // bos2.close();
        // Log.i("EDebug::compareImageBytes = ",""+compareImageBytes.length);
    } catch (Exception ex) {
        Log.e("EDebug::OnCreate Error - ", "Error::" + ex.getLocalizedMessage() + "::" + ex.getMessage());
    }
    // Log.i("EDebug::FaceRecog OnCreate: ", message);
    Log.i("EDebug::FaceRecog OnCreate: licenseImgPath = ", "" + licenseImgPath);
    Log.i("EDebug::FaceRecog OnCreate: ocrResponse=", "" + ocrResponse.toString());
    Log.i("EDebug::FaceRecog OnCreate: licenseBytes = ", "" + licenseBytes.length);
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

/**
 * //  w  w  w  .  j  av a2  s .c  om
 * @return a map that contains objects with the following keys:
 * 
 *         delete - the url used to delete the uploaded image (null if
 *         error).
 * 
 *         original - the url to the uploaded image (null if error) The map
 *         is null if error
 */
private Map<String, String> handleSendIntent(final Intent intent) {
    Log.i(this.getClass().getName(), "in handleResponse()");

    Log.d(this.getClass().getName(), intent.toString());
    final Bundle extras = intent.getExtras();
    try {
        //upload a new image
        if (Intent.ACTION_SEND.equals(intent.getAction()) && (extras != null)
                && extras.containsKey(Intent.EXTRA_STREAM)) {

            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (uri != null) {
                Log.d(this.getClass().getName(), uri.toString());
                // store uri so we can create the thumbnail if we succeed
                imageLocation = uri;
                final String jsonOutput = readPictureDataAndUpload(uri);
                return parseJSONResponse(jsonOutput);
            }
            Log.e(this.getClass().getName(), "URI null");
        }
    } catch (final Exception e) {
        Log.e(this.getClass().getName(), "Completely unexpected error", e);
    }
    return null;
}

From source file:org.ambientdynamix.core.HomeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode == Activity.RESULT_OK) {
        final Bundle extras = intent.getExtras();
        switch (requestCode) {
        case ACTIVITY_EDIT:
            // Access the serialized app coming in from the Intent's Bundle
            // extra
            final DynamixApplication app = (DynamixApplication) extras.getSerializable("app");
            // Update the DynamixService with the updated application
            DynamixService.updateApplication(app);
            refresh();//from   ww  w  .java  2 s  .co m
            break;
        }
    }
}

From source file:com.commonsware.cwac.locpoll.demo.LocationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;// w  w  w .  j ava  2s. c  o m

    File log = new File(Environment.getExternalStorageDirectory(), "LocationLog.txt");

    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(log.getAbsolutePath(), log.exists()));

        out.write(new Date().toString());
        out.write(" : ");

        Bundle b = intent.getExtras();
        loc = (Location) b.get(LocationPoller.EXTRA_LOCATION);
        String msg;

        if (loc == null) {
            loc = (Location) b.get(LocationPoller.EXTRA_LASTKNOWN);

            if (loc == null) {
                msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR);
            } else {
                msg = "TIMEOUT, lastKnown=" + loc.toString();
            }
        } else {
            msg = loc.toString();
            Log.d("Location Poller", msg);

            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

            if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA)) {
                Log.d("Type", "3g");// for 3g HSDPA networktype will be return as
                // per testing(real) in device with 3g enable data
                // and speed will also matters to decide 3g network type
                type = 2;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPAP)) {
                Log.d("Type", "4g"); // /No specification for the 4g but from wiki
                // i found(HSPAP used in 4g)
                // http://goo.gl/bhtVT
                type = 3;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) {
                Log.d("Type", "GPRS");
                type = 1;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)) {
                Log.d("Type", "EDGE 2g");
                type = 0;
            }

            /* Update the listener, and start it */
            MyListener = new MyPhoneStateListener();
            Tel = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
            Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        if (msg == null) {
            msg = "Invalid broadcast received!";
        }

        out.write(msg);
        out.write("\n");
        out.close();
    } catch (IOException e) {
        Log.e(getClass().getName(), "Exception appending to log file", e);
    }
}

From source file:io.teak.sdk.Session.java

/**
 * Process an Intent and assign new values for launching from a deep link or Teak notification.
 * <p/>/*from   w  w w . ja  v  a 2  s .  co m*/
 * If currentSession was launched via a deep link or notification, and the incoming intent has
 * a new (non null/empty) value. Create a new Session, cloning state from the old one.
 *
 * @param intent Incoming Intent to process.
 */
public static void processIntent(Intent intent, @NonNull AppConfiguration appConfiguration,
        @NonNull DeviceConfiguration deviceConfiguration) {
    if (intent == null)
        return;

    synchronized (currentSessionMutex) {
        // Call getCurrentSession() so the null || Expired logic stays in one place
        getCurrentSession(appConfiguration, deviceConfiguration);

        // Check for launch via deep link
        String intentDataString = intent.getDataString();
        String launchedFromDeepLink = null;
        if (intentDataString != null && !intentDataString.isEmpty()) {
            launchedFromDeepLink = intentDataString;
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Launch from deep link: " + launchedFromDeepLink);
            }
        }

        // Check for launch via notification
        Bundle bundle = intent.getExtras();
        String launchedFromTeakNotifId = null;
        if (bundle != null) {
            String teakNotifId = bundle.getString("teakNotifId");
            if (teakNotifId != null && !teakNotifId.isEmpty()) {
                launchedFromTeakNotifId = teakNotifId;
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Launch from Teak notification: " + launchedFromTeakNotifId);
                }
            }
        }

        // If the current session has a launch from deep link/notification, and there is a new
        // deep link/notification, it's a new session
        if (stringsAreNotNullOrEmptyAndAreDifferent(currentSession.launchedFromDeepLink, launchedFromDeepLink)
                || stringsAreNotNullOrEmptyAndAreDifferent(currentSession.launchedFromTeakNotifId,
                        launchedFromTeakNotifId)) {
            Session oldSession = currentSession;
            currentSession = new Session(oldSession.appConfiguration, oldSession.deviceConfiguration);
            currentSession.userId = oldSession.userId;
            currentSession.attributionChain.addAll(oldSession.attributionChain);

            oldSession.setState(State.Expiring);
            oldSession.setState(State.Expired);
        }

        // Assign attribution
        if (launchedFromDeepLink != null && !launchedFromDeepLink.isEmpty()) {
            currentSession.launchedFromDeepLink = launchedFromDeepLink;
            currentSession.attributionChain.add(launchedFromDeepLink);
        } else if (launchedFromTeakNotifId != null && !launchedFromTeakNotifId.isEmpty()) {
            currentSession.launchedFromTeakNotifId = launchedFromTeakNotifId;
            currentSession.attributionChain.add(launchedFromTeakNotifId);
        }
    }
}

From source file:com.irontec.mintzatu.EzarpenakDetailActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TWITTER_AUTH) {
        if (resultCode == Activity.RESULT_OK) {
            final String oauthVerifier = (String) data.getExtras().get("oauth_verifier");
            if (oauthVerifier != null && oauthVerifier != "") {
                new Thread(new Runnable() {
                    AccessToken accessToken = null;

                    public void run() {
                        try {
                            accessToken = twitter.getOAuthAccessToken(requestToken, oauthVerifier);
                            Editor e = TwitterHelper.getTwitterPrerefencesEditor(mContext);
                            e.putString(TwitterHelper.PREF_KEY_TOKEN, accessToken.getToken());
                            e.putString(TwitterHelper.PREF_KEY_SECRET, accessToken.getTokenSecret());
                            e.commit();//from  ww  w  . ja va2 s.  c  o  m
                        } catch (TwitterException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }
    }
}

From source file:cc.softwarefactory.lokki.android.androidServices.LocationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Log.d(TAG, "onStartCommand invoked");

    if (intent == null) {
        return START_STICKY;
    }//from w ww.j a  v  a  2  s.  c o m

    Bundle extras = intent.getExtras();

    if (extras == null) {
        return START_STICKY;
    }

    if (extras.containsKey(RUN_1_MIN)) {
        Log.d(TAG, "onStartCommand RUN_1_MIN");
        setTemporalTimer();
    } else if (extras.containsKey(ALARM_TIMER)) {
        Log.d(TAG, "onStartCommand ALARM_TIMER");
        stopSelf();
    }
    return START_STICKY;
}

From source file:com.fastbootmobile.rssdemo.PushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "ACTION : " + intent.getAction()); // Debug log the intent "action"

    // Get the shared preferences for OwnPush keys
    SharedPreferences pref = context.getApplicationContext().getSharedPreferences(OwnPushClient.PREF_PUSH,
            Context.MODE_PRIVATE);

    if (intent.getAction().equals(OwnPushClient.INTENT_RECEIVE)) {

        // This is a push message

        Log.d(TAG, "Decrypt : " + intent.getExtras().getString(OwnPushClient.EXTRA_DATA));

        OwnPushCrypto fp = new OwnPushCrypto(); // Create a crypto object for decrypt

        // Get the app key pair from shared preferences (these have been confirmed by the register intent)
        OwnPushCrypto.AppKeyPair keys = fp.getKey(pref.getString(OwnPushClient.PREF_PUBLIC_KEY, ""),
                pref.getString(OwnPushClient.PREF_PRIVATE_KEY, ""));

        // Decrypt the message from the intent extra data
        String msg = fp.decryptFromIntent(intent.getExtras(), BuildConfig.APP_PUBLIC_KEY, keys);

        JSONObject jObj;/* w w  w .  j av a 2  s  .c om*/
        if (msg != null) {
            Log.e(TAG, "RSS : " + msg);

            try {
                // Decode the JOSN data in the message
                jObj = new JSONObject(msg);

                Intent i = new Intent(Intent.ACTION_VIEW); // Create the intent
                i.setData(Uri.parse(jObj.getString("link"))); // Set the data using URI (these are web links)

                // Convert to pending intent
                PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), i,
                        0);

                // Create the notification
                Notification n = new Notification.Builder(context.getApplicationContext())
                        .setContentTitle("OwnPush RSS") // Main Title
                        .setContentText(jObj.getString("title")) // Set content
                        .setContentIntent(pIntent) // Add the pending intent
                        .setSmallIcon(R.drawable.ic_done).setAutoCancel(true) // Remove notification if opened
                        .build();

                n.defaults |= Notification.DEFAULT_SOUND; // Make some noise on push

                // Get the notification manager and display notification
                NotificationManager notificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(notification_num, n);

                // Increase the notification counter by 1
                notification_num++;

            } catch (Exception e) {
                return;
            }

        }
    }
}

From source file:com.scigames.slidegame.ObjectiveActivity.java

@Override
protected void onNewIntent(Intent i) {
    View thisView = findViewById(R.id.objective_page); //find view
    setContentView(thisView);//from w w  w .  jav a  2 s  . c o m
    thisView.setBackgroundResource(R.drawable.bg_blank);
    objectiveImgNum = 0;
    objectiveImg = null;
    if (i.getExtras().getString("slideLevel") != null) {
        Log.d(TAG, "onNewIntent!");
        rfidIn = i.getStringExtra("rfid");
        studentIdIn = i.getStringExtra("studentId");
        slideLevelIn = i.getStringExtra("slideLevel");

        String thisSlideLevel = i.getExtras().getString("slideLevel");
        getObjectiveImages(slideLevelIn);
    }

}