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:edu.mit.media.funf.probe.Probe.java

/**
 * Updates request list with items in queue, replacing duplicate pending intents for this probe.
 * @param requests/*www .  ja  v  a  2  s.  c om*/
 */
private void updateRequests(boolean removeRunOnce) {
    assert requestsIntent != null;
    boolean hasChanges = false;
    ArrayList<Intent> requests = requestsIntent.getParcelableArrayListExtra(INTERNAL_REQUESTS_KEY);
    if (requests == null) {
        hasChanges = true;
        requests = new ArrayList<Intent>();
    }

    // Remove run once requests
    Parameter periodParam = Parameter.getAvailableParameter(getAvailableParameters(), Parameter.Builtin.PERIOD);
    if (periodParam != null && removeRunOnce) {
        for (Intent request : requests) {
            ArrayList<Bundle> dataRequests = Utils.getArrayList(request.getExtras(), REQUESTS_KEY);
            List<Bundle> runOnceDataRequests = new ArrayList<Bundle>();
            for (Bundle dataRequest : dataRequests) {
                long periodValue = Utils.getLong(dataRequest, Parameter.Builtin.PERIOD.name,
                        (Long) periodParam.getValue());
                if (periodValue == 0L) {
                    Log.d(TAG, "Removing run once dataRequest: " + dataRequest);
                    runOnceDataRequests.add(dataRequest);
                }
            }
            dataRequests.removeAll(runOnceDataRequests);
            if (dataRequests.isEmpty()) {
                deadRequests.add(request);
            } else {
                request.putExtra(REQUESTS_KEY, dataRequests);
            }
        }
    }

    // Remove all requests that we aren't able to (or supposed to) send to anymore
    if (!deadRequests.isEmpty()) {
        hasChanges = true;
        for (Intent deadRequest = deadRequests.poll(); deadRequest != null; deadRequest = deadRequests.poll()) {
            Log.d(TAG, "Removing dead request: " + deadRequest);
            requests.remove(deadRequest);
        }
    }
    // Add any pending requests
    if (!pendingRequests.isEmpty()) {
        hasChanges = true;
        Map<PendingIntent, Intent> existingCallbacksToRequests = new HashMap<PendingIntent, Intent>();
        for (Intent existingRequest : requests) {
            PendingIntent callback = existingRequest.getParcelableExtra(CALLBACK_KEY);
            existingCallbacksToRequests.put(callback, existingRequest);
        }
        for (Intent request = pendingRequests.poll(); request != null; request = pendingRequests.poll()) {
            PendingIntent callback = request.getParcelableExtra(CALLBACK_KEY);
            if (packageHasRequiredPermissions(this, callback.getTargetPackage(), getRequiredPermissions())) {
                existingCallbacksToRequests.containsKey(callback);
                int existingRequestIndex = requests.indexOf(existingCallbacksToRequests.get(callback));
                ArrayList<Bundle> dataRequests = Utils.getArrayList(request.getExtras(), REQUESTS_KEY);
                Log.d(TAG, "Adding pending intent with data requests: " + dataRequests);
                if (existingRequestIndex >= 0) {
                    if (dataRequests == null || dataRequests.isEmpty()) {
                        Log.d(TAG, "Adding pending intent, removing because empty or null");
                        requests.remove(existingRequestIndex);
                    } else {
                        requests.set(existingRequestIndex, request);
                    }
                } else {
                    if (dataRequests != null && !dataRequests.isEmpty()) { // Only add requests with nonempty data requests
                        Log.d(TAG, "Adding new pending intent: " + request);
                        requests.add(request);
                    }
                }
            } else {
                Log.w(TAG, "Package '" + callback.getTargetPackage()
                        + "' does not have the required permissions to get data from this probe.");
            }
        }
    }

    if (hasChanges) {
        requestsIntent.putExtra(INTERNAL_REQUESTS_KEY, requests);
        updateInternalRequestsPendingIntent();
    }
}

From source file:com.gmail.at.faint545.services.DataQueueService.java

