List of usage examples for android.app Activity RESULT_OK
int RESULT_OK
To view the source code for android.app Activity RESULT_OK.
Click Source Link
From source file:bluetoothchat.BluetoothChatFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true);/* ww w . ja v a 2 s .co m*/ } break; case REQUEST_CONNECT_DEVICE_INSECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, false); } break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { btnEnableSwap.setText("Connect a device"); // Bluetooth is now enabled, so set up a chat session setupChat(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(getActivity(), R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); // getActivity().finish(); } } }
From source file:com.inductivebiblestudyapp.billing.util.IabHelper.java
/** * Handles an activity result that's part of the purchase flow in in-app billing. If you * are calling {@link #launchPurchaseFlow}, then you must call this method from your * Activity's {@link android.app.Activity@onActivityResult} method. This method * MUST be called from the UI thread of the Activity. * * @param requestCode The requestCode as you received it. * @param resultCode The resultCode as you received it. * @param data The data (Intent) as you received it. * @return Returns true if the result was related to a purchase flow and was handled; * false if the result was not related to a purchase, in which case you should * handle it normally./* w ww.ja v a 2 s. com*/ */ public boolean handleActivityResult(int requestCode, int resultCode, Intent data) { IabResult result; if (requestCode != mRequestCode) return false; checkNotDisposed(); checkSetupDone("handleActivityResult"); // end of async purchase operation that started on launchPurchaseFlow flagEndAsync(); if (data == null) { logError("Null data in IAB activity result."); result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result"); if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); return true; } int responseCode = getResponseCodeFromIntent(data); String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA); String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE); if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) { logDebug("Successful resultcode from purchase activity."); logDebug("Purchase data: " + purchaseData); logDebug("Data signature: " + dataSignature); logDebug("Extras: " + data.getExtras()); logDebug("Expected item type: " + mPurchasingItemType); if (purchaseData == null || dataSignature == null) { logError("BUG: either purchaseData or dataSignature is null."); logDebug("Extras: " + data.getExtras().toString()); result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature"); if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); return true; } Purchase purchase = null; try { purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature); String sku = purchase.getSku(); // Verify signature if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature) && !mIsTestingMode) { logError("Purchase signature verification FAILED for sku " + sku); result = new IabResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for sku " + sku); if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, purchase); return true; } logDebug("Purchase signature successfully verified."); } catch (JSONException e) { logError("Failed to parse purchase data."); e.printStackTrace(); result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data."); if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); return true; } if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"), purchase); } } else if (resultCode == Activity.RESULT_OK) { // result code was OK, but in-app billing response was not OK. logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode)); if (mPurchaseListener != null) { result = new IabResult(responseCode, "Problem purchashing item."); mPurchaseListener.onIabPurchaseFinished(result, null); } } else if (resultCode == Activity.RESULT_CANCELED) { logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode)); result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled."); if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); } else { logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: " + getResponseDesc(responseCode)); result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response."); if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); } return true; }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PERFORM_ACTIONS: mActivityCallback.onFinished();//from www. j av a2 s . c o m break; case ACTIVITY_REQUEST_FILE: if (data != null && resultCode == Activity.RESULT_OK) { mSelectedUri = data.getData(); GenericProgressDialog.Builder builder = new GenericProgressDialog.Builder(); builder.title(R.string.in_app_flashing_dialog_verifying_zip); builder.message(R.string.please_wait); builder.build().show(getFragmentManager(), PROGRESS_DIALOG_VERIFY_ZIP); queryUriMetadata(); } break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:de.geithonline.abattlwp.billinghelper.IabHelper.java
/** * Handles an activity result that's part of the purchase flow in in-app * billing. If you are calling {@link #launchPurchaseFlow}, then you must * call this method from your Activity's {@link android.app.Activity * @onActivityResult} method. This method MUST be called from the UI thread * of the Activity.// w ww.ja va 2s. c o m * * @param requestCode * The requestCode as you received it. * @param resultCode * The resultCode as you received it. * @param data * The data (Intent) as you received it. * @return Returns true if the result was related to a purchase flow and was * handled; false if the result was not related to a purchase, in * which case you should handle it normally. */ public boolean handleActivityResult(final int requestCode, final int resultCode, final Intent data) { IabResult result; if (requestCode != mRequestCode) { return false; } checkNotDisposed(); checkSetupDone("handleActivityResult"); // end of async purchase operation that started on launchPurchaseFlow flagEndAsync(); if (data == null) { logError("Null data in IAB activity result."); result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result"); if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(result, null); } return true; } final int responseCode = getResponseCodeFromIntent(data); final String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA); final String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE); if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) { logDebug("Successful resultcode from purchase activity."); logDebug("Purchase data: " + purchaseData); logDebug("Data signature: " + dataSignature); logDebug("Extras: " + data.getExtras()); logDebug("Expected item type: " + mPurchasingItemType); if (purchaseData == null || dataSignature == null) { logError("BUG: either purchaseData or dataSignature is null."); logDebug("Extras: " + data.getExtras().toString()); result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature"); if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(result, null); } return true; } Purchase purchase = null; try { purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature); final String sku = purchase.getSku(); // Verify signature if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) { logError("Purchase signature verification FAILED for sku " + sku); result = new IabResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for sku " + sku); if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(result, purchase); } return true; } logDebug("Purchase signature successfully verified."); } catch (final JSONException e) { logError("Failed to parse purchase data."); e.printStackTrace(); result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data."); if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(result, null); } return true; } if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"), purchase); } } else if (resultCode == Activity.RESULT_OK) { // result code was OK, but in-app billing response was not OK. logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode)); if (mPurchaseListener != null) { result = new IabResult(responseCode, "Problem purchashing item."); mPurchaseListener.onIabPurchaseFinished(result, null); } } else if (resultCode == Activity.RESULT_CANCELED) { logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode)); result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled."); if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(result, null); } } else { logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: " + getResponseDesc(responseCode)); result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response."); if (mPurchaseListener != null) { mPurchaseListener.onIabPurchaseFinished(result, null); } } return true; }
From source file:com.irccloud.android.activity.UploadsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (ColorFormatter.file_uri_template != null) template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template); super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC));//from ww w. java 2 s . c om cloud.recycle(); } if (Build.VERSION.SDK_INT >= 14) { try { java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http"); long httpCacheSize = 10 * 1024 * 1024; // 10 MiB HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { Log.i("IRCCloud", "HTTP response cache installation failed:" + e); } } setContentView(R.layout.ignorelist); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar)); getSupportActionBar().setElevation(0); } if (savedInstanceState != null && savedInstanceState.containsKey("cid")) { cid = savedInstanceState.getInt("cid"); to = savedInstanceState.getString("to"); msg = savedInstanceState.getString("msg"); page = savedInstanceState.getInt("page"); File[] files = (File[]) savedInstanceState.getSerializable("adapter"); for (File f : files) { adapter.addFile(f); } adapter.notifyDataSetChanged(); } footer = getLayoutInflater().inflate(R.layout.messageview_header, null); ListView listView = (ListView) findViewById(android.R.id.list); listView.setAdapter(adapter); listView.addFooterView(footer); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) { canLoadMore = false; new FetchFilesTask().execute((Void) null); } } }); listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { final File f = (File) adapter.getItem(i); AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null); final EditText messageinput = (EditText) v.findViewById(R.id.message); messageinput.setText(msg); final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail); v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (messageinput.hasFocus()) { v.post(new Runnable() { @Override public void run() { v.scrollTo(0, v.getBottom()); } }); } } }); if (f.mime_type.startsWith("image/")) { try { thumbnail.setImageBitmap(f.image); thumbnail.setVisibility(View.VISIBLE); thumbnail.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class); i.setData(Uri.parse(f.url)); startActivity(i); } }); thumbnail.setClickable(true); } catch (Exception e) { e.printStackTrace(); } } else { thumbnail.setVisibility(View.GONE); } ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata); v.findViewById(R.id.filename).setVisibility(View.GONE); v.findViewById(R.id.filename_heading).setVisibility(View.GONE); builder.setTitle("Send A File To " + to); builder.setView(v); builder.setPositiveButton("Send", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String message = messageinput.getText().toString(); if (message.length() > 0) message += " "; message += f.url; dialog.dismiss(); if (getParent() == null) { setResult(Activity.RESULT_OK); } else { getParent().setResult(Activity.RESULT_OK); } finish(); NetworkConnection.getInstance().say(cid, to, message); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog d = builder.create(); d.setOwnerActivity(UploadsActivity.this); d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); d.show(); } }); }
From source file:com.mikebl71.android.websms.connector.cabbage.CabbageConnector.java
/** * Processes an answer from the captcha solver app. *///from ww w. j a v a2 s . co m private void processCaptchaSolverAnswer(final Context context, final Intent intent) { final ConnectorSpec specs = this.getSpec(context); final String tag = specs.toString(); Log.d(tag, "got solved captcha"); String answer = CaptcherSolverClient.parseResponseIntent(context, intent); gotSolvedCaptcha(context, answer); try { this.setResultCode(Activity.RESULT_OK); } catch (Exception e) { Log.w(tag, "not an ordered boradcast: " + e.toString()); } }
From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) { super.onActivityResult(requestCode, resultCode, data); return;//from w ww .j ava2s . c o m } Uri[] results = null; if (resultCode == Activity.RESULT_OK) { if (data == null) { if (mCameraPhotoPath != null) { results = new Uri[] { Uri.parse(mCameraPhotoPath) }; } } else { String dataString = data.getDataString(); if (dataString != null) { results = new Uri[] { Uri.parse(dataString) }; } } } mFilePathCallback.onReceiveValue(results); mFilePathCallback = null; }
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Called when the camera view exits./*from ww w . jav a2 s. co m*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; Log.d(LOG_TAG, "-z"); // If retrieving photo from library if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { Log.d(LOG_TAG, "-y"); if (resultCode == Activity.RESULT_OK) { Log.d(LOG_TAG, "-x"); Uri uri = intent.getData(); Log.d(LOG_TAG, "-w"); // If you ask for video or all media type you will automatically // get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { Log.d(LOG_TAG, "mediaType not PICTURE, so must be Video"); String metadataDateTime = ""; ExifInterface exif; try { exif = new ExifInterface(this.getRealPathFromURI(uri, this.cordova)); if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); } } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } Log.d(LOG_TAG, "before create thumbnail"); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail( (new File(this.getRealPathFromURI(uri, this.cordova))).getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND); Log.d(LOG_TAG, "after create thumbnail"); String mid = generateRandomMid(); try { String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); bitmap.compress(CompressFormat.JPEG, 100, foMedium); foMedium.flush(); foMedium.close(); bitmap.recycle(); System.gc(); JSONObject mediaFile = new JSONObject(); try { mediaFile.put("mid", mid); mediaFile.put("mediaType", "video"); mediaFile.put("filePath", filePathMedium); mediaFile.put("filePathMedium", filePathMedium); mediaFile.put("filePathThumb", filePathMedium); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); String absolutePath = (new File(this.getRealPathFromURI(uri, this.cordova))) .getAbsolutePath(); mediaFile.put("fileExt", absolutePath.substring(absolutePath.lastIndexOf(".") + 1)); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } } catch (JSONException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } Log.d(LOG_TAG, "mediafile at 638" + mediaFile.toString()); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); new UploadVideoToS3Task().execute(new File(this.getRealPathFromURI(uri, this.cordova)), this.callbackContext, mid, mediaFile); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } else { String imagePath = this.getRealPathFromURI(uri, this.cordova); String mimeType = FileUtils.getMimeType(imagePath); // If we don't have a valid image so quit. if (imagePath == null || mimeType == null || !(mimeType.equalsIgnoreCase("image/jpeg") || mimeType.equalsIgnoreCase("image/png"))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } String mid = generateRandomMid(); Log.d(LOG_TAG, "a"); JSONObject mediaFile = new JSONObject(); Log.d(LOG_TAG, "b"); try { FileInputStream fi = new FileInputStream(imagePath); Bitmap bitmap = BitmapFactory.decodeStream(fi); fi.close(); Log.d(LOG_TAG, "z1"); // try to get exif data ExifInterface exif = new ExifInterface(imagePath); Log.d(LOG_TAG, "z2"); JSONObject metadataJson = new JSONObject(); Log.d(LOG_TAG, "z3"); /* JSONObject latlng = new JSONObject(); String lat = "0"; String lng = "0"; if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) != null) { lat = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); } if (exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) != null) { lng = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); } latlng.put("lat", lat); latlng.put("lng", lng); Log.d(LOG_TAG, "z4"); metadataJson.put("locationData", latlng); */ String metadataDateTime = ""; if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); JSONObject exifWrapper = new JSONObject(); exifWrapper.put("DateTimeOriginal", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); exifWrapper.put("DateTimeDigitized", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); Log.d(LOG_TAG, "z5"); metadataJson.put("Exif", exifWrapper); } Log.d(LOG_TAG, "z6"); Log.d(LOG_TAG, "metadataJson: " + metadataJson.toString()); Log.d(LOG_TAG, "metadataDateTime: " + metadataDateTime.toString()); if (exif.getAttribute(ExifInterface.TAG_ORIENTATION) != null) { int o = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION)); Log.d(LOG_TAG, "z7"); if (o == ExifInterface.ORIENTATION_NORMAL) { rotate = 0; } else if (o == ExifInterface.ORIENTATION_ROTATE_90) { rotate = 90; } else if (o == ExifInterface.ORIENTATION_ROTATE_180) { rotate = 180; } else if (o == ExifInterface.ORIENTATION_ROTATE_270) { rotate = 270; } else { rotate = 0; } Log.d(LOG_TAG, "z8"); Log.d(LOG_TAG, "rotate: " + rotate); // try to correct orientation if (rotate != 0) { Matrix matrix = new Matrix(); Log.d(LOG_TAG, "z9"); matrix.setRotate(rotate); Log.d(LOG_TAG, "z10"); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); Log.d(LOG_TAG, "z11"); } } Log.d(LOG_TAG, "c"); String filePath = this.getTempDirectoryPath(this.cordova.getActivity()) + "/econ_" + mid + ".jpg"; FileOutputStream foEcon = new FileOutputStream(filePath); fitInsideSquare(bitmap, 850).compress(CompressFormat.JPEG, 45, foEcon); foEcon.flush(); foEcon.close(); Log.d(LOG_TAG, "d"); String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); makeInsideSquare(bitmap, 320).compress(CompressFormat.JPEG, 55, foMedium); foMedium.flush(); foMedium.close(); Log.d(LOG_TAG, "e"); String filePathThumb = this.getTempDirectoryPath(this.cordova.getActivity()) + "/thumb_" + mid + ".jpg"; FileOutputStream foThumb = new FileOutputStream(filePathThumb); makeInsideSquare(bitmap, 175).compress(CompressFormat.JPEG, 55, foThumb); foThumb.flush(); foThumb.close(); bitmap.recycle(); System.gc(); Log.d(LOG_TAG, "f"); mediaFile.put("mid", mid); mediaFile.put("mediaType", "photo"); mediaFile.put("filePath", filePath); mediaFile.put("filePathMedium", filePath); mediaFile.put("filePathThumb", filePath); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); //mediaFile.put("metadataJson", metadataJson); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); Log.d(LOG_TAG, "g"); Log.d(LOG_TAG, "mediaFile " + mediaFile.toString()); new UploadFilesToS3Task().execute(new File(filePath), new File(filePathMedium), new File(filePathThumb), this.callbackContext, mid, mediaFile); Log.d(LOG_TAG, "h"); } catch (FileNotFoundException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } catch (IOException e1) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e1.getStackTrace().toString()); } catch (JSONException e2) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e2.getStackTrace().toString()); } /* if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova .getActivity() .getContentResolver() .query(intent.getData(), cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } } // Create an ExifHelper to save the exif // data that is lost during compression String resizePath = this .getTempDirectoryPath(this.cordova .getActivity()) + "/resize.jpg"; ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(resizePath); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } OutputStream os = new FileOutputStream( resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { exif.createOutFile(this .getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); // The resized image is cached by the app in // order to get around this and not have to // delete your // application cache I'm adding the current // system time to the end of the file url. this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis()); */ } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
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();//from w w w.j av a 2 s . c o m // 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; }