List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.csipsimple.ui.incall.CallActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PICKUP_SIP_URI_XFER: if (resultCode == RESULT_OK && service != null) { String callee = data.getStringExtra(Intent.EXTRA_PHONE_NUMBER); int callId = data.getIntExtra(CALL_ID, -1); if (callId != -1) { try { service.xfer((int) callId, callee); } catch (RemoteException e) { // TODO : toaster }/* w w w . java 2s. com*/ } } return; case PICKUP_SIP_URI_NEW_CALL: if (resultCode == RESULT_OK && service != null) { Log.d(TAG, "OnActivityResult, PICKUP_SIP_URI_NEW_CALL"); String callee = data.getStringExtra(Intent.EXTRA_PHONE_NUMBER); long accountId = data.getLongExtra(SipProfile.FIELD_ID, SipProfile.INVALID_ID); if (accountId != SipProfile.INVALID_ID) { try { service.makeCall(callee, (int) accountId); } catch (RemoteException e) { // TODO : toaster } } } return; default: break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.jesusla.google.BillingService.java
/** * The {@link BillingReceiver} sends messages to this service using intents. * Each intent has an action and some extra arguments specific to that action. * @param intent the intent containing one of the supported actions * @param startId an identifier for the invocation instance of this service *///from w w w . j av a2 s .c o m public void handleCommand(Intent intent, int startId) { String action = intent.getAction(); if (Consts.DEBUG) { Log.i(TAG, "handleCommand() action: " + action); } if (Consts.ACTION_CONFIRM_NOTIFICATION.equals(action)) { String[] notifyIds = intent.getStringArrayExtra(Consts.NOTIFICATION_ID); confirmNotifications(startId, notifyIds); } else if (Consts.ACTION_GET_PURCHASE_INFORMATION.equals(action)) { String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID); getPurchaseInformation(startId, new String[] { notifyId }); } else if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) { String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA); String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE); purchaseStateChanged(startId, signedData, signature); } else if (Consts.ACTION_RESPONSE_CODE.equals(action)) { long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1); int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE, ResponseCode.RESULT_ERROR.ordinal()); ResponseCode responseCode = ResponseCode.valueOf(responseCodeIndex); checkResponseCode(requestId, responseCode); } }
From source file:ca.mimic.apphangar.Settings.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Tools.HangarLog("ResultCode: " + resultCode + "RequestCode: " + requestCode + "Intent: " + data); if (requestCode == 1001) { int responseCode = data.getIntExtra("RESPONSE_CODE", 0); String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA"); if (responseCode == 0) { try { JSONObject jo = new JSONObject(purchaseData); String sku = jo.getString("productId"); Tools.HangarLog("It werked! productId: " + sku); launchThanks(THANK_YOU_GOOGLE); } catch (JSONException e) { e.printStackTrace();//w w w . j av a 2 s . c om } } else { if (responseCode > 1) { Tools.HangarLog("Not user's fault, tried to purchase but bailed."); Toast.makeText(mContext, getResources().getString(R.string.donate_try_paypal), Toast.LENGTH_LONG).show(); } launchDonate(); } } else if (requestCode == 1) { // Icon chooser if (resultCode == Activity.RESULT_OK) { try { Bitmap bitmap = data.getParcelableExtra("icon"); ComponentName componentTask = ComponentName .unflattenFromString(mIconTask.getPackageName() + "/" + mIconTask.getClassName()); IconCacheHelper.preloadComponent(mContext, componentTask, bitmap, Tools.dpToPx(mContext, CACHED_ICON_SIZE)); myService.execute(SERVICE_CREATE_NOTIFICATIONS); completeRedraw = true; Tools.updateWidget(mContext); } catch (Exception e) { Tools.HangarLog("Icon result exception: " + e); } } } else if (requestCode == 2) { // Icon chooser if (resultCode == Activity.RESULT_OK) { try { Bitmap bitmap = data.getParcelableExtra("icon"); IconCacheHelper.preloadIcon(mContext, Settings.MORE_APPS_PACKAGE, bitmap, Tools.dpToPx(mContext, CACHED_ICON_SIZE)); myService.execute(SERVICE_CREATE_NOTIFICATIONS); completeRedraw = true; Tools.updateWidget(mContext); updateMoreAppsIcon(mContext); } catch (Exception e) { Tools.HangarLog("Icon result exception: " + e); } } } }
From source file:jp.mixi.android.sdk.MixiContainerImpl.java
private void callbackExecute(int resultCode, Intent data, CallbackListener listener) { if (resultCode == Activity.RESULT_OK) { listener.onComplete(data.getExtras()); return;/*from w w w . j a v a 2 s . c o m*/ } else { if (data != null && data.hasExtra(ERROR_STR)) { Log.d(TAG, data.getStringExtra(ERROR_STR)); int code = data.getIntExtra(ERROR_CODE_STR, 0); if (code == ErrorInfo.SERVER_ERROR) { listener.onError(new ErrorInfo(data.getStringExtra(ERROR_MESSAGE_STR), code)); return; } else if (code == ErrorInfo.OTHER_ERROR && ACCOUNT_EXCEPTION.equals(data.getStringExtra(ERROR_STR))) { listener.onError(new ErrorInfo(data.getStringExtra(ERROR_MESSAGE_STR), ErrorInfo.OFFICIAL_APP_ACCOUNT_ERROR)); return; } listener.onFatal(new ErrorInfo(data.getStringExtra(ERROR_MESSAGE_STR), code)); return; } Log.d(TAG, "Login canceled by user."); listener.onCancel(); return; } }
From source file:de.j4velin.wifiAutoOff.Locations.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { if (requestCode == REQUEST_LOCATION) { if (resultCode == RESULT_OK) { LatLng location = data.getParcelableExtra("location"); String locationName = "UNKNOWN"; if (Geocoder.isPresent()) { Geocoder gc = new Geocoder(this); try { List<Address> result = gc.getFromLocation(location.latitude, location.longitude, 1); if (result != null && !result.isEmpty()) { Address address = result.get(0); locationName = address.getAddressLine(0); if (address.getLocality() != null) { locationName += ", " + address.getLocality(); }//from w w w . j a v a 2s . c om } } catch (IOException e) { if (BuildConfig.DEBUG) Logger.log(e); e.printStackTrace(); } } Database db = Database.getInstance(this); db.addLocation(locationName, location); db.close(); locations.add(new Location(locationName, location)); mAdapter.notifyDataSetChanged(); } } else if (requestCode == REQUEST_BUY) { if (resultCode == RESULT_OK) { if (data.getIntExtra("RESPONSE_CODE", 0) == 0) { try { JSONObject jo = new JSONObject(data.getStringExtra("INAPP_PURCHASE_DATA")); PREMIUM_ENABLED = jo.getString("productId").equals("de.j4velin.wifiautomatic.billing.pro") && jo.getString("developerPayload").equals(getPackageName()); getSharedPreferences("settings", Context.MODE_PRIVATE).edit() .putBoolean("pro", PREMIUM_ENABLED).commit(); if (PREMIUM_ENABLED) { Toast.makeText(this, "Thank you!", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { if (BuildConfig.DEBUG) Logger.log(e); Toast.makeText(this, e.getClass().getName() + ": " + e.getMessage(), Toast.LENGTH_LONG) .show(); } } } } else { super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.cerema.cloud2.files.services.FileUploader.java
/** * Entry point to add one or several files to the queue of uploads. * * New uploads are added calling to startService(), resulting in a call to * this method. This ensures the service will keep on working although the * caller activity goes away.//from ww w . ja v a 2 s.c o m */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log_OC.d(TAG, "Starting command with id " + startId); if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)) { Account account = intent.getParcelableExtra(KEY_ACCOUNT); if (mCurrentUpload != null) { FileUploaderBinder fub = (FileUploaderBinder) mBinder; fub.cancel(account); return Service.START_NOT_STICKY; } } if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) { Log_OC.e(TAG, "Not enough information provided in intent"); return Service.START_NOT_STICKY; } int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1); if (uploadType == -1) { Log_OC.e(TAG, "Incorrect upload type provided"); return Service.START_NOT_STICKY; } Account account = intent.getParcelableExtra(KEY_ACCOUNT); if (!AccountUtils.exists(account, getApplicationContext())) { return Service.START_NOT_STICKY; } String[] localPaths = null, remotePaths = null, mimeTypes = null; OCFile[] files = null; if (uploadType == UPLOAD_SINGLE_FILE) { if (intent.hasExtra(KEY_FILE)) { files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) }; } else { localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) }; remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) }; mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) }; } } else { // mUploadType == UPLOAD_MULTIPLE_FILES if (intent.hasExtra(KEY_FILE)) { files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO // will // this // casting // work // fine? } else { localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE); remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE); mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE); } } FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver()); boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false); boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false); int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET); if (intent.hasExtra(KEY_FILE) && files == null) { Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent"); return Service.START_NOT_STICKY; } else if (!intent.hasExtra(KEY_FILE)) { if (localPaths == null) { Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent"); return Service.START_NOT_STICKY; } if (remotePaths == null) { Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent"); return Service.START_NOT_STICKY; } if (localPaths.length != remotePaths.length) { Log_OC.e(TAG, "Different number of remote paths and local paths!"); return Service.START_NOT_STICKY; } files = new OCFile[localPaths.length]; for (int i = 0; i < localPaths.length; i++) { files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i], ((mimeTypes != null) ? mimeTypes[i] : null)); if (files[i] == null) { // TODO @andomaex add failure Notification return Service.START_NOT_STICKY; } } } OwnCloudVersion ocv = AccountUtils.getServerVersion(account); boolean chunked = FileUploader.chunkedUploadIsSupported(ocv); AbstractList<String> requestedUploads = new Vector<String>(); String uploadKey = null; UploadFileOperation newUpload = null; try { for (int i = 0; i < files.length; i++) { newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite, localAction, getApplicationContext()); if (isInstant) { newUpload.setRemoteFolderToBeCreated(); } newUpload.addDatatransferProgressListener(this); newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder); Pair<String, String> putResult = mPendingUploads.putIfAbsent(account, files[i].getRemotePath(), newUpload); if (putResult != null) { uploadKey = putResult.first; requestedUploads.add(uploadKey); } // else, file already in the queue of uploads; don't repeat the request } } catch (IllegalArgumentException e) { Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } catch (IllegalStateException e) { Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } catch (Exception e) { Log_OC.e(TAG, "Unexpected exception while processing upload intent", e); return START_NOT_STICKY; } if (requestedUploads.size() > 0) { Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = requestedUploads; mServiceHandler.sendMessage(msg); } return Service.START_NOT_STICKY; }
From source file:jp.co.conit.sss.sp.ex1.billing.BillingService.java
/** * The {@link BillingReceiver} sends messages to this service using intents. * Each intent has an action and some extra arguments specific to that * action.//from ww w . j a va 2 s . c om * * @param intent the intent containing one of the supported actions * @param startId an identifier for the invocation instance of this service */ public void handleCommand(Intent intent, int startId) { if (intent == null) { return; } String action = intent.getAction(); if (Consts.ACTION_CONFIRM_NOTIFICATION.equals(action)) { String[] notifyIds = intent.getStringArrayExtra(Consts.NOTIFICATION_ID); confirmNotifications(startId, notifyIds); } else if (Consts.ACTION_GET_PURCHASE_INFORMATION.equals(action)) { String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID); getPurchaseInformation(startId, new String[] { notifyId }); } else if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) { String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA); String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE); purchaseStateChanged(startId, signedData, signature); } else if (Consts.ACTION_RESPONSE_CODE.equals(action)) { long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1); int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE, ResponseCode.RESULT_ERROR.ordinal()); ResponseCode responseCode = ResponseCode.valueOf(responseCodeIndex); checkResponseCode(requestId, responseCode); } }
From source file:com.coact.kochzap.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // historyManager must be initialized here to update the history preference historyManager = new HistoryManager(this); historyManager.trimHistory();/*w w w. jav a2 s . co m*/ // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't // want to open the camera driver and measure the screen size if we're going to show the help on // first launch. That led to bugs where the scanning rectangle was the wrong size and partially // off screen. cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); resultView = findViewById(R.id.result_view); statusView = (TextView) findViewById(R.id.status_view); handler = null; lastResult = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); resetStatusView(); beepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); Intent intent = getIntent(); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; sourceUrl = null; scanFromWebPageManager = null; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and return the result to the calling activity. source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); decodeHints = DecodeHintManager.parseDecodeHints(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } if (intent.hasExtra(Intents.Scan.CAMERA_ID)) { int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1); if (cameraId >= 0) { cameraManager.setManualCameraId(cameraId); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { statusView.setText(customPromptMessage); } } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) { // Scan only products and send the result to mobile Product Search. source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { // Scan formats requested in query string (all formats if none specified). // If a return URL is specified, send the results there. Otherwise, handle it ourselves. source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(dataString); scanFromWebPageManager = new ScanFromWebPageManager(inputUri); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); // Allow a sub-set of the hints to be specified by the caller. decodeHints = DecodeHintManager.parseDecodeHints(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the camera. surfaceHolder.addCallback(this); } }
From source file:com.BeeFramework.service.PushMessageReceiver.java
/** * * * @param context/* w ww. ja v a 2s . com*/ * Context * @param intent * intent */ @Override public void onReceive(final Context context, Intent intent) { shared = context.getSharedPreferences("userInfo", 0); editor = shared.edit(); if (intent.getAction().equals(PushConstants.ACTION_MESSAGE)) { //?? // String message = intent.getExtras().getString( // PushConstants.EXTRA_PUSH_MESSAGE_STRING); // // //??CUSTOM_KEY????key // String customContentString = intent.getExtras().getString("content"); // // //??,?demo? // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_MESSAGE); // responseIntent.putExtra(SquaredActivity.EXTRA_MESSAGE, message); // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(responseIntent); //?? //:PushManager.startWork()PushConstants.METHOD_BIND } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVE)) { //? final String method = intent.getStringExtra(PushConstants.EXTRA_METHOD); //?,???bind??bind,??startWork final int errorCode = intent.getIntExtra(PushConstants.EXTRA_ERROR_CODE, PushConstants.ERROR_SUCCESS); // final String content = new String(intent.getByteArrayExtra(PushConstants.EXTRA_CONTENT)); //??,?demo? // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_RESPONSE); // responseIntent.putExtra(SquaredActivity.RESPONSE_METHOD, method); // responseIntent.putExtra(SquaredActivity.RESPONSE_ERRCODE, // errorCode); // responseIntent.putExtra(SquaredActivity.RESPONSE_CONTENT, content); // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(responseIntent); if (errorCode == 0) { 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 if (intent.getAction().equals(PushConstants.ACTION_RECEIVER_NOTIFICATION_CLICK)) { // String content = intent // .getStringExtra(PushConstants.EXTRA_NOTIFICATION_CONTENT); // // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_PUSHCLICK); // // // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // // //??CUSTOM_KEY????key // String customContentString = intent.getExtras().getString("content"); // responseIntent.putExtra(SquaredActivity.CUSTOM_CONTENT, customContentString); // // context.startActivity(responseIntent); } }