@Override
protected void onHandleIntent(Intent intent) {
    String url = intent.getStringExtra("url");
    String api = intent.getStringExtra("api");
    StringBuilder results = new StringBuilder();

    HttpClient client = new DefaultHttpClient();
    HttpPost request = new HttpPost(url);

    ArrayList<NameValuePair> arguments = new ArrayList<NameValuePair>();
    arguments.add(new BasicNameValuePair(SabnzbdConstants.APIKEY, api));
    arguments.add(new BasicNameValuePair(SabnzbdConstants.OUTPUT, SabnzbdConstants.OUTPUT_JSON));
    arguments.add(new BasicNameValuePair(SabnzbdConstants.MODE, SabnzbdConstants.MODE_QUEUE));

    try {//from   ww w .jav  a  2  s.  co  m
        request.setEntity(new UrlEncodedFormEntity(arguments));
        HttpResponse result = client.execute(request);
        InputStream inStream = result.getEntity().getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(inStream), 8);
        String line;
        while ((line = br.readLine()) != null) {
            if (line.length() > 0) {
                results.append(line);
            }
        }
        br.close();
        inStream.close();

        Bundle extras = intent.getExtras();
        Messenger messenger = (Messenger) extras.get("messenger");
        Message message = Message.obtain();

        Bundle resultsBundle = new Bundle();
        resultsBundle.putString("results", results.toString());
        message.setData(resultsBundle);

        messenger.send(message);
        stopSelf();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

/** public API - get info on peer */
public synchronized PeerRequestInfo getPeer(Intent i) {
    String sourceip = i.getExtras().getString(EXTRA_SOURCEIP);
    String name = i.getExtras().getString(EXTRA_NAME);
    for (PeerRequestInfo pi : peerRequests) {
        if (pi.instanceName.equals(name) && pi.src.getHostAddress().equals(sourceip))
            return pi;
    }//from w ww  .  j  av a  2s . co  m
    return null;
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

private synchronized ClientInfo getClientInfo(Intent triggerIntent) {
    String id = triggerIntent.getExtras().getString(EXTRA_ID);
    for (ClientInfo ci : clients) {
        if (ci.id.equals(id))
            return ci;
    }//from w  ww  .j a v a 2s  .co  m
    return null;
}

From source file:com.netease.qa.emmagee.service.EmmageeService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(LOG_TAG, "service onStart");
    PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0,
            new Intent(this, MainPageActivity.class), 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon).setWhen(System.currentTimeMillis())
            .setAutoCancel(true).setContentTitle("ETest");
    startForeground(startId, builder.build());

    HttpUtils.testSuitId = 0;/*  w w w.  j  a v a2s.co  m*/
    pid = intent.getExtras().getInt("pid");
    uid = intent.getExtras().getInt("uid");
    processName = intent.getExtras().getString("processName");
    packageName = intent.getExtras().getString("packageName");
    startActivity = intent.getExtras().getString("startActivity");
    appVersion = intent.getExtras().getString("appVersion");

    cpuInfo = new CpuInfo(getBaseContext(), pid, Integer.toString(uid));
    readSettingInfo();
    if (isFloating) {
        viFloatingWindow = LayoutInflater.from(this).inflate(R.layout.floating, null);
        txtUnusedMem = (TextView) viFloatingWindow.findViewById(R.id.memunused);
        txtTotalMem = (TextView) viFloatingWindow.findViewById(R.id.memtotal);
        txtTraffic = (TextView) viFloatingWindow.findViewById(R.id.traffic);
        btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi);

        wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        if (wifiManager.isWifiEnabled()) {
            btnWifi.setText(R.string.close_wifi);
        } else {
            btnWifi.setText(R.string.open_wifi);
        }
        txtUnusedMem.setText(getString(R.string.calculating));
        txtUnusedMem.setTextColor(android.graphics.Color.RED);
        txtTotalMem.setTextColor(android.graphics.Color.RED);
        txtTraffic.setTextColor(android.graphics.Color.RED);
        btnStop = (Button) viFloatingWindow.findViewById(R.id.stop);
        btnStop.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("isServiceStop", true);
                intent.setAction(SERVICE_ACTION);
                sendBroadcast(intent);

                stopSelf();
            }
        });
        createFloatingWindow();
    }
    createResultCsv();
    if (isRoot) {
        getlog();
    }
    handler.postDelayed(task, 1000);
    return START_NOT_STICKY;
}

From source file:com.yourkey.billing.util.InAppBilling.java

public void onActivityResult(int activityResultCode, Intent data) {
    // any result but OK we will assume user cancelled the activity
    if (activityResultCode != Activity.RESULT_OK) {
        // unbind service
        dispose();/*w w  w  .j  a  v a 2  s .c om*/

        // user canceled
        inAppBillingListener.inAppBillingCanceled();
        return;
    }

    int result = getResponseCodeFromBundle(data.getExtras());
    if (result != RESULT_OK) {
        // unbind service
        dispose();

        // user canceled the purchase
        if (result == RESULT_USER_CANCELED) {
            inAppBillingListener.inAppBillingCanceled();
        }

        // purchase was canceled for other reason
        else {
            inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_PURCHASE_FAILED, result));
        }
        return;
    }

    // extract purchased data and signature
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    // invalid response
    if (purchaseData == null || signature == null || !verifySignature(purchaseData, signature)) {
        // unbind service
        dispose();

        // invalid response
        inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_INVALID_PURCHASE_RESPONSE));
        return;
    }

    // final test make sure we received the same sku we wanted
    try {
        // create json object
        JSONObject jsonObject = new JSONObject(purchaseData);

        // verify product id
        if (!jsonObject.optString(KEY_PRODUCT_ID).equals(itemSku)) {
            // unbind service
            dispose();

            // invalid response
            inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_INVALID_PURCHASE_RESPONSE));
            return;
        }

        // NOTE TO PROGRAMMERS
        // the jsonObject contains the following information
        // "orderId":"12999763169054705758.1371079406387615"
        // "packageName":"com.example.app",
        // "productId":"exampleSku",
        // "purchaseTime":1345678900000, (msec since 1970/01/01)
        // "purchaseState":0,  // 0-purchased, 1 canceled, 2 refunded
        // "developerPayload":"example developer payload"
        // "purchaseToken" : "122333444455555",

    }

    catch (Exception e) {
        // unbind service
        dispose();

        // invalid response
        inAppBillingListener.inAppBillingFailure(exceptionMessage(PLAY_STORE_INVALID_PURCHASE_RESPONSE, e));
        return;
    }

    // unbind service
    dispose();

    // success
    inAppBillingListener.inAppBillingBuySuccsess();
    return;
}

