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.gadelkareem.serverload.ServerLoadConfig.java

@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    // Set the result to CANCELED. This will cause the widget host to cancel
    // out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);/* w  ww  .j  av a  2  s .  co m*/

    // Set the view layout resource to use.
    setContentView(R.layout.serverload_config);

    // Find the EditText
    URL_Input = (EditText) findViewById(R.id.URL);
    servername_Input = (EditText) findViewById(R.id.servername);

    // Bind the action for the save button.
    findViewById(R.id.save_button).setOnClickListener(mOnClickListener);

    // Find the widget id from the intent.
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }

    // If they gave us an intent without the widget id, just bail.
    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
        Log.d(TAG, "Widget id is invalid");
        finish();
    }

    URL_Input.setText(loadPref(ServerLoadConfig.this, appWidgetId, "URL"));
    servername_Input.setText(loadPref(ServerLoadConfig.this, appWidgetId, "servername"));

}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.RviService.java

protected void starting(Intent intent) {
    if (intent != null && intent.getExtras() != null) {
        int btState = intent.getExtras().getInt("bluetooth", BluetoothAdapter.STATE_OFF);
        if (btState == BluetoothAdapter.STATE_ON) {
            Log.w(TAG, "BT on, start ranging");
            br.start();// w  ww .java 2  s. c om
        } else if (btState == BluetoothAdapter.STATE_OFF) {
            Log.w(TAG, "BT off, stop ranging");
            br.stop();
        }
    }
}

From source file:com.johan.vertretungsplan.background.VertretungsplanService.java

@Override
protected void onHandleIntent(Intent intent) {
    context = this;
    settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    extras = intent.getExtras();
    Gson gson = new Gson();

    boolean autoSync;
    try {//from  w  w  w.j  a  v  a  2 s .  c om
        autoSync = extras.getBoolean("AutoSync");
    } catch (NullPointerException e) {
        autoSync = false;
    }

    ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    //wifi
    State wifi = conMan.getNetworkInfo(1).getState();

    if (wifi == NetworkInfo.State.CONNECTED || autoSync == false
            || settings.getBoolean("syncWifi", false) == false) {

        Log.d("Vertretungsplan", "WiFi state: " + wifi);
        Log.d("Vertretungsplan", "autoSync: " + autoSync);
        Log.d("Vertretungsplan", "syncWifi: " + Boolean.valueOf(settings.getBoolean("syncWifi", false)));

        Log.d("Vertretungsplan", "Vertretungsplan wird abgerufen");

        try {
            BaseParser parser = ((VertretungsplanApplication) getApplication()).getParser();

            if (parser == null)
                return;

            Vertretungsplan v = parser.getVertretungsplan();
            settings.edit().putString("Vertretungsplan", gson.toJson(v)).commit();

            AppWidgetManager mgr = AppWidgetManager.getInstance(this);
            int[] ids = mgr.getAppWidgetIds(new ComponentName(this, VertretungsplanWidgetProvider.class));
            new VertretungsplanWidgetProvider().onUpdate(this, mgr, ids);
        } catch (IOException | JSONException e) {
            e.printStackTrace();
        } catch (VersionException e) {
        } catch (UnauthorizedException e) {
        }
    }
}

From source file:com.cloverstudio.spika.GCMIntentService.java

/**
 * Method called on Receiving a new message
 * *///  www.ja va 2s .  c  o  m
