G
G
Gfd2016-08-21 18:32:00
Java
Gfd, 2016-08-21 18:32:00

Can't figure out how action_send works in android?

Wrote this activity:

public class SendWelcomeActivity extends ActionBarActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            Intent intent = getIntent();
            String action = intent.getAction();
            String type = intent.getType();
    
            if (Intent.ACTION_SEND.equals(action) && type != null) {
                if ("*/*".equals(type)) {
                    try {
                        Person person = (Person) intent.getSerializableExtra(Intent.EXTRA_STREAM);
                        SerializationAndDeserialization.writeToFile(person.getName(), person, this);
                        saveName(person.getName());
                    } catch (Exception e) {
                        Toast.makeText(this, "Unknown format of file!", Toast.LENGTH_LONG).show();
                    }
                }
            }
    
            finish();
        }
    
        private void saveName(String name) {
            InformationAboutPersons inf = new InformationAboutPersons();
            String[] names = inf.getNames(this);
            if (names != null) {
                for (int i = 0; i < names.length; i++) {
                    if (names[i].equals(name)) {
                        return;
                    }
                }
                inf.addNamePerson(name, this);
            } else {
                inf.addNamePerson(name, this);
            }
        }
    }

Here it is in the manifest:
<activity android:name=".Controller.SendWelcomeActivity">
                <intent-filter>
                    <action android:name="android.intent.action.SEND" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="*/*" />
                </intent-filter>
            </activity>

It should open the file containing the object and save it.
Here is how I send this file by email:
try {
                String FILENAME = "filesLifeOrganizationRe" + mPerson.getName() + ".person";
    
                File imageFile = getFileStreamPath(FILENAME);
                Uri imageUri = Uri.fromFile(imageFile);
    
                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.setType("*/*");
                emailIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    
                this.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), 1);
            } catch (Exception e) {
                e.printStackTrace();
            }

Sending a file seems to work, but for some reason when I click on a file in gmail, it says that this file is not supported by the installed applications. And the very opening of the file does not work, person = null. I don't know how to do everything right
PS: I'm new to programming

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question