protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult (requestCode, resultCode, data); switch (requestCode) { case CAMMY: if (resultCode == Result.Ok) { string filename = data.GetStringExtra ("filename"); if (!string.IsNullOrEmpty (filename)) { using (Bitmap bmp = BitmapFactory.DecodeFile(filename)) { if (bmp != null) { using (MemoryStream ms = new MemoryStream ()) { bmp.Compress (Bitmap.CompressFormat.Jpeg, 80, ms); if (userImage == null) userImage = new byte[ms.Length]; userImage = ms.ToArray (); displayImage (userImage); } } } AndroidData.imageFileName = filename; } } break; case PICCY: if (resultCode == Result.Ok) { string filename = getRealPathFromUri (data.Data); using (Bitmap bmp = BitmapFactory.DecodeFile(filename)) { if (bmp != null) { using (MemoryStream ms = new MemoryStream ()) { bmp.Compress (Bitmap.CompressFormat.Jpeg, 80, ms); if (userImage == null) userImage = new byte[ms.Length]; userImage = ms.ToArray (); displayImage (userImage); } } } AndroidData.imageFileName = filename; } break; case NEXT: username.Text = data.GetStringExtra ("username"); email.Text = data.GetStringExtra ("email"); password.Text = verify.Text = data.GetStringExtra ("password"); userImage = data.GetByteArrayExtra ("image"); displayImage (userImage); break; } }
private object GetParameterFromIntent(Intent intent) { if (intent == null) return null; string value = intent.GetStringExtra(ParameterString); if (value != null) return value; byte[] bytes = intent.GetByteArrayExtra(ParameterSerializer); if (bytes == null) return null; using (var ms = new MemoryStream(bytes)) return _serializer.Deserialize(ms); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); _keepPasswordInOnResume = true; Kp2aLog.Log("PasswordActivity.OnActivityResult "+resultCode+"/"+requestCode); AppTask.TryGetFromActivityResult(data, ref AppTask); //NOTE: original code from k eepassdroid used switch ((Android.App.Result)requestCode) { (but doesn't work here, although k eepassdroid works) switch(resultCode) { case KeePass.ExitNormal: // Returned to this screen using the Back key if (PreferenceManager.GetDefaultSharedPreferences(this) .GetBoolean(GetString(Resource.String.LockWhenNavigateBack_key), false)) { App.Kp2a.LockDatabase(); } //by leaving the app with the back button, the user probably wants to cancel the task //The activity might be resumed (through Android's recent tasks list), then use a NullTask: AppTask = new NullTask(); Finish(); break; case KeePass.ExitLock: // The database has already been locked, and the quick unlock screen will be shown if appropriate _rememberKeyfile = _prefs.GetBoolean(GetString(Resource.String.keyfile_key), Resources.GetBoolean(Resource.Boolean.keyfile_default)); //update value if ((KeyProviderType == KeyProviders.KeyFile) && (_rememberKeyfile)) { //check if the keyfile was changed (by importing to internal directory) var newKeyFile = GetKeyFile(_ioConnection.Path); if (newKeyFile != _keyFileOrProvider) { _keyFileOrProvider = newKeyFile; UpdateKeyfileIocView(); } } break; case KeePass.ExitCloseAfterTaskComplete: // Do not lock the database SetResult(KeePass.ExitCloseAfterTaskComplete); Finish(); break; case KeePass.ExitClose: SetResult(KeePass.ExitClose); Finish(); break; case KeePass.ExitReloadDb: if (App.Kp2a.GetDb().Loaded) { //remember the composite key for reloading: var compositeKey = App.Kp2a.GetDb().KpDatabase.MasterKey; //lock the database: App.Kp2a.LockDatabase(false); //reload the database (without most other stuff performed in PerformLoadDatabase. // We're assuming that the db file (and if appropriate also the key file) are still available // and there's no need to re-init the file storage. if it is, loading will fail and the user has // to retry with typing the full password, but that's intended to avoid showing the password to a // a potentially unauthorized user (feature request https://keepass2android.codeplex.com/workitem/274) Handler handler = new Handler(); OnFinish onFinish = new AfterLoad(handler, this); _performingLoad = true; LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish); _loadDbTask = null; // prevent accidental re-use new ProgressTask(App.Kp2a, this, task).Run(); } break; case Result.Ok: if (requestCode == RequestCodeSelectKeyfile) { IOConnectionInfo ioc = new IOConnectionInfo(); SetIoConnectionFromIntent(ioc, data); _keyFileOrProvider = IOConnectionInfo.SerializeToString(ioc); UpdateKeyfileIocView(); } break; case (Result)FileStorageResults.FileUsagePrepared: if (requestCode == RequestCodePrepareDbFile) { if (KeyProviderType == KeyProviders.KeyFile) { var iocKeyfile = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider); App.Kp2a.GetFileStorage(iocKeyfile) .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile, RequestCodePrepareKeyFile, false); } else PerformLoadDatabase(); } if (requestCode == RequestCodePrepareKeyFile) { PerformLoadDatabase(); } if (requestCode == RequestCodePrepareOtpAuxFile) { GetAuxFileLoader().LoadAuxFile(true); } break; } if (requestCode == RequestCodeSelectAuxFile && resultCode == Result.Ok) { IOConnectionInfo auxFileIoc = new IOConnectionInfo(); SetIoConnectionFromIntent(auxFileIoc, data); PreferenceManager.GetDefaultSharedPreferences(this).Edit() .PutString("KP2A.PasswordAct.AuxFileIoc" + IOConnectionInfo.SerializeToString(_ioConnection), IOConnectionInfo.SerializeToString(auxFileIoc)) .Apply(); GetAuxFileLoader().LoadAuxFile(false); } if (requestCode == RequestCodeChallengeYubikey && resultCode == Result.Ok) { try { _challengeProv = new KeeChallengeProv(); byte[] challengeResponse = data.GetByteArrayExtra("response"); _challengeSecret = _challengeProv.GetSecret(_chalInfo, challengeResponse); Array.Clear(challengeResponse, 0, challengeResponse.Length); } catch (Exception e) { Kp2aLog.Log(e.ToString()); Toast.MakeText(this, "Error: " + e.Message, ToastLength.Long).Show(); return; } UpdateOkButtonState(); FindViewById(Resource.Id.otpInitView).Visibility = ViewStates.Gone; if (_challengeSecret != null) { new LoadingDialog<object, object, object>(this, true, //doInBackground delegate { //save aux file try { ChallengeInfo temp = _challengeProv.Encrypt(_challengeSecret); IFileStorage fileStorage = App.Kp2a.GetOtpAuxFileStorage(_ioConnection); IOConnectionInfo iocAux = fileStorage.GetFilePath(fileStorage.GetParentPath(_ioConnection), fileStorage.GetFilenameWithoutPathAndExt(_ioConnection) + ".xml"); if (!temp.Save(iocAux)) { Toast.MakeText(this, Resource.String.ErrorUpdatingChalAuxFile, ToastLength.Long).Show(); return false; } } catch (Exception e) { Kp2aLog.Log(e.ToString()); } return null; } , delegate { }).Execute(); } else { Toast.MakeText(this, Resource.String.bad_resp, ToastLength.Long).Show(); return; } } }
/** * <p>Call this from your {@link Activity}'s * {@link Activity#onActivityResult(int, int, Intent)} method.</p> * * @return null if the event handled here was not related to this class, or * else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning, * the fields will be null. */ public static MvxZXingIntentResult ParseActivityResult(int requestCode, Result resultCode, Intent intent) { if (requestCode == REQUEST_CODE) { if (resultCode == Result.Ok) { String contents = intent.GetStringExtra("SCAN_RESULT"); String formatName = intent.GetStringExtra("SCAN_RESULT_FORMAT"); byte[] rawBytes = intent.GetByteArrayExtra("SCAN_RESULT_BYTES"); int? intentOrientation = intent.GetIntExtra("SCAN_RESULT_ORIENTATION", int.MinValue); int? orientation = intentOrientation == int.MinValue ? null : intentOrientation; String errorCorrectionLevel = intent.GetStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL"); return new MvxZXingIntentResult(contents, formatName, rawBytes, orientation, errorCorrectionLevel); } return new MvxZXingIntentResult(); } return null; }