package com.example.mobapp_16_2;

import java.util.List;

import org.apache.http.protocol.HTTP;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
	static final int SEND_MY_STR = 1;  // The request code

	public void sendintent(View view)
	{
		EditText edit = (EditText)findViewById(R.id.editText1);
		String s = edit.getText().toString();

		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType(HTTP.PLAIN_TEXT_TYPE);
		intent.putExtra(Intent.EXTRA_TEXT, s);

		PackageManager packageManager = getPackageManager();
		List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
		if (activities.size() > 0) {
			startActivityForResult(intent, SEND_MY_STR);
		}
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	    // Check which request we're responding to
	    if (requestCode == SEND_MY_STR) {
	        // Make sure the request was successful
	        if (resultCode == RESULT_OK) {
	        	Bundle extras = data.getExtras();
	        	
	        	String s = (String)extras.get("myresult");
	        	
	        	EditText edit = (EditText)findViewById(R.id.editText2);
	        	edit.setText(s);
	        }
	    }
	}	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