From source file:edu.mit.media.funf.probe.Probe.java

/**
 * Send some values to each requesting pending intent
 * @param valuesIntent/* w  w w  . j  av a2  s.c  o m*/
 */
protected void _callback_registered(Intent valuesIntent, PendingIntent callback) {
    long epochTimestamp = valuesIntent.getLongExtra(TIMESTAMP, 0L);
    Set<PendingIntent> callbacks = new HashSet<PendingIntent>();
    if (callback != null) {
        callbacks.add(callback);
    }
    ArrayList<Intent> requests = null;
    if (requestsIntent != null) {
        requests = requestsIntent.getParcelableArrayListExtra(INTERNAL_REQUESTS_KEY);
    }

    if (ACTION_DATA.equals(valuesIntent.getAction())) {
        // Send to all requesters
        if (requests != null && !requests.isEmpty()) {
            JSONObject dataSentTimes = null;
            try {
                dataSentTimes = new JSONObject(
                        getHistoryPrefs().getString(MOST_RECENT_DATA_BY_REQUEST_KEY, "{}"));
            } catch (JSONException e) {
                Log.e(TAG, "Unable to parse data sent history.");
                dataSentTimes = new JSONObject();
            }

            Parameter[] availableParameters = getAvailableParameters();
            for (Intent request : requests) {
                PendingIntent requesterCallback = request.getParcelableExtra(CALLBACK_KEY);
                ArrayList<Bundle> dataRequests = Utils.getArrayList(request.getExtras(), REQUESTS_KEY);

                for (Bundle dataRequest : dataRequests) {
                    String requestKey = normalizedStringRepresentation(dataRequest, getAvailableParameters());
                    long lastDataSentTime = dataSentTimes.optLong(requestKey);
                    // TODO: If data request accepts passive data, but also needs data enforced on a schedule
                    // we may need to make logic more complicated
                    if (isDataRequestSatisfied(dataRequest, availableParameters, epochTimestamp,
                            lastDataSentTime)
                            || isDataRequestAcceptingPassiveData(dataRequest, availableParameters)) {
                        callbacks.add(requesterCallback);
                        try {
                            dataSentTimes.put(requestKey, epochTimestamp);
                        } catch (JSONException e) {
                            Log.e(TAG, "Unable to store data sent time in .");
                        }
                    }
                }
            }

            // Save the data sent times
            getHistoryPrefs().edit().putString(MOST_RECENT_DATA_BY_REQUEST_KEY, dataSentTimes.toString())
                    .putLong(MOST_RECENT_DATA_KEY, epochTimestamp).commit();
        }

    } else {
        // Add all
        for (Intent request : requests) {
            PendingIntent requesterCallback = request.getParcelableExtra(CALLBACK_KEY);
            callbacks.add(requesterCallback);
        }
    }

    Log.d(TAG, "Sent probe data at " + epochTimestamp);
    for (PendingIntent requesterCallback : callbacks) {
        try {
            requesterCallback.send(this, 0, valuesIntent);
        } catch (CanceledException e) {
            Log.w(TAG, "Unable to send to canceled pending intent at " + epochTimestamp);
            Map<PendingIntent, Intent> callbacksToRequests = getCallbacksToRequests(requests);
            Intent request = callbacksToRequests.get(requesterCallback);
            if (request != null) {
                deadRequests.add(request);
            }
        }
    }

    updateRequests();
}

From source file:com.cwp.cmoneycharge.activity.AddPayActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        onResults(data.getExtras());
    }// w w w  .jav a  2  s  . c  o  m
    switch (requestCode) {
    case 102:
        if (resultCode == 3 || resultCode == 0) {
            if ((Bimp.drr.size() != 0) && (Bimp.smdrr.size() != 0)) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < Bimp.drr.size(); i++) {
                    sb.append(Bimp.drr.get(i) + ",");
                }
                for (int i = 0; i < Bimp.drr.size(); i++) {
                    sb.append(Bimp.smdrr.get(i) + ",");
                }
                textphoto = sb.toString().substring(0, sb.length() - 1);
                initphoto();
            } else {
                textphoto = "";
                initphoto();
            }

        }
    }

}