I try to add some hyperlinks in mail body when I create my intent but they don't appears in the previsualisation and mail sent.
Also, I set the mime type with "text/html" and I used EXTRA_TEXT static.
This is my code :
String text = "";
text += "<html><body>";
text += "<a href=\"" + CallAPI.mBaseUrl +
"/uploads/media/default/0001/01/021ffb272477a45c032c178de0160e352134f8dd.png" + "\">" + "test" + "</a>";
text += "</body></html>";
Log.d("FragmentFicheProduit", text);
Utils.openApplication(rootView.getContext(), "com.lotus.sync.traveler", getResources().getString(R.string.information_nom_produit) + " " + produit.getNom_produit(), text, null);
public static void openApplication(final Context context, String packageN, String subject, String text, ArrayList<Contact> contactArrayList) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
if (i != null) {
if (subject != null)
i.putExtra(Intent.EXTRA_SUBJECT, subject);
if (text != null)
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(text));
if (contactArrayList != null) {
String[] tmp = new String[contactArrayList.size()];
for (int y = 0; y < contactArrayList.size(); y++) {
tmp[y] = contactArrayList.get(y).getEmailaddress1();
}
i.putExtra(android.content.Intent.EXTRA_EMAIL, tmp);
}
final PackageManager pm = context.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(i, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches) {
if (info.activityInfo.packageName.endsWith(".traveler")) best = info;
}
if (best != null)
i.setClassName(best.activityInfo.packageName, best.activityInfo.name);
context.startActivity(i);
} else {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageN)));
} catch (android.content.ActivityNotFoundException anfe) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + packageN)));
}
}
}
Thanks in advance :)
Related
On clicking the order app in the app that i have created, it calls the submitOrder() method and it is supposed to display the order summary by calling the createOrderSummary() method in gmail .However the gmail app does not open and it displays the message (which is in the else block )that I can’t display the intent.(i am new to android development.)
CheckBox whippedCreamBox = (CheckBox) findViewById(R.id.whipped_cream_check_box);
boolean isWhippedCreamBoxChecked = whippedCreamBox.isChecked();
CheckBox chocolateBox = (CheckBox) findViewById(R.id.chocalate_check_box);
boolean isChocolateBoxChecked = chocolateBox.isChecked();
int price = calculatePrice(quantity, isWhippedCreamBoxChecked, isChocolateBoxChecked);
EditText nameEditText = (EditText) findViewById(R.id.name_edit_text);
Editable userEnteredString = nameEditText.getText();
String priceMessage = createOrderSummary(userEnteredString, price, isWhippedCreamBoxChecked, isChocolateBoxChecked);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SENDTO);
sendIntent.setData(Uri.parse("mailto:ritvikupadhyay2000#gmail.com"));
sendIntent.setType("text/plain");
sendIntent.putExtra(sendIntent.EXTRA_SUBJECT, "Order for the just java app");
sendIntent.putExtra(sendIntent.EXTRA_TEXT, priceMessage);
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
else
{
displayMessage("I can't display the intent");
}
and here is the java code for createOrderSummary()
private String createOrderSummary(Editable userEnteredString, int price, boolean isWhippedCreamBoxChecked, boolean isChocalateBoxChecked) {
String priceMessage = "Name:" + userEnteredString + "\nAdd whipped cream?" + isWhippedCreamBoxChecked + "\nAdd chocalate?" + isChocalateBoxChecked + "\nQuantity:" + quantity + "\nTotal:$" + price + "\nThank you!\n";
return priceMessage;
Try this way, it is from official docs.
And also note to use String array, many claims using String array only works.
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
I have a BroadCastReciver in my app which listen for incoming sms.
I want to when sms receive, application open the google map via intent. This is my code but I don't know where is my mistake.
Thank's for any help.
BroadcastReciver.class:
public class IncomingSms extends BroadcastReceiver {
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
startAct(message, context);
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}
private void startAct(String message, Context con) {
double Mylatitude = 12;
double Mylongitude = 11;
GPSTracker tracker = new GPSTracker(con);
if (tracker.canGetLocation()) {
Mylatitude = tracker.getLatitude();
Mylongitude = tracker.getLongitude();
}
String location = message;
String ACC_lat = location.substring(0, location.indexOf(","));
String ACC_lang = location.substring(location.indexOf(",") + 1, location.length());
Toast.makeText(con, ACC_lang + " ^ " + ACC_lat, Toast.LENGTH_LONG).show();
Intent mapIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + Mylatitude + "," + Mylongitude + "&daddr=" + ACC_lat + "," + ACC_lang));
con.startActivity(mapIntent);
}
I also added it in manifest.xml file
You need to split URI into two parts, use one in costructor of Intent and other as package. Here is more details, how to send intents.
Sample:
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
How do i can read data from received mms.
I receive an mms but I can't take any data from it to save it
public class MmsReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String type = intent.getType();
Utils.PrintInfo("Action : "+action+", Type : "+type);
Bundle bundle = intent.getExtras();
Utils.PrintDebug("bundle " + bundle);
if (bundle != null) {
for(String k:bundle.keySet()) {
Utils.PrintInfo(k);
}
byte[] buffer = bundle.getByteArray("data");
Utils.PrintDebug("buffer " + buffer);
String incomingNumber = new String(buffer);
int indx = incomingNumber.indexOf("/TYPE");
if (indx > 0 && (indx - 15) > 0) {
int newIndx = indx - 15;
incomingNumber = incomingNumber.substring(newIndx, indx);
indx = incomingNumber.indexOf("+");
if (indx > 0) {
incomingNumber = incomingNumber.substring(indx);
Utils.PrintDebug("Mobile Number: " + incomingNumber);
}
}
int transactionId = bundle.getInt("transactionId");
Utils.PrintDebug("transactionId " + transactionId);
int pduType = bundle.getInt("pduType");
Utils.PrintDebug("pduType " + pduType);
byte[] buffer2 = bundle.getByteArray("header");
String header = new String(buffer2);
Utils.PrintDebug("header " + header);
}
}
}
data from that mms looks like
data : ???1351504361#mms2??????+48668822862/TYPE=PLMN???????????????http://mmsc.play.pl/?id=1351504361B??
how can I get any image from it? - i have send image from other device to that one
This intent has stoppped working . It was working for 2 months
2 month ago class name has changed from "com.twitter.android.PostActivity" to "com.twitter.applib.PostActivity" . I think it changed again. Is it changed again again and again ?
Can anyone help me to post tweet ?
and sorry about my english
try {
getPackageManager().getPackageInfo(
"com.twitter.android", 0);
Intent twitterIntent = new Intent(
Intent.ACTION_VIEW);
String twitterVersionName = getPackageManager()
.getPackageInfo("com.twitter.android",
0).versionName;
VersionControl currentVersion = new VersionControl(
twitterVersionName);
VersionControl requestedVersion = new VersionControl(
"4.1.9");
if (currentVersion.compareTo(requestedVersion) > -1) {
twitterIntent.setClassName(
"com.twitter.android",
"com.twitter.applib.PostActivity");
} else {
twitterIntent.setClassName(
"com.twitter.android",
"com.twitter.android.PostActivity");
}
twitterIntent.putExtra(Intent.EXTRA_TEXT,
tweetText);
startActivity(twitterIntent);
} catch (NameNotFoundException e) {
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/intent/tweet?source=webclient&text="
+ URLEncoder.encode(
tweetText, "UTF-8"))));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
Twitter change "com.twitter.applib.PostActivity" to "com.twitter.applib.composer.TextFirstComposerActivity"
You don't need to search for exact name , you can try like this,
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Your text here");
shareIntent.putExtra(Intent.EXTRA_STREAM, screenShot);
String appName = "twitter";
// use also instagram, pinterest, mail etc for appName.(not facebook)
final PackageManager pm = _activity.getPackageManager();
final List<?> activityList = pm.queryIntentActivities(shareIntent, 0);
int len = activityList.size();
Log.d("Tag","Length: "+len);
for (int i = 0; i < len; i++)
{
final ResolveInfo app = (ResolveInfo) activityList.get(i);
Log.d("Apps on share list: "+ app.activityInfo.name);
if ((app.activityInfo.name.contains(appName)))
{
Log.d("Tag","Found package: "+app.activityInfo.name);
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.setComponent(name);
//TODO change your activity here
_activity.startActivityForResult(shareIntent,SHARE_REQUEST_CODE);
return;
}
}
// not found so make default redirecting
Log.d("Tag","Not Found package: ");
The Google API allows us to get the list of all active admins in the device from the method: getActiveAdmins(). However, my requirement is that I want the list of all possible admins in the device , whether active or not. Is there some method to do so ?
Thanks
You can find list of applications by below code
final Intent deviceAdminIntent = new Intent("android.app.action.DEVICE_ADMIN_ENABLED", null);
final List<ResolveInfo> pkgAppsList = getPackageManager().queryBroadcastReceivers(deviceAdminIntent, 0);
for (ResolveInfo aResolveInfo : pkgAppsList) {
String pkg = aResolveInfo.activityInfo.applicationInfo.packageName;
String name = aResolveInfo.activityInfo.applicationInfo.loadLabel(getPackageManager()).toString();
System.out.println("Package :: " + pkg);
System.out.println("Name :: " + name);
}
You can get all the necessary data in the ResolveInfo of an application. You can check ResolveInfo javadoc here.
I wrote a method which returns the ComponentName as same as getActiveAdmins
private List<ComponentName> getAllAdmins(Context mContext) {
List<ComponentName> result = new ArrayList<ComponentName>();
// Read all receivers who can listen android.app.action.DEVICE_ADMIN_ENABLED
// You can add all other action which can be used for DeviceAdminReceiver
final Intent deviceAdminIntent = new Intent("android.app.action.DEVICE_ADMIN_ENABLED", null);
final List<ResolveInfo> pkgAppsList = mContext.getPackageManager().queryBroadcastReceivers(deviceAdminIntent, 0);
for (ResolveInfo aResolveInfo : pkgAppsList) {
// Prepare component and add to list
result.add(new ComponentName(aResolveInfo.activityInfo.applicationInfo.packageName,
aResolveInfo.activityInfo.name));
//String pkg = aResolveInfo.activityInfo.applicationInfo.packageName;
//String name = aResolveInfo.activityInfo.applicationInfo.loadLabel(getPackageManager()).toString();
//System.out.println("Package :: " + pkg);
//System.out.println("Name :: " + name);
}
return result;
}
You can find the necessary code in the following Android source for DeviceAdminSettings: https://android.googlesource.com/platform/packages/apps/Settings/+/kitkat-release/src/com/android/settings/DeviceAdminSettings.java
DevicePolicyManager mDPM; // = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
...
mActiveAdmins.clear();
List<ComponentName> cur = mDPM.getActiveAdmins();
if (cur != null) {
for (int i=0; i<cur.size(); i++) {
mActiveAdmins.add(cur.get(i));
}
}
mAvailableAdmins.clear();
List<ResolveInfo> avail = getActivity().getPackageManager().queryBroadcastReceivers(
new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
if (avail == null) {
avail = Collections.emptyList();
}
// Some admins listed in mActiveAdmins may not have been found by the above query.
// We thus add them separately.
Set<ComponentName> activeAdminsNotInAvail = new HashSet<ComponentName>(mActiveAdmins);
for (ResolveInfo ri : avail) {
ComponentName riComponentName =
new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name);
activeAdminsNotInAvail.remove(riComponentName);
}
if (!activeAdminsNotInAvail.isEmpty()) {
avail = new ArrayList<ResolveInfo>(avail);
PackageManager packageManager = getActivity().getPackageManager();
for (ComponentName unlistedActiveAdmin : activeAdminsNotInAvail) {
List<ResolveInfo> resolved = packageManager.queryBroadcastReceivers(
new Intent().setComponent(unlistedActiveAdmin),
PackageManager.GET_META_DATA
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
if (resolved != null) {
avail.addAll(resolved);
}
}
}
for (int i = 0, count = avail.size(); i < count; i++) {
ResolveInfo ri = avail.get(i);
try {
DeviceAdminInfo dpi = new DeviceAdminInfo(getActivity(), ri);
if (dpi.isVisible() || mActiveAdmins.contains(dpi.getComponent())) {
mAvailableAdmins.add(dpi);
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Skipping " + ri.activityInfo, e);
} catch (IOException e) {
Log.w(TAG, "Skipping " + ri.activityInfo, e);
}
}
getListView().setAdapter(new PolicyListAdapter());
This is how Android lists them for you in the Device Admins tab.