Example usage for android.app Activity RESULT_OK

List of usage examples for android.app Activity RESULT_OK

Introduction

In this page you can find the example usage for android.app Activity RESULT_OK.

Prototype

int RESULT_OK

To view the source code for android.app Activity RESULT_OK.

Click Source Link

Document

Standard activity result: operation succeeded.

Usage

From source file:com.example.cuisoap.agrimac.machineRegister.machineInfoFragment.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri uri = data.getData();//from   w  ww .j  a  v  a 2  s .c  om
        Log.e("uri", uri.toString());
        ContentResolver cr = context.getContentResolver();
        try {
            Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
            bitmap = ImageUtils.comp(bitmap);
            switch (requestCode) {
            case 1:
                license_pic1.setImageBitmap(bitmap);
                license_path1 = ImageUtils.saveMyBitmap(bitmap, "machineinfo");
                license_pic1.setVisibility(View.VISIBLE);
                license1.setVisibility(View.GONE);
                license_pic1.setOnClickListener(myOnClickListener);
                break;
            case 2:
                license_pic2.setImageBitmap(bitmap);
                license_path2 = ImageUtils.saveMyBitmap(bitmap, "machineinfo");
                license_pic2.setVisibility(View.VISIBLE);
                license2.setVisibility(View.GONE);
                license_pic2.setOnClickListener(myOnClickListener);
                break;
            }
        } catch (FileNotFoundException e) {
            Log.e("Exception", e.getMessage(), e);
        }
    } else {
        Toast.makeText(context, "?", Toast.LENGTH_SHORT).show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.hhunj.hhudata.SearchBookContentsActivity.java

private void sendSMS(String phoneNumber, String message) {
    // ---sends an SMS message to another device---
    SmsManager sms = SmsManager.getDefault();
    String SENT_SMS_ACTION = "SENT_SMS_ACTION";
    String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";

    // create the sentIntent parameter
    Intent sentIntent = new Intent(SENT_SMS_ACTION);
    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0);

    // create the deilverIntent parameter
    Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
    PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);

    // register the Broadcast Receivers
    registerReceiver(new BroadcastReceiver() {
        @Override/*  w ww .ja  va  2  s  .  c o m*/
        public void onReceive(Context _context, Intent _intent) {
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS sent success actions", Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                Toast.makeText(getBaseContext(), "SMS generic failure actions", Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Toast.makeText(getBaseContext(), "SMS radio off failure actions", Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Toast.makeText(getBaseContext(), "SMS null PDU failure actions", Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(SENT_SMS_ACTION));

    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context _context, Intent _intent) {
            Toast.makeText(getBaseContext(), "SMS delivered actions", Toast.LENGTH_SHORT).show();
        }
    }, new IntentFilter(DELIVERED_SMS_ACTION));

    // if message's length more than 70 ,
    // then call divideMessage to dive message into several part ,and call
    // sendTextMessage()
    // else direct call sendTextMessage()
    if (message.length() > 70) {
        ArrayList<String> msgs = sms.divideMessage(message);
        for (String msg : msgs) {
            sms.sendTextMessage(phoneNumber, null, msg, sentPI, deliverPI);
        }
    } else {
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliverPI);
    }
}

From source file:fi.iki.murgo.irssinotifier.SettingsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode != ICB_HOST_REQUEST_CODE) {
        return;/*from   www. j  ava  2  s .c  o  m*/
    }

    Preferences prefs = new Preferences(this);

    if (data == null || resultCode != Activity.RESULT_OK) {
        prefs.setIcbHost(null, null);
    } else {
        String hostName = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
        Intent intent = (Intent) data.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT);
        if (intent != null) {
            String intentUri = intent.toUri(0);
            prefs.setIcbHost(hostName, intentUri);
        } else {
            prefs.setIcbHost(null, null);
        }
    }

    handleIcb();
}

From source file:com.arantius.tivocommander.SeasonPass.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;/*www.  j a  v  a  2  s  .  c  o m*/
    }

    if (data.getBooleanExtra("refresh", false)) {
        startRequest();
    }
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

@Override
public void finish(boolean acceptNewConnection) {
    if (acceptNewConnection && server.hasUserAuth()) {
        Server.setCurrentServer(server);
    } else {/*from   ww w.jav  a  2  s  . c  o m*/
        //server.destroy();
    }

    setResult((acceptNewConnection) ? Activity.RESULT_OK : Activity.RESULT_CANCELED);

    super.finish();
}

From source file:com.sdspikes.fireworks.FireworksActivity.java

@Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
    super.onActivityResult(requestCode, responseCode, intent);

    switch (requestCode) {
    case RC_SELECT_PLAYERS:
        // we got the result from the "select players" UI -- ready to create the room
        handleSelectPlayersResult(responseCode, intent);
        break;/*from w  w  w . j av a 2  s . co  m*/
    case RC_INVITATION_INBOX:
        // we got the result from the "select invitation" UI (invitation inbox). We're
        // ready to accept the selected invitation:
        handleInvitationInboxResult(responseCode, intent);
        break;
    case RC_WAITING_ROOM:
        // we got the result from the "waiting room" UI.
        if (responseCode == Activity.RESULT_OK) {
            // ready to start playing
            Log.d(TAG, "Starting game (waiting room returned OK).");
            startGame(true);
        } else if (responseCode == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
            // player indicated that they want to leave the room
            leaveRoom();
        } else if (responseCode == Activity.RESULT_CANCELED) {
            // Dialog was cancelled (user pressed back key, for instance). In our game,
            // this means leaving the room too. In more elaborate games, this could mean
            // something else (like minimizing the waiting room UI).
            leaveRoom();
        }
        break;
    case RC_SIGN_IN:
        Log.d(TAG, "onActivityResult with requestCode == RC_SIGN_IN, responseCode=" + responseCode + ", intent="
                + intent);
        mSignInClicked = false;
        mResolvingConnectionFailure = false;
        if (responseCode == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            BaseGameUtils.showActivityResultError(this, requestCode, responseCode, R.string.signin_other_error);
        }
        break;
    }
    super.onActivityResult(requestCode, responseCode, intent);
}

From source file:com.arantius.tivocommander.ShowList.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;// ww w .j av a  2  s  .com
    }

    if (EXPECT_REFRESH_INTENT_ID == requestCode) {
        if (data.getBooleanExtra("refresh", false)) {
            setRefreshResult();
            if (mShowData.size() == 1) {
                // We deleted the last show! Go up a level.
                finishWithRefresh();
            } else {
                // Load the list of remaining shows.
                startRequest();
                setRefreshResult();
            }
        }
    }
}

From source file:br.org.funcate.dynamicforms.FragmentDetailActivity.java

private void saveAction() throws Exception {

    FragmentDetail detailFragment = (FragmentDetail) getSupportFragmentManager()
            .findFragmentById(R.id.detailFragment);
    if (detailFragment != null) {
        detailFragment.storeFormItems(false);
    }//from w ww  .  j av a2s.c  om

    if (sectionObject == null) {
        throw new Exception(this.getString(R.string.session_object_exception));
    }

    // extract and check constraints
    List<String> availableFormNames = TagsManager.getFormNames4Section(sectionObject);
    Bundle formData = null;

    if (availableFormNames.isEmpty()) {
        throw new Exception(this.getString(R.string.session_object_exception));
    }

    for (String formNameIt : availableFormNames) {
        JSONObject formObject = TagsManager.getForm4Name(formNameIt, sectionObject);
        JSONArray formItemsArray = TagsManager.getFormItems(formObject);

        int length = formItemsArray != null ? formItemsArray.length() : 0;
        formData = new Bundle(length);
        ArrayList<String> keys = new ArrayList<String>(length);
        ArrayList<String> types = new ArrayList<String>(length);

        String key = "";
        String value = "";
        String type = "";
        boolean insertKey;// This control flag is used to ignore some types because are simply ignored or are manipulated in other time.

        for (int i = 0; i < length; i++) {
            JSONObject jsonObject = formItemsArray.getJSONObject(i);

            if (jsonObject.has(TAG_KEY))
                key = jsonObject.getString(TAG_KEY).trim();

            if (jsonObject.has(TAG_VALUE)) {
                value = jsonObject.getString(TAG_VALUE).trim();
            }

            if (jsonObject.has(TAG_TYPE)) {
                type = jsonObject.getString(TAG_TYPE).trim();
            }

            if (!key.equals("") && !value.equals("") && !type.equals("")) {

                insertKey = true;

                if (type.equals(TYPE_STRING)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_STRINGAREA)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_DOUBLE)) {
                    formData.putDouble(key, Double.valueOf(value));
                } else if (type.equals(TYPE_INTEGER)) {
                    formData.putInt(key, Integer.valueOf(value));
                } else if (type.equals(TYPE_DATE)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_TIME)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_LABEL)) {
                    insertKey = false;
                    //formData.putString(key, value);
                } else if (type.equals(TYPE_LABELWITHLINE)) {
                    insertKey = false;
                    //formData.putString(key, value);
                } else if (type.equals(TYPE_BOOLEAN)) {
                    formData.putBoolean(key, Boolean.valueOf(value));
                } else if (type.equals(TYPE_STRINGCOMBO)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_CONNECTEDSTRINGCOMBO)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_STRINGMULTIPLECHOICE)) {
                    insertKey = false;
                    //formData.putString(key,value);
                } else if (type.equals(TYPE_PICTURES)) {
                    insertKey = false;
                    // Using the new key to represent a list of image paths. It is manipulated on posterior time.
                    //formData.putString(key,value);
                    decodeFromJson(value, formData);
                }

                if (insertKey) {
                    keys.add(key);
                    types.add(type);
                }

            }
        }
        formData.putStringArrayList(LibraryConstants.FORM_TYPES, types);
        formData.putStringArrayList(LibraryConstants.FORM_KEYS, keys);

        if (sectionObject.has(FormUtilities.ATTR_GEOJSON_TAGS)) {
            JSONObject geojsonGeometry = sectionObject.getJSONObject(FormUtilities.ATTR_GEOJSON_TAGS);
            formData.putString(FormUtilities.ATTR_GEOJSON_TAGS, geojsonGeometry.toString());
        }

        if (pointId >= 0) {
            formData.putLong(FormUtilities.GEOM_ID, pointId);
        }

        if (existingFeatureData != null) {
            formData.putBundle(FormUtilities.ATTR_DATA_VALUES, existingFeatureData);
        }
    }

    if (formData == null) {
        throw new Exception(this.getString(R.string.session_object_exception));
    }
    Intent intent = getIntent();
    intent.putExtra(LibraryConstants.PREFS_KEY_FORM, formData);
    setResult(Activity.RESULT_OK, intent);
    finish();
}

