Problem obtaining data from EXTRA_TEXT [closed]

1

In the design company for which I work we try to create a private messaging application which allows us to share different URLs from different applications such as social networks, so that when we share it, it is added in the body of the message, for this We use different intent-filters for each desired application and try to get that URL through an intent something like this:

  Bundle ext = getIntent().getExtras()
  String URLX = ext.getString(Intent.EXTRA_TEXT)

While I have the intent-filter defined in the AndroidManifest.xml:

        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:mimeType="text/plain" />
        </intent-filter>

We are in doubt to know if this is the correct way to obtain said URL or image in the case of some social networks, and in what way that intent / string can be applied to automatically complete the EditText field of the message body once shared. I hope I could explain myself in a correct and understandable way.

Edit:

We are trying to add the URL obtained through the following code:

      Bundle extras = getIntent().getExtras();
    String URL = extras.getString(Intent.EXTRA_TEXT);
          et1.setText(URL);

But the application is not giving the desired results

    
asked by Mariano Martin 18.11.2016 в 13:54
source

3 answers

0

See if with this you can guide yourself: link I recently need something similar and there is very well explained

    
answered by 18.11.2016 в 15:12
0

It is received by:

  String textoRecibido = intent.getStringExtra(Intent.EXTRA_TEXT);

What you are defining is a filter so that a content type in this case text/plain can be opened by your application:

<intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:mimeType="text/plain" />
    </intent-filter>

In this case, when you sent an email through Intent.createChooser () your application would appear in the list of applications that can handle this type of content.

This is an example of sending email:

  String[] TO = {""}; //Direcciones email  a enviar.
  String[] CC = {""}; //Direcciones email con copia.

  Intent emailIntent = new Intent(Intent.ACTION_SEND);

  emailIntent.setData(Uri.parse("mailto:"));
  emailIntent.setType("text/plain");
  emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
  emailIntent.putExtra(Intent.EXTRA_CC, CC);
  emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Tu Asunto...");
  emailIntent.putExtra(Intent.EXTRA_TEXT, "[email protected]"); // * configurar email aquí!

  try {
     startActivity(Intent.createChooser(emailIntent, "Enviar email."));        
     Log.i("EMAIL", "Enviando email...");
  }
  catch (android.content.ActivityNotFoundException e) {
     Toast.makeText(this, "NO existe ningún cliente de email instalado!.", Toast.LENGTH_SHORT).show();
  }

When making the shipment, a screen would appear, where you can make the selection of the client to send the email, including your application since it has defined the intent-filter to perform this action for this type of content ( text/plain ) .

Review the documentation "Receive data from other applications" (English)

    
answered by 18.11.2016 в 16:56
0

Solved, I leave the code in case someone needs it in the future

    Intent receivedIntent = getIntent();
    String receivedAction = receivedIntent.getAction();
    String receivedType = receivedIntent.getType();
    //make sure it's an action and type we can handle
    if(receivedAction.equals(Intent.ACTION_SEND)){

    }
    else if (receivedAction.equals(Intent.ACTION_MAIN)){

    }

    String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
    //check we have a string
    if (receivedText != null) {
        //set the text
        et1.setText(receivedText);
    }
    
answered by 18.11.2016 в 19:57