-1

I want "share location" functionality same like whatsapp in my current application. Here is a chooser dialog

Here is a share location screen

After selecting your location it displays like this

Now to open chooser dialog i used below mentioned code.

public static void showFileChooser(Activity activity, Fragment fragment, boolean isAllowMultiple) {
        try {

            File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "demo");
            if (!imageStorageDir.exists()) {
                imageStorageDir.mkdirs();
            }
            File file = new File(imageStorageDir + File.separator + "i" + String.valueOf(System.currentTimeMillis()) + ".jpg");
            mCapturedImageURI = Uri.fromFile(file); // save to the private variable

            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
            captureIntent.putExtra("capturedimageuri", mCapturedImageURI.toString());

            // Intent for Audio Recording
            final Intent audioRecordIntent = new Intent();
            audioRecordIntent.setAction(IxxxConstants.ACTION_AUDIO_RECORD);

            final Intent videoRecordIntent = new Intent();
            videoRecordIntent.setAction(IxxxConstants.ACTION_VIDEO_RECORD);

            // Use the GET_CONTENT intent from the utility class
            Intent target = com.xxx.xxx.filechooser.FileUtils.createGetContentIntent();
            if (isAllowMultiple) {
                target.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            }
            // Create the chooser Intent


            if (activity != null) {
                Intent intent = Intent.createChooser(
                        target, activity.getString(R.string.chooser_title));

                intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{captureIntent, audioRecordIntent, videoRecordIntent});
                activity.startActivityForResult(intent, IMAGE_ANNOTATION_REQUEST_CODE);
            } else {
                Intent intent = Intent.createChooser(
                        target, fragment.getString(R.string.chooser_title));

                intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{captureIntent, audioRecordIntent, videoRecordIntent});
                fragment.startActivityForResult(intent, IMAGE_ANNOTATION_REQUEST_CODE);
            }

        } catch (ActivityNotFoundException e) {
            xxxLog.e(DEBUG_TAG, "Error:" + e);
        } catch (Exception ex) {
            ex.printStackTrace();
            CommonUtilities.showToast(activity, activity.getString(R.string.error_message), Toast.LENGTH_LONG);
        }
    }

After this code chooser opens similar to like this. enter image description here

Now how can I add share location icon to this file chooser dialog and after selecting a particular location and share it to other user in chat application?

Kush Patel
  • 1,228
  • 1
  • 13
  • 34
  • You can try this editor for location sharing https://github.com/irshuLx/Android-WYSIWYG-Editor Or you can go with bottomsheet dialog for same dialog as whatsapp – Vidhi Dave May 30 '18 at 09:51
  • @VishvaDave I don't want it from Editor. I want to open it from chooser dialog. And after choosing a location it should be displayed like a last screenshot that i have attached. – Kush Patel May 30 '18 at 09:57
  • Try this bottomsheet dialog https://medium.com/glucosio-project/moving-from-dialogs-to-bottomsheetdialogs-on-android-15fb8d140295 and use custom layout in recyclerview item for map type... this will be a broad answer start on something and get back when any errors – Vidhi Dave May 30 '18 at 09:59

1 Answers1

2

Try :

  1. Any chooser don't have every type of actions (i.e video,location,audio,document etc) every chooser is based on one category. So for this chooser screen use Bottomsheet dialog. It is same as dialog it will have custom layout. just make one layout same as the screen and inflate in this.
  2. Now Inside dialog on click of location open place picker of google. It will look same as your location picker screen.
  3. For location display use a custom item layout in recyclerview. i.e layout will have linear layout(vertical) -> imageview and two textviews with some padding. Recyclerview demo.
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
  • Can you answer this https://stackoverflow.com/questions/50674829/how-to-display-location-message-in-chat-window-same-like-whatsapp-in-android-pro? – Kush Patel Jun 04 '18 at 06:53