1.normal share
private void sendShare(String subject, String body, String type) {
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
try {
if (type == null || type.length() == 0) {
type = "text";
}
shareIntent.setType(type + "/*");
if (subject != null && subject.length() > 0) {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
}
if (body != null && body.length() > 0) {
shareIntent.putExtra(Intent.EXTRA_TEXT, body);
}
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
} finally {
PkrssActivity.s_pkrss.startActivity(Intent.createChooser(shareIntent, PkrssActivity.s_pkrss.getTitle()));
}
}
2.email share
private void sendEmail(String address, String body, String subject, boolean isHTML, String cc, String bcc, String attachment) {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
try {
if (isHTML) {
emailIntent.setType("text/html");
} else {
emailIntent.setType("text/plain");
}
if (subject != null && subject.length() > 0) {
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
}
if (body != null && body.length() > 0) {
if (isHTML) {
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
} else {
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
}
}
if (address != null && address.length() > 0) {
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address.split(";"));
} else{
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "pkrss@gmail.com");
}
if (cc != null && cc.length() > 0 && cc!="null") {
emailIntent.putExtra(android.content.Intent.EXTRA_CC, address.split(";"));
}
if (bcc != null && bcc.length() > 0 && bcc!="null") {
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, address.split(";"));
}
if (attachment != null && attachment.length() > 0 && attachment!="null") {
String[] attachments = attachment.split(";");
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i = 0; i < attachments.length; i++) {
File file = new File(attachments[i]);
if (file.exists()) {
uris.add(Uri.fromFile(file));
}
}
if (uris.size() > 0) {
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
}
}
} catch (Exception e) {
} finally {
PkrssActivity.s_pkrss.startActivity(Intent.createChooser(emailIntent, PkrssActivity.s_pkrss.getTitle()));
}
}
3.sms share
private void sendSMS(String phoneNumber, String message) {
try {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phoneNumber));//Intent.ACTION_MAIN
//intent.setData(Uri.parse("content://mms-sms/"));
intent.putExtra("sms_body", message);
PkrssActivity.s_pkrss.startActivity(intent);
return;
} catch (Exception e) {
e.printStackTrace();
}
}
No comments:
Post a Comment