Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

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

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:gov.in.bloomington.georeporter.fragments.ReportFragment.java

/**
 * Callback from ChooseLocationActivity//  w  w  w .j a  v  a 2 s. co  m
 * 
 * Intent data should have latitude and longitude
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CHOOSE_LOCATION_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            int latitudeE6 = data.getIntExtra(Open311.LATITUDE, 0);
            int longitudeE6 = data.getIntExtra(Open311.LONGITUDE, 0);

            String latitude = Double.toString(latitudeE6 / 1e6);
            String longitude = Double.toString(longitudeE6 / 1e6);
            // Display the lat/long as text for now
            // It will get replaced with the address when ReverseGeoCodingTask returns
            mLocationView.setText(String.format("%s, %s", latitude, longitude));

            mReport.add(new BasicNameValuePair(Open311.LATITUDE, latitude));
            mReport.add(new BasicNameValuePair(Open311.LONGITUDE, longitude));

            new ReverseGeocodingTask(getActivity(), mLocationView)
                    .execute(new GeoPoint(latitudeE6, longitudeE6));
        }
    }
}

From source file:com.callrecorder.android.RecordService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(Constants.TAG, "RecordService onStartCommand");
    if (intent != null) {
        int commandType = intent.getIntExtra("commandType", 0);
        if (commandType != 0) {
            if (commandType == Constants.RECORDING_ENABLED) {
                Log.d(Constants.TAG, "RecordService RECORDING_ENABLED");
                silentMode = intent.getBooleanExtra("silentMode", true);
                if (!silentMode && phoneNumber != null && onCall && !recording)
                    commandType = Constants.STATE_START_RECORDING;

            } else if (commandType == Constants.RECORDING_DISABLED) {
                Log.d(Constants.TAG, "RecordService RECORDING_DISABLED");
                silentMode = intent.getBooleanExtra("silentMode", true);
                if (onCall && phoneNumber != null && recording)
                    commandType = Constants.STATE_STOP_RECORDING;
            }//from   ww w. j a  v  a 2s.  com

            if (commandType == Constants.STATE_INCOMING_NUMBER) {
                Log.d(Constants.TAG, "RecordService STATE_INCOMING_NUMBER");
                startService();
                if (phoneNumber == null)
                    phoneNumber = intent.getStringExtra("phoneNumber");

                silentMode = intent.getBooleanExtra("silentMode", true);
            } else if (commandType == Constants.STATE_CALL_START) {
                Log.d(Constants.TAG, "RecordService STATE_CALL_START");
                onCall = true;

                if (!silentMode && phoneNumber != null && onCall && !recording) {
                    startService();
                    startRecording(intent);
                }
            } else if (commandType == Constants.STATE_CALL_END) {
                Log.d(Constants.TAG, "RecordService STATE_CALL_END");
                onCall = false;
                phoneNumber = null;
                stopAndReleaseRecorder();
                recording = false;
                stopService();
            } else if (commandType == Constants.STATE_START_RECORDING) {
                Log.d(Constants.TAG, "RecordService STATE_START_RECORDING");
                if (!silentMode && phoneNumber != null && onCall) {
                    startService();
                    startRecording(intent);
                }
            } else if (commandType == Constants.STATE_STOP_RECORDING) {
                Log.d(Constants.TAG, "RecordService STATE_STOP_RECORDING");
                stopAndReleaseRecorder();
                recording = false;
            }
        }
    }
    return super.onStartCommand(intent, flags, startId);
}

From source file:ch.fixme.status.Widget.java

public void onReceive(Context ctxt, Intent intent) {
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        // Remove widget alarm
        int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        PendingIntent pi = PendingIntent.getService(ctxt, widgetId, getIntent(ctxt, widgetId), 0);
        AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
        am.cancel(pi);// www  . j a v  a2s. c  o m

        // remove preference
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
        Editor edit = prefs.edit();
        edit.remove(Main.PREF_API_URL_WIDGET + widgetId);
        edit.remove(Main.PREF_INIT_WIDGET + widgetId);
        edit.remove(Main.PREF_LAST_WIDGET + widgetId);
        edit.remove(Main.PREF_FORCE_WIDGET + widgetId);
        edit.commit();

        // Log.i(Main.TAG, "Remove widget alarm for id=" + widgetId);
    } else if (intent.hasExtra(WIDGET_IDS) && AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
        int[] ids = intent.getExtras().getIntArray(WIDGET_IDS);
        onUpdate(ctxt, AppWidgetManager.getInstance(ctxt), ids);
    } else
        super.onReceive(ctxt, intent);
}

From source file:com.example.lista3new.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    String host = intent.getStringExtra(MESSAGE_URL);
    String username = intent.getStringExtra(MESSAGE_USERNAME);
    String password = intent.getStringExtra(MESSAGE_PASSOWRD);
    int port = intent.getIntExtra(MESSAGE_PORT, defaultPort);
    Log.d(TAG, "Connecting...");
    if (ftpConnect(host, port, username, password)) {
        syncFiles(ftpGetCurrentDirectory(), path.getPath());
    } else {//from w  w  w  . j a va 2 s. c  om
        Log.d(TAG, "Cant connect");
    }

}

From source file:com.gaze.webpaser.StackWidgetService.java

public StackRemoteViewsFactory(Context context, Intent intent) {
    mContext = context;//from w w w  . j av  a  2s.  c o  m
    mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);
}

From source file:com.BeeFramework.activity.MainActivity.java

/**
 * ?Intent/*from   www.j  av  a 2s.  c  om*/
 *
 * @param intent
 *            intent
 */
