Embedding Inline image in email body - android

In my application i have to send image in body not as an attachment. I have spent more than one week and found no success. I have implemented same via Java mail API. But need to implement with intent. What i have tried is:
Spanned emailText11 = Html.fromHtml("<body><p><img src=\"http://www.datarecoverydownloadwebsite.com/drdwebsite/image/pen-drive1.jpg\" alt=\"Smiley face\" align=\"bottom\" width=\"32\" height=\"32\" /></p></body>", new Html.ImageGetter() {
#Override
public Drawable getDrawable(String source) {
Drawable drawFromPath;
int path = Inline_Image_Gmail.this.getResources().getIdentifier(source, "drawable", "com.package...");
drawFromPath = (Drawable) Inline_Image_Gmail.this.getResources().getDrawable(path);
drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(), drawFromPath.getIntrinsicHeight());
return drawFromPath;
}
}, null);
emailIntent.putExtra(Intent.EXTRA_STREAM,emailText11 );
I googled alot and ans is it is not possible. If not can anyone clear me the reason for this.
Thanks.

Related

Using Bypass to parse Markdown in Android, not working with Images

I'm using bypass lib to parse a markdown string to show inside a TextView.
What basically this lib does is to parse all strings and build an SpannedString to show this inside a TextView. I've debuged all the lib code and aren't able to find what is doing wrong in a reasonable time. Is there someone that have been faced the same problem and can help me?
String markdownStr = "# Testing Markdown\n" +
"\n" +
"![surf](http://www.adesl.pt/images/outras-provas/surf.jpg)";
TextView markdownTxtView = (TextView) findViewById(R.id.markdown);
Bypass bypass = new Bypass(getApplicationContext());
CharSequence charSequence = bypass.markdownToSpannable(markdownStr, new Bypass.ImageGetter() {
#Override
public Drawable getDrawable(String source) {
//TODO: get drawable from source
Drawable drawable = getApplicationContext().getResources().getDrawable(R.drawable.test);
return drawable;
}
});
markdownTxtView.setText(charSequence);
by adding bellow code it works:
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
Picasso Image Getter
https://github.com/Commit451/BypassPicassoImageGetter
Glide Image Getter
https://github.com/victorlaerte/BypassGlideImageGetter

Android : Calling images from drawable and displaying on the screen

I am designing a Image Puzzle(JigSaw) game. I am stuck in a problem that, when I start the game it shows the option "New Image" but, when I click on that, it gives an error message, means images from the drawable folder are not loading.
I did research and i came with this, i have implemented this in my code. but, it gives an error.. "Could not Load."
protected void newImage()
{
LinkedList<Uri> availableImages = new LinkedList<Uri>();
findInternalImages(availableImages);
if(availableImages.isEmpty())
{
Toast.makeText(this, getString(R.string.error_could_not_load_image), Toast.LENGTH_LONG).show();
return;
}
int index = new Random().nextInt(availableImages.size());
loadBitmap(availableImages.get(index));
}
protected void findInternalImages(List<Uri> list)
{
Field[] fields = R.drawable.class.getFields();
for(Field field: fields)
{
//String name = field.getName();
//if(name.startsWith(FILENAME_IMAGE_PREFIX))
//{
//int id = getResources().getIdentifier(name, "drawable", getPackageName());
for(int j=1;j<13;j++)
{
Drawable drawable = getResources().getDrawable(getResources()
.getIdentifier("image_"+j, "drawable", getPackageName()));
}
//}
}
}
My Problem is,
when i run the program it should show images from drawable folder and when i choose the one then actual scrambling should start. so, one can play the jig saw game.
Start by checking that your images are in a Android compatible format, that was causing me problems to begin with. I normally stick to .png now.
This is the code you will need to modify the image
ImageView pwrSwap = (ImageView) beaconitems.findViewById(R.id.yourImageID);
pwrSwap.setImageResource(R.drawable.yourImage);
http://developer.android.com/guide/appendix/media-formats.html

How do I iterate over a large number of resources with similar names?

