Example usage for android.support.v4.content FileProvider getUriForFile

List of usage examples for android.support.v4.content FileProvider getUriForFile

Introduction

In this page you can find the example usage for android.support.v4.content FileProvider getUriForFile.

Prototype

public static Uri getUriForFile(Context context, String str, File file) 

Source Link

Usage

From source file:com.annanovas.bestprice.DashBoardEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dash_board_edit);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   ww  w.  j  a  va2  s .  com*/
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    //        chosenBrandList.add(new ArrayList<String>());
    //        chosenBrandList.add(new ArrayList<String>());
    //        chosenBrandList.add(new ArrayList<String>());

    etAddress = (EditText) findViewById(R.id.et_address);
    etEmail = (EditText) findViewById(R.id.et_email);
    etShopName = (EditText) findViewById(R.id.et_shop_name);
    etDrivingLicense = (EditText) findViewById(R.id.et_driving_licence);
    etNid = (EditText) findViewById(R.id.et_nid);
    etExperience = (EditText) findViewById(R.id.et_experience);
    etFirstName = (EditText) findViewById(R.id.et_first_name);
    etMiddleName = (EditText) findViewById(R.id.et_middle_name);
    etLastName = (EditText) findViewById(R.id.et_last_name);
    etPhoneNumber = (EditText) findViewById(R.id.et_phone);
    tvAddress = (TextView) findViewById(R.id.tv_address);
    tvArea = (TextView) findViewById(R.id.tv_area);
    tvDealerShip = (LinearLayout) findViewById(R.id.tv_dealership);
    tvDealerShipWith = (TextView) findViewById(R.id.tv_dealership_content);
    tvSelectedProduct = (TextView) findViewById(R.id.tv_select_product_content);
    tvProduct = (LinearLayout) findViewById(R.id.tv_select_product);
    buttonSubmit = (Button) findViewById(R.id.button_submit);
    areaLayout = (LinearLayout) findViewById(R.id.layout_area);
    brandLayout = (LinearLayout) findViewById(R.id.layout_brand);
    productLayout = (LinearLayout) findViewById(R.id.layout_product);
    layoutCamera = (LinearLayout) findViewById(R.id.layout_camera);
    layoutGallery = (LinearLayout) findViewById(R.id.layout_gallery);
    userImage = (ImageView) findViewById(R.id.iv_user_image);
    areaRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_area);
    brandRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_brand);
    productRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_product);
    etProductSearch = (EditText) findViewById(R.id.et_product_name);
    etBrandSearch = (EditText) findViewById(R.id.et_brand_name);
    etAreaSearch = (EditText) findViewById(R.id.et_area_name);
    layoutSearchArea = (LinearLayout) findViewById(R.id.layout_search_area);
    layoutSearchProduct = (LinearLayout) findViewById(R.id.layout_search_product);
    layoutSearchBrand = (LinearLayout) findViewById(R.id.layout_search_brand);
    tvSelectedBrand = (TextView) findViewById(R.id.tv_selected_brand);
    tvSelectedArea = (TextView) findViewById(R.id.tv_setect_area);
    ivArrow1 = (ImageView) findViewById(R.id.iv_arrow1);
    ivArrow2 = (ImageView) findViewById(R.id.iv_arrow2);
    ivArrow3 = (ImageView) findViewById(R.id.iv_arrow3);
    ivArrow4 = (ImageView) findViewById(R.id.iv_arrow4);

    myDB = MyDatabaseManager.getInstance(getApplicationContext());
    sharedPreferences = getSharedPreferences(AppGlobal.MY_PREFS_NAME, MODE_PRIVATE);

    userType = sharedPreferences.getInt("user_type", 1);

    int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics());

    myDB.open();
    Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", ""));
    if (userType == AppGlobal.CAR_OWNER) {
        userImage.setImageResource(R.drawable.ic_car_owner);
        tvAddress.setVisibility(View.VISIBLE);
        etAddress.setVisibility(View.VISIBLE);
        tvArea.setVisibility(View.VISIBLE);
        areaLayout.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));

                if (cursor.getString(cursor.getColumnIndex("address")) != null
                        && !cursor.getString(cursor.getColumnIndex("address")).equals("null")) {
                    etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                }

                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                areaId = cursor.getInt(cursor.getColumnIndex("area_id"));
                if (areaId != 0) {
                    tvSelectedArea.setText(myDB.getAreaName(areaId));
                } else {
                    tvSelectedArea.setText(getResources().getString(R.string.select_area));
                }

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();

        generateAreaRecyclerView();

    } else if (userType == AppGlobal.SUPPLIER) {
        tvAddress.setVisibility(View.VISIBLE);
        etAddress.setVisibility(View.VISIBLE);
        tvDealerShip.setVisibility(View.VISIBLE);
        tvProduct.setVisibility(View.VISIBLE);
        tvArea.setVisibility(View.VISIBLE);
        brandLayout.setVisibility(View.VISIBLE);
        productLayout.setVisibility(View.VISIBLE);
        areaLayout.setVisibility(View.VISIBLE);
        etShopName.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                areaId = cursor.getInt(cursor.getColumnIndex("area_id"));
                if (areaId != 0) {
                    tvSelectedArea.setText(myDB.getAreaName(areaId));
                } else {
                    tvSelectedArea.setText(getResources().getString(R.string.select_area));
                }
                selectedProductIdList = myDB.getSelectedProductList(cursor.getInt(cursor.getColumnIndex("id")));
                chosenBrandIdList = myDB.getSelectedBrandList(cursor.getInt(cursor.getColumnIndex("id")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_supplier);
                }
            }
        }
        cursor.close();

        generateAreaRecyclerView();
        generateProductRecyclerView();

    } else if (userType == AppGlobal.DRIVER) {
        etDrivingLicense.setVisibility(View.VISIBLE);
        etNid.setVisibility(View.VISIBLE);
        etExperience.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etDrivingLicense.setText(cursor.getString(cursor.getColumnIndex("drivinglicence")));
                etNid.setText(cursor.getString(cursor.getColumnIndex("nid")));
                etExperience.setText(cursor.getString(cursor.getColumnIndex("yearofexperience")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();

    } else if (userType == AppGlobal.SHOP_WORKER) {
        etShopName.setVisibility(View.VISIBLE);
        etNid.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                etNid.setText(cursor.getString(cursor.getColumnIndex("nid")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();
    }
    myDB.close();

    areaLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (layoutSearchArea.getVisibility() == View.GONE) {
                layoutSearchArea.setVisibility(View.VISIBLE);
                areaRecyclerView.setVisibility(View.VISIBLE);
                ivArrow2.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchArea.setVisibility(View.GONE);
                areaRecyclerView.setVisibility(View.GONE);
                ivArrow2.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    brandLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (selectedProductIdList.size() == 0) {
                Toast.makeText(getApplicationContext(), R.string.add_product, Toast.LENGTH_SHORT).show();
                return;
            }
            if (layoutSearchBrand.getVisibility() == View.GONE) {
                layoutSearchBrand.setVisibility(View.VISIBLE);
                brandRecyclerView.setVisibility(View.VISIBLE);
                ivArrow3.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchBrand.setVisibility(View.GONE);
                brandRecyclerView.setVisibility(View.GONE);
                ivArrow3.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    productLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (layoutSearchProduct.getVisibility() == View.GONE) {
                layoutSearchProduct.setVisibility(View.VISIBLE);
                productRecyclerView.setVisibility(View.VISIBLE);
                ivArrow1.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchProduct.setVisibility(View.GONE);
                productRecyclerView.setVisibility(View.GONE);
                ivArrow1.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    layoutCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File file = createImageFile();
                imageUri = String.valueOf(file);
                // showLog(imageUri);
                Uri photoURI = FileProvider.getUriForFile(getApplicationContext(),
                        BuildConfig.APPLICATION_ID + ".provider", file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(intent, REQUEST_CAMERA);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    layoutGallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            intent.setType("image/*");
            startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
        }
    });

    buttonSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            progressDialog = new ProgressDialog(DashBoardEditActivity.this);
            progressDialog.setMessage(getResources().getString(R.string.please_wait));
            progressDialog.setCancelable(false);
            progressDialog.show();
            UpdateUserInfo updateUserInfo = new UpdateUserInfo(getApplicationContext());
            updateUserInfo.signUpListener = DashBoardEditActivity.this;
            //viewEnable(false);

            if (userType == AppGlobal.CAR_OWNER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }
                if (etAddress.getText().length() == 0) {
                    etAddress.setError(getResources().getString(R.string.enter_address));
                    hasError = true;
                }
                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("district_id", "1");
                params.put("area_id", String.valueOf(areaId));
                params.put("address", etAddress.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateCarOwnerInfo");
            } else if (userType == AppGlobal.SUPPLIER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }
                if (etShopName.getText().length() == 0) {
                    etShopName.setError(getResources().getString(R.string.enter_shop_name));
                    hasError = true;
                }
                if (etAddress.getText().length() == 0) {
                    etAddress.setError(getResources().getString(R.string.enter_address));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("district_id", "1");
                params.put("area_id", String.valueOf(areaId));
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                params.put("shopname", etShopName.getText().toString());
                params.put("address", etAddress.getText().toString());
                for (int i = 0; i < selectedProductIdList.size(); i++) {
                    params.put("products[" + i + "]", selectedProductIdList.get(i));
                }
                for (int i = 0; i < chosenBrandIdList.size(); i++) {
                    params.put("brands[" + i + "]", chosenBrandIdList.get(i));
                }
                updateUserInfo.parseData(params, "updateSupplierInfo");
            } else if (userType == AppGlobal.DRIVER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                boolean hasDrivingLicenseNoError = false;
                boolean hasNidNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }

                if (etDrivingLicense.getText().length() == 0) {
                    etDrivingLicense.setError(getResources().getString(R.string.enter_driving_licence));
                    hasError = true;
                    hasDrivingLicenseNoError = true;
                }

                if (!hasDrivingLicenseNoError && etDrivingLicense.getText().length() != 15) {
                    etDrivingLicense.setError(getResources().getString(R.string.enter_valid_driving_licence));
                    hasError = true;
                }
                if (etNid.getText().length() == 0) {
                    etNid.setError(getResources().getString(R.string.enter_nid_no));
                    hasError = true;
                    hasNidNoError = true;
                }
                if (!hasNidNoError && etNid.getText().length() != 17) {
                    etNid.setError(getResources().getString(R.string.enter_valid_nid));
                    hasError = true;
                }

                if (etExperience.getText().length() == 0) {
                    etExperience.setError(getResources().getString(R.string.enter_year_of_experience));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("drivinglicence", etDrivingLicense.getText().toString());
                params.put("nid", etNid.getText().toString());
                params.put("yearofexperience", etExperience.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateDriverInfo");
            } else if (userType == AppGlobal.SHOP_WORKER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }

                if (etNid.getText().length() == 0) {
                    etNid.setError(getResources().getString(R.string.enter_nid_no));
                    hasError = true;
                }

                if (etShopName.getText().length() == 0) {
                    etShopName.setError(getResources().getString(R.string.enter_shop_name));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("nid", etNid.getText().toString());
                params.put("shopname", etShopName.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateWorkerInfo");
            }
        }
    });
}

From source file:com.mycelium.wallet.activity.modern.ModernMain.java

private void shareTransactionHistory() {
    WalletAccount account = _mbwManager.getSelectedAccount();
    MetadataStorage metaData = _mbwManager.getMetadataStorage();
    try {//from  w ww . ja  v  a 2  s.com
        String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv";
        File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName));
        PackageManager packageManager = Preconditions.checkNotNull(getPackageManager());
        PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS);
        for (ProviderInfo info : packageInfo.providers) {
            if (info.name.equals("android.support.v4.content.FileProvider")) {
                String authority = info.authority;
                Uri uri = FileProvider.getUriForFile(this, authority, historyData);
                Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider
                        .setType("text/plain")
                        .setSubject(getResources().getString(R.string.transaction_history_title))
                        .setText(getResources().getString(R.string.transaction_history_title)).getIntent()
                        .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
                startActivity(Intent.createChooser(intent,
                        getResources().getString(R.string.share_transaction_history)));
            }
        }
    } catch (IOException | PackageManager.NameNotFoundException e) {
        _toaster.toast("Export failed. Check your logs", false);
        e.printStackTrace();
    }
}

