0

I want share URL from other app and add it in EditText field

Manifest:

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

Activity:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    et1=(EditText)findViewById(R.id.et1);

    Bundle extras = getIntent().getExtras();

    String value1 = extras.getString(Intent.EXTRA_TEXT);
    et1.setText(value1);

But when i try run app it close, what i'm doing bad? I see my app in share list so manifest isn't bad

Added: LogCat error at String lane

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • 1
    Use LogCat to examine the Java stack trace associated with your app: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Nov 18 '16 at 16:29
  • There could be serious mistakes in your Activity's `onCreate()` which we are unaware of because the code isn't in the question. Is there's a proper `setContentView()` call? Is there a (successfull) `findViewById()` call for the `EditText`? Is the `setText()` call after these and not before etc. You should share some more code. (And of course check and share the crash log from LogCat as suggested.) – Markus Kauppinen Nov 18 '16 at 16:34
  • I edited and add full code, but all it's ok i think, edited logcat warn – Mariano Martin Nov 18 '16 at 16:47

1 Answers1

0

Fixed code:

    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)){
        //content is being shared
    }
    else if (receivedAction.equals(Intent.ACTION_MAIN)){

    }

    String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);

    if (receivedText != null) {

        et1.setText(receivedText);
    }

Ty all