private void handleIntent(Intent intent) {
    String action = intent.getAction();

    if (ACTION_RESPONSE.equals(action)) {

        String method = intent.getStringExtra(RESPONSE_METHOD);

        if (PushConstants.METHOD_BIND.equals(method)) {
            int errorCode = intent.getIntExtra(RESPONSE_ERRCODE, 0);
            if (errorCode == 0) {
                String content = intent.getStringExtra(RESPONSE_CONTENT);
                String appid = "";
                String channelid = "";
                String userid = "";

                try {
                    JSONObject jsonContent = new JSONObject(content);
                    JSONObject params = jsonContent.getJSONObject("response_params");
                    appid = params.getString("appid");
                    channelid = params.getString("channel_id");
                    userid = params.getString("user_id");
                    editor.putString("UUID", userid);
                    editor.commit();

                } catch (JSONException e) {

                }
            } else {

            }

        }
    } else if (ACTION_LOGIN.equals(action)) {
        String accessToken = intent.getStringExtra(EXTRA_ACCESS_TOKEN);
        PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_ACCESS_TOKEN, accessToken);

    } else if (ACTION_MESSAGE.equals(action)) {
        String message = intent.getStringExtra(EXTRA_MESSAGE);
        String summary = "Receive message from server:\n\t";
        JSONObject contentJson = null;
        String contentStr = message;
        try {
            contentJson = new JSONObject(message);
            contentStr = contentJson.toString(4);
        } catch (JSONException e) {

        }
        summary += contentStr;
    } else if (ACTION_PUSHCLICK.equals(action)) {
        String message = intent.getStringExtra(CUSTOM_CONTENT);
    }
}

From source file:com.thunder.iap.IAPActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RC_INAPP_BUY) {
        //in app item bought
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
        if (resultCode == RESULT_OK) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                //String sku = jo.getString("productId");
                if (buyItemListener != null) {
                    buyItemListener.onSuccess(jo);
                }//from   w  w  w.j  av a 2s.c  o m
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            if (buyItemListener != null) {
                buyItemListener.onError(new RuntimeException("Error during onActivityResult"));
            }
        }
    }
    if (requestCode == RC_SUBS_BUY) {
        //subscription bought
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
        if (resultCode == RESULT_OK) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                //String sku = jo.getString("productId");
                if (buySubscriptionListener != null) {
                    buySubscriptionListener.onSuccess(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            if (buySubscriptionListener != null) {
                buySubscriptionListener.onError(new RuntimeException("Error during onActivityResult"));
            }
        }
    }
}

From source file:com.fanfou.app.opensource.service.DownloadService.java

@Override
protected void onHandleIntent(final Intent intent) {
    this.nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    final int type = intent.getIntExtra(Constants.EXTRA_TYPE, DownloadService.TYPE_CHECK);
    if (AppContext.DEBUG) {
        Log.d(DownloadService.TAG, "onHandleIntent type=" + type);
    }/*  www  .j a v  a 2s  .  c  om*/
    if (type == DownloadService.TYPE_CHECK) {
        check();
    } else if (type == DownloadService.TYPE_DOWNLOAD) {
        final AppVersionInfo info = intent.getParcelableExtra(Constants.EXTRA_URL);
        log("onHandleIntent TYPE_DOWNLOAD info=" + info);
        if ((info != null) && !TextUtils.isEmpty(info.downloadUrl)) {
            download(info);
        }
    }
}

From source file:my.madet.uniteninfo.MainHome.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("onActivityResult", "onActivityResult in main Home " + requestCode);
    Log.d("onActivityResult", "onActivityResult in main Home " + data.getIntExtra("RESPONSE_CODE", 0));
    super.onActivityResult(requestCode, resultCode, data);

    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.frame_container);
    if (fragment != null) {
        fragment.onActivityResult(requestCode, resultCode, data);
    }//w ww  .  j a v  a  2  s . c o  m
}