Hi, I have this problem and I hope you can guide me.
I'm programming an application and I need to send a PDF file, I've already made the program and it's like this:
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.io.File;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button) findViewById(R.id.ButtonSendFeedback)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String to = ((EditText) findViewById(R.id.txtTo)).getText().toString();
String sub = ((EditText) findViewById(R.id.txtSubject)).getText().toString();
String mess = ((EditText) findViewById(R.id.txtMessage)).getText().toString();
String serv = ((EditText) findViewById(R.id.txtserv)).getText().toString();
String cuerpo = ((EditText) findViewById(R.id.txtBody)).getText().toString();
String archivopdf = "Download/Ordendeservicio.pdf";
Uri uri = Uri.fromFile(new File(Environment.getDownloadCacheDirectory().getAbsolutePath(), "file://" + archivopdf ));
Intent mail = new Intent(Intent.ACTION_SEND);
mail.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
mail.putExtra(Intent.EXTRA_SUBJECT, sub);
mail.putExtra(Intent.EXTRA_TEXT, "orden de servicio" );
mail.putExtra(Intent.EXTRA_STREAM, uri);
mail.setType("message/rfc822");
startActivity(Intent.createChooser(mail, "Send email via:"));
}
});
}
}
The code will open the gmail apk, but when it does, it tells me that the file can not be attached.
What do you think is the error that I have or that I have not configured correctly? Thank you in advance for any comments.