From source file:io.teak.sdk.GooglePlay.java

public void checkActivityResultForPurchase(int resultCode, Intent data) {
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    Log.d(LOG_TAG, "Checking activity result for purchase.");

    // Check for purchase activity result
    if (purchaseData != null && dataSignature != null) {
        int responseCode = getResponseCodeFromIntent(data);

        if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
            try {
                JSONObject json = new JSONObject(purchaseData);
                Teak.purchaseSucceeded(json);
            } catch (Exception e) {
                Log.e(LOG_TAG, "Failed to convert purchase data to JSON.");
                Teak.sdkRaven.reportException(e);
            }/*from  w ww  .  j a  v a 2 s.  c  o  m*/
        } else {
            Teak.purchaseFailed(responseCode);
        }
    } else {
        Log.d(LOG_TAG, "No purchase found in activity result.");
    }
}

From source file:br.com.GUI.perfil.PerfilAluno.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == 200 || requestCode == 202) {

            if (requestCode == 200) {

                selectedImageUri = data.getData();

                cortar(requestCode);//from   ww  w .  j a  v a  2  s  .c  om

                /*selectedImageUri = Uri.fromFile(photo);
                        
                ContentResolver cr = getContentResolver();
                        
                Bitmap foto;
                try{
                   foto = android.provider.MediaStore.Images.Media.getBitmap(cr,  selectedImageUri);
                   bmp = ImageUtils.compactImages(foto);
                   imagem.setImageBitmap(foto);
                        
                }catch(FileNotFoundException e){
                   Log.i("Exception", e.toString());
                   e.printStackTrace();
                } catch (IOException e){
                           
                           
                }*/
            } else if (requestCode == 202) {
                //get the returned data
                Bundle extras = data.getExtras();
                //get the cropped bitmap
                Bitmap foto = extras.getParcelable("data");
                bmp = ImageUtils.compactImages(foto);
                img.setImageBitmap(bmp);

                //Log.i("tirei a foto ",  "e setei no canvas");
                Aluno p = new Aluno();
                p.setUsuario(pref.getString("usuario", null));
                if (p.editarFotoAlunoWeb(ImageUtils.bitmapToByteArray(bmp))) {
                    if (p.atualizarFotoAluno(b, ImageUtils.bitmapToByteArray(bmp))) {
                        Toast.makeText(getActivity(), "Atualizada com sucesso!", Toast.LENGTH_SHORT).show();
                    }
                }
                refresh();

            }

        } else if (requestCode == 100 || requestCode == 102) {

            if (requestCode == 100) {
                selectedImageUri = data.getData();

                cortar(requestCode);

            } else if (requestCode == 102) {
                //get the returned data
                Bundle extras = data.getExtras();
                //get the cropped bitmap
                Bitmap foto = extras.getParcelable("data");
                bmp = ImageUtils.compactImages(foto);
                img.setImageBitmap(bmp);

                Aluno p = new Aluno();
                p.setUsuario(pref.getString("usuario", null));
                if (p.editarFotoAlunoWeb(ImageUtils.bitmapToByteArray(bmp))) {
                    if (p.atualizarFotoAluno(b, ImageUtils.bitmapToByteArray(bmp))) {
                        Toast.makeText(getActivity(), "Atualizada com sucesso!", Toast.LENGTH_SHORT).show();
                    }
                }
                refresh();

            }
            /*try {
                       
                Uri selectedImage = data.getData();
                        
                String[] nomeCaminho = {MediaStore.Images.Media.DATA};
                        
                Cursor cursor = getContentResolver().query(selectedImage, nomeCaminho, null, null, null);
                cursor.moveToFirst();
                        
                int indexColuna = cursor.getColumnIndex(nomeCaminho[0]);
                String caminho = cursor.getString(indexColuna);
                        
                bmp = ImageUtils.compactImages(BitmapFactory.decodeFile(caminho));
                imagem.setImageBitmap(BitmapFactory.decodeFile(caminho));
                               
                      
            } catch (Exception e) {
               Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
               Log.e("Camera", e.toString());
            }
            */
        }

    } else {
        selectedImageUri = null;
        img.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.profile));
    }
}