[Andorid] Finished Lab3




Recap


SharedPreferences

public static void LoadFromPref() {
        SharedPreferences settings = mContext.getSharedPreferences(MY_EMP_PREFS, 0);
        emailAdress = settings.getString("DefaultEmail", "email@domain.com");
    }



  public static void StoreToPref() {
        SharedPreferences settings = mContext.getSharedPreferences(MY_EMP_PREFS, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("DefaultEmail", emailAdress);
        editor.commit();
    }



Intent (using String)

Intent resultIntent = new Intent
          resultIntent.putExtra("Response", getString(R.string.ResCANCEL));
          setResult(Activity.RESULT_OK, resultIntent);


putExtra(String Name, CharSequence) --- getString to get String type




Capture image by camera app

AndroidManifest.xml

    <uses-feature android:name="android.hardware.camera"
        android:required="true" />

// Giving permission to use camera


ListItemActivity.java

static final int REQUEST_IMAGE_CAPTURE = 1;
    public ImageButton imageB;


    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
                Bundle extras = data.getExtras();
                Bitmap imageBitmap = (Bitmap) extras.get("data");

                imageB = findViewById(R.id.imageButton);
                imageB.setImageBitmap(imageBitmap);

            String messagePassed = data.getStringExtra("Response");
            Toast toast = Toast.makeText(this , messagePassed, Toast.LENGTH_SHORT); 
            toast.show(); //display your message box

        }
    }







Comments

Popular Posts