From source file:com.brq.wallet.activity.modern.ModernMain.java

private void shareTransactionHistory() {
    WalletAccount account = _mbwManager.getSelectedAccount();
    MetadataStorage metaData = _mbwManager.getMetadataStorage();
    try {/* w  w  w.  jav  a  2 s  .  co  m*/
        String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv";
        File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName));
        PackageManager packageManager = Preconditions.checkNotNull(getPackageManager());
        PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS);
        for (ProviderInfo info : packageInfo.providers) {
            if (info.name.equals("android.support.v4.content.FileProvider")) {
                String authority = info.authority;
                Uri uri = FileProvider.getUriForFile(this, authority, historyData);
                Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider
                        .setType("text/plain")
                        .setSubject(getResources().getString(R.string.transaction_history_title))
                        .setText(getResources().getString(R.string.transaction_history_title)).getIntent()
                        .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
                startActivity(Intent.createChooser(intent,
                        getResources().getString(R.string.share_transaction_history)));
            }
        }
    } catch (IOException e) {
        _toaster.toast("Export failed. Check your logs", false);
        e.printStackTrace();
    } catch (PackageManager.NameNotFoundException e) {
        _toaster.toast("Export failed. Check your logs", false);
        e.printStackTrace();
    }
}

From source file:com.android.cts.verifier.managedprovisioning.ByodHelperActivity.java