I'm currently trying to start a thread which fetches a drawable from its resources and posts it after a set amount of time. Then fetches the next drawable from resources and does the same thing all over.
final ImageView zImageView = (ImageView) findViewById(R.id.zzz_animation_view);
new Thread(new Runnable() {
public void run() {
for(int i = 1; i<=510; i++)
{
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.z_animation0001); // how do I increment this recourse to z_animation0002, 0003, ..., 0510 ?
zImageView.postDelayed(new Runnable() {
public void run() {
zImageView.setImageBitmap(bitmap);
}
},200);
}
}
}).start();
Firstly. Is this a proper way of approaching the problem? The drawables are too large for me to use animation-list and as such my goal is to load the images one at a time to ensure that I have enough memory. Secondly how do I solve the problem of iterating over my resources?
You can get resource id by its name using Resources.getIdentifier :
final int current = 5;
final String pattern = "z_animation%04d";
final String name = String.format(pattern, current);
final int id = getResources().getIdentifier(name, "drawable", getPackageName());
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), id);
Also, here you can find my answer for the same question with code sample that does exactly what you want.
I would put the images in the assets folder and load them from there as described here: https://xjaphx.wordpress.com/2011/10/02/store-and-use-files-in-assets/
In the assets folder you can just add a number to the file name.

Loading Images to Textview with AsyncTask

My problem is the following: I try to load images to a text view like this:
URLImageParser p = new URLImageParser(textView, this);
Spanned htmlSpan = Html.fromHtml(textWithImages, p, null);
textView.setText(htmlSpan);
I followed this example https://stackoverflow.com/a/7442725/1835251
If I load images from the web it works perfectly.
I modified to code a bit to load certain images from SDCard as well.
In the "doInBackground" Method of the async task I implemented this:
#Override
protected Drawable doInBackground(String... params) {
String source = params[0];
Drawable d = null
if(source != null) {
if(source.startsWith("/myApp/images/")) {
localImage = true;
}
}
if(localImage) {
String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();
d = Drawable.createFromPath(sdcard+source);
d.setBounds(0, 0, 0 + (int)(d.getIntrinsicWidth()), 0
+ (int) (d.getIntrinsicHeight()));
localImage = false;
} else {
// load images from internet
}
return d;
localImage is a boolen which is set to determine if the current source "points" to an
image from the internet or a local image.
As stated before: Loading images from the internet works perfectly.
BUT when I load images from the SDCard it sometimes happens that not all images are displayed.
The whole text (including the images) gets cut as if it hasn't been loaded correctly.
I figured out that this happens much more often on a Samsung Galaxy S3 than on a Samsung S Plus.
On the S3 I sometimes load only 1 or 1.5 images and the rest gets cut.
The S Plus always loads all 4 images but rarely cuts the last 2 or 3 sentences of the text.
I think that it is a sort of a timing problem with the AsyncTask but I never worked with it before.
I know this is a really large post but I hope that someone still can help me.
Best regards
Siggy
Ok I am stupid... I solved it!
I forgot that I only need the AsyncTask if I load images from the internet. For local images I don't need that.
Solution for the interested:
ImageGetter imgGetter = new ImageGetter() {
#Override
public Drawable getDrawable(String source) {
String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();
Drawable d = Drawable.createFromPath(sdcard+source);
d.setBounds(0, 0, 0 + (int)(d.getIntrinsicWidth()), 0
+ (int) (d.getIntrinsicHeight()));
return d;
}
};
Spanned htmlSpan = Html.fromHtml(textAndImage, imgGetter, null);
textView.setText(htmlSpan);

create drawable from path problem

For some reason d=null when creating a drawable from coverArtURLStr, which is the full http path to the resource on the LAN.
Anything obvious wrong? It's a path to a .png
[I can access the LAN OK, and Data.defaultCoverArt works fine]
public static void updateCoverArt(String coverArtURLStr)
{
String coverArtURL = coverArtURLStr;
Drawable d;
if (coverArtURL.equals(""))
d = Data.defaultCoverArt;
else
d = Drawable.createFromPath(coverArtURL);
Data.coverArtIV.setImageDrawable(d);
}
I don't think Drawable.createFromPath() method can handle URLs. Try this solution Android Drawable Images from URL.

Categories

Resources