@Override
protected void onMessage(Context context, Intent intent) {

    Bundle pushExtras = intent.getExtras();
    String pushMessage = intent.getStringExtra(Const.PUSH_MESSAGE);
    String pushFromName = intent.getStringExtra(Const.PUSH_FROM_NAME);
    try {
        boolean appIsInForeground = new SpikaApp.ForegroundCheckAsync().execute(getApplicationContext()).get();
        boolean screenLocked = ((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                .inKeyguardRestrictedInputMode();
        if (appIsInForeground && !screenLocked) {

            mPushBroadcast.replaceExtras(pushExtras);

            LocalBroadcastManager.getInstance(this).sendBroadcast(mPushBroadcast);
        } else {
            triggerNotification(this, pushMessage, pushFromName, pushExtras);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

}

From source file:com.liferay.alerts.receiver.PushNotificationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    GoogleCloudMessaging gcm = GCMUtil.getGoogleCloudMessaging(this);

    String type = gcm.getMessageType(intent);
    Bundle extras = intent.getExtras();

    if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(type) && !extras.isEmpty()) {

        try {//from  w  w w  .ja va  2s  .c o m
            long parentPushNotificationsEntryId = Long
                    .parseLong(extras.getString(Alert.PARENT_PUSH_NOTIFICATIONS_ENTRY_ID));

            if (parentPushNotificationsEntryId != 0) {
                return;
            }

            long id = Long.parseLong(extras.getString(Alert.PUSH_NOTIFICATIONS_ENTRY_ID));

            JSONObject userJSONObject = new JSONObject(extras.getString(Alert.USER));

            User user = new User(userJSONObject);

            JSONObject payload = new JSONObject(extras.getString(Alert.PAYLOAD));

            Alert alert = new Alert(id, user, payload);

            _insert(user, alert);

            NotificationUtil.notifyUnreadAlerts(this);
            MainActivity.addCard(this, alert);
        } catch (JSONException je) {
            Log.e(_TAG, "Couldn't parse alert JSON.", je);
        } finally {
            PushNotificationReceiver.completeWakefulIntent(intent);
        }
    }
}

From source file:com.arubadesignweb.app.appoverview.util.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*ww w.j a  v a2s  .  c om*/
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */

        if (extras.getString("radius") != null && Float.parseFloat(extras.getString("radius")) != 0
                && extras.getString("latitude") != null && extras.getString("longitude") != null) {

            Log.e(TAG, extras.toString());

            String target_latitude = extras.getString("latitude");
            String target_longitude = extras.getString("longitude");
            double target_radius = Double.parseDouble(extras.getString("radius")) * 1000;

            Location target_location = new Location("target");
            target_location.setLatitude(Double.parseDouble(target_latitude));
            target_location.setLongitude(Double.parseDouble(target_longitude));

            Log.e(TAG, "TargetLocation: " + target_location);

            if (CommonUtilities.isInsideLocation(this, null, target_location, target_radius)) {
                Log.e(TAG, "isInsideRegion, send push notification");
                sendNotificationSuccess(extras);
            } else {
                addProximityAlert(extras, target_location, target_radius);
            }

        } else {

            Log.e("NORMAL", "normal notif");

            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                sendNotification("Send error: " + extras.toString());
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendNotification("Deleted messages on server: " + extras.toString());
                // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // This loop represents the service doing some work.
                for (int i = 0; i < 5; i++) {
                    Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                    }
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotificationSuccess(extras);
                Log.i(TAG, "Received: " + extras.toString());
            }

        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.wbs.itm.SelectedQuestionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.all_ans);//from   w  w  w.j a  v a  2  s .  c o  m
    selquesList = new ArrayList<HashMap<String, String>>();
    Intent newqestionintent = getIntent();
    String newquestion = newqestionintent.getExtras().getString("TAG_QUESTION");
    new LoadAllSelques().execute();
    TextView text = (TextView) findViewById(R.id.selectedquestion);
    text.setText("Q. ");
    text.append(newquestion);
    ListView lv = getListView();
    Button gohome = (Button) findViewById(R.id.gohome);
    gohome.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), TalkyLaunchActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);
        }
    });

    Button ansbtn = (Button) findViewById(R.id.ansbtn);
    ansbtn.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            newqintent = getIntent();
            newqid = newqintent.getExtras().getString("TAG_PID");
            /*String newpid = ((TextView) findViewById(R.id.qid)).getText()
                .toString();*/
            Intent mynewIntent = new Intent(SelectedQuestionActivity.this, NewAnswerActivity.class);
            mynewIntent.putExtra("TAG_newPID", newqid);
            SelectedQuestionActivity.this.startActivity(mynewIntent);
        }
    });
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // getting values from selected ListItem
            // Do nothing! //Later on implement selective Replies.
        }
    });
}

From source file:com.jakebasile.android.linkshrink.ShortenUrl.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    reshare = false;/*  w ww . ja  v  a 2  s .  c om*/
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    shorten(prefs, extras.getString(Intent.EXTRA_TEXT));
}

From source file:com.prey.receivers.C2DMReceiver.java

private void handleMessage(Context context, Intent intent) {
    PreyLogger.d("PUSH_______________");
    PreyConfig config = PreyConfig.getPreyConfig(context);

    Set<String> set = intent.getExtras().keySet();
    Iterator<String> ite = set.iterator();
    while (ite.hasNext()) {
        String key = ite.next();//  w  w  w .  j a v a 2 s .  c o  m
        PreyLogger.d("___[" + key + "]" + intent.getExtras().getString(key));
    }

    String body = intent.getExtras().getString("body");
    String version = intent.getExtras().getString("version");

    String api_key = intent.getExtras().getString("api_key");
    String remote_email = intent.getExtras().getString("remote_email");

    String cmd = intent.getExtras().getString("cmd");

    if ((api_key != null && !"".equals(api_key)) || (body != null && body.indexOf("api_key") > 0)) {
        registrationPlanB(context, api_key, remote_email, body);
    } else {
        handleMessageBeta(context, body, version, cmd);
        config.setVersion(PreyConfig.VERSION_V2);
    }
}

From source file:com.pulp.campaigntracker.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    TLog.v(TAG, "extras : " + extras.toString());

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*from  ww w .  jav  a2  s .c o  m*/
         * Filter messages based on message type. Since it is likely that
         * GCM will be extended in the future with new message types, just
         * ignore any message types you're not interested in, or that you
         * don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.i(TAG, "Send error: " + extras.toString());

        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.i(TAG, "Deleted messages on server: " + extras.toString());

            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.

            if (!mAppPref.getString(ConstantUtils.USER_EMAIL, "").isEmpty()
                    && !mAppPref.getString(ConstantUtils.LOGIN_ID, "").isEmpty()) {

                GCM mMessage = parseMessageObject(extras.getString(MESSAGE));
                // Post notification of received message.
                sendNotification(mMessage);
                Log.i(TAG, "Received: " + extras.getString(MESSAGE));
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}