private Pair<File, Uri> getTempUri(String fileName) {
    final File file = new File(getFilesDir() + File.separator + "images" + File.separator + fileName);
    file.getParentFile().mkdirs(); //if the folder doesn't exists it is created
    mTempFiles.add(file);//from w w w .  j  a  v  a2 s  .  c om
    return new Pair<>(file, FileProvider.getUriForFile(this,
            "com.android.cts.verifier.managedprovisioning.fileprovider", file));
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static Uri getOutputMediaUri(boolean temp) {
    String fileName = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
    File outputMediaFile;/*from   w  w  w.ja  va2s  . co m*/
    if (MyApplication.getInstance().isProtected() && !temp) {
        outputMediaFile = getOutputMediaFile(fileName, false);
        if (outputMediaFile == null)
            return null;
        return FileProvider.getUriForFile(MyApplication.getInstance(), "org.totschnig.myexpenses.fileprovider",
                outputMediaFile);
    } else {
        outputMediaFile = getOutputMediaFile(fileName, temp);
        if (outputMediaFile == null)
            return null;
        return Uri.fromFile(outputMediaFile);
    }
}

From source file:com.mbientlab.metawear.app.LoggingFragment.java

private void startEmailIntent() {
    mwMnger.getCurrentController().removeModuleCallback(sensors[sensorIndex]);

    ArrayList<Uri> fileUris = new ArrayList<>();

    try {//from   w w w  . ja v  a2  s .c  om
        for (File it : sensors[sensorIndex].saveDataToFile()) {
            fileUris.add(
                    FileProvider.getUriForFile(getActivity(), "com.mbientlab.metawear.app.fileprovider", it));
        }

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT,
                String.format(Locale.US, "Logged %s data - %tY-%<tm-%<tdT%<tH-%<tM-%<tS",
                        sensors[sensorIndex].toString(), Calendar.getInstance().getTime()));

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
        startActivity(Intent.createChooser(intent, "Send email..."));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.baumann.browser.helper.helper_main.java

private static void openFile(Activity activity, File file, String string, View view) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri contentUri = FileProvider.getUriForFile(activity,
                activity.getApplicationContext().getPackageName() + ".provider", file);
        intent.setDataAndType(contentUri, string);

    } else {//from   w  ww.jav a 2s. com
        intent.setDataAndType(Uri.fromFile(file), string);
    }

    try {
        activity.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Snackbar.make(view, R.string.toast_install_app, Snackbar.LENGTH_LONG).show();
    }
}

From source file:com.example.bidisha.ace.ClueScan.java

private void takePicture() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = new File(Environment.getExternalStorageDirectory(), "picture1.jpg");
    // imageUri = Uri.fromFile(photo);
    imageUri = FileProvider.getUriForFile(ClueScan.this, BuildConfig.APPLICATION_ID + ".provider", photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intent, PHOTO_REQUEST);
}

From source file:net.emilymaier.movebot.MoveBotActivity.java

/**
 * Generate a run's .gpx file and share it.
 * @param run the run session to generate the .gpx from
 *///from   w  w  w  .j  a  va 2s . co  m
private void shareGpx(Run run) {
    String filename;
    try {
        filename = run.generateGpx(this);
    } catch (IOException e) {
        throw new RuntimeException("IOException", e);
    }
    File gpxFile = new File(getFilesDir(), filename);
    Uri gpxUri = FileProvider.getUriForFile(this, "net.emilymaier.movebot.fileprovider", gpxFile);
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_STREAM, gpxUri);
    sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sendIntent.setType("application/xml");
    startActivity(sendIntent);
}

From source file:org.rm3l.maoni.ui.MaoniActivity.java

private void validateAndSubmitForm() {
    //Validate form
    if (this.validateForm(mRootView)) {
        //TODO Check that device is actually connected to the internet prior to going any further
        boolean includeScreenshot = false;
        if (mScreenCapturingFeatureEnabled && mIncludeScreenshot != null) {
            includeScreenshot = mIncludeScreenshot.isChecked();
        }// w  w w  . j ava  2s. c  om
        String contentText = "";
        if (mContent != null) {
            contentText = mContent.getText().toString();
        }

        final Intent intent = getIntent();

        Uri screenshotUri = null;
        File screenshotFile = null;
        Uri logsUri = null;
        File logsFile = null;

        final boolean includeLogs = mLogsCapturingFeatureEnabled && mIncludeLogs != null
                && mIncludeLogs.isChecked();
        if (includeLogs) {
            logsFile = new File(mWorkingDir, MAONI_LOGS_FILENAME);
            LogcatUtils.getLogsToFile(logsFile);
        }

        if (intent.hasExtra(FILE_PROVIDER_AUTHORITY)) {
            final String fileProviderAuthority = intent.getStringExtra(FILE_PROVIDER_AUTHORITY);
            //#11 : Potential NPE in Android's FileProvider if Provider Authority couldn't be resolved
            final ProviderInfo providerAuthorityInfo = this.getPackageManager()
                    .resolveContentProvider(fileProviderAuthority, PackageManager.GET_META_DATA);
            if (providerAuthorityInfo == null) {
                Log.w(TAG,
                        "Could not resolve file provider authority : " + fileProviderAuthority
                                + ". Sharing of files captured not supported then. "
                                + "See http://maoni.rm3l.org/ for setup instructions.");
            } else {
                if (mScreenshotFilePath != null) {
                    screenshotFile = new File(mScreenshotFilePath.toString());
                    screenshotUri = FileProvider.getUriForFile(this, fileProviderAuthority, screenshotFile);
                    grantUriPermission(intent.getComponent().getPackageName(), screenshotUri,
                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
                if (logsFile != null) {
                    logsUri = FileProvider.getUriForFile(this, fileProviderAuthority, logsFile);
                    grantUriPermission(intent.getComponent().getPackageName(), logsUri,
                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            }
        }

        //Construct the feedback object and call the actual implementation
        final Feedback feedback = new Feedback(mFeedbackUniqueId, this, mAppInfo, contentText,
                includeScreenshot, screenshotUri, screenshotFile, includeLogs, logsUri, logsFile,
                mSharedPreferences);
        if (mListener != null) {
            if (mListener.onSendButtonClicked(feedback)) {
                finish();
            } // else do *not* finish the activity
        } else {
            finish();
        }
    } //else do nothing - this is up to the callback implementation
}