I want to add a default profile picture for my logged in user in my Android application. The way android marshmallow and above android version provides default alphabetical contact picture in contacts. There is a similar application "Micopi Pico". I want to use such functionality in my Android application to display the alphabetical profile picture as user's default profile picture. Is there any library or API or any method to do so? please help me.
There are many libraries to do that, here is an example, a library called Text Drawable (Click here to know more)
Import with Gradle:
repositories{
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
dependencies {
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
}
Usage :
TextDrawable drawable = TextDrawable.builder()
.buildRect("A", Color.RED);
ImageView image = (ImageView) findViewById(R.id.image_view);
image.setImageDrawable(drawable);
You can go through the documentation to know more about the usage.
You should always try searching for a solution to your problem before asking a question in stack overflow.
Related
Is it possible to create an App which can receive images without using any permissions or buttons on the receiving device? I would like to show these images instantly on the device (device has no touchscreen so I can't accept any permissions). The device has only WiFi and no Bluetooth.
I was thinking about choosing a image from my smartphone, connect it to the target device, send it via WiFi-Direct(P2P) and display it on the device.
Is something like that possible? All the tutorials to sending/receiving images always have the issue that buttons or permissions are necessary.
Yes you can achieve that simply if you set an ImageView that will load the image from an URL (for example). Could be your website or a share site that has a static link reference.
It could look like that:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
Glide.with(this).load("https://your-image.png").into(imageView);
}
Use this implemtation in your build.gradle:
dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
And in the other build.gradle folder:
repositories {
google()
mavenCentral()
}
Here is a example video written in kotlin.
And also the glide feature explained at github.
I would like to display the URL preview entered by the user like skype app in . For example if i am entering a youtube url in the skype app to other person , it is automatically displaying the thumbnail preview of that URL entered by the user.
https://www.youtube.com/watch?v=QUgRDYehv0M
When i have entered above url means.. Skype automatically showing the thumbnail preview of that link like below:
Like skype i would like to do in android. Whenever if user enters any url means.. i need to show the preview of an url..
https://play.google.com/store/apps/details?id=com.leocardz.link.preview&feature=search_result
Refered above app.. anyother help or guidance will be helpful.
You can import the library using Gradle :
Simply add the repository to your build.gradle file:
repositories {
jcenter()
maven { url 'https://github.com/leonardocardoso/mvn-repo/raw/master/maven-deploy' }
}
And you can use the artifacts like this:
dependencies {
compile 'org.jsoup:jsoup:1.8.3' // required
compile 'com.leocardz:link-preview:1.2.1#aar'
}
You can refer this link for more details.
I have an app where i am adding shortcut. I want to add shortcut icon image from URL path(images are stored on server and can be change) instead of using Drawable but i don't know how to do that. I tried to find a lot on this community. Any help?
If the term used "shortcut icon" is a view or its descendants such as ImageView, then you can set the image, your application receive from the server by doing this :
add dependency to your app.gradle file :
compile 'com.github.bumptech.glide:glide:3.7.0'
and in the activity you can use this method to set the image to the imageview your app receive from the server :
ImageView imageView = (ImageView) findViewById(R.id.image_view);
Glide.with(imageview.getContext()).load("https://url").error(R.drawable.not_found).centerCrop().into(imageview);
What you could do is first download that icon and store locally and then take that file path and use
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, UUID.randomUUID().toString())
.setIntent(intent) // !!! intent's action must be set on oreo
.setShortLabel(lable)
.setIcon(IconCompat.createWithAdaptiveBitmapContentUri(filePath)).build();
ShortcutManagerCompat.requestPinShortcut(this, shortcutInfo, null);
add this in your build.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
now you can load the image using following code
Picaso.with(this).load(urlHere).into(imageView);
I coose RxPparazzo to manage the images in my app, but I'm still having the same problem. I don't know why when I select more than one image from gallery, the lib retrieves always the same image per image that it should have been added.
/**
* Pick some images from gallery using RxPaparazzo lib.
*/
private void takePhotosFromGallery() {
RxPaparazzo.takeImages(this)
.usingGallery()
.subscribe(response -> {
if (response.resultCode() != Activity.RESULT_OK) {
response.targetUI().showUserCanceled();
return;
}
response.targetUI().loadImages(response.data());
});
}
UPDATED
Fixed in version 0.1.3
The lib duplicate images ?
UPDATED
Here the explanation why RxPaparazzo create new images.
remove images after retrieving them
thanks for use RxPaparazzo
I've just released a new library version which hopefully fixes this issue.
I say 'hopefully' because I haven't been able to reproduce the bug, but looking at the file names, which matches, I think they were saved at the same second, so I've added the milliseconds to the end of the filename.
Try it out and let me know if it works for you.
I don't think it's duplicating 'cause all the answers I've found were made several years ago. So, I load bitmap from URL and then do it this way:
currentView.setBackground(new BitmapDrawable(result));
...where "result" is Bitmap.
But "BitmapDrawable" is deprecated and it doesn't work from API 22 or 21.
Are there some other way of converting Bitmap to Drawable or loading drawable from URL instead of Bitmap?
As the documentation tells you - don't use the deprecated
new BitmapDrawable(result)
Instead use the API 18 version
new BitmapDrawable(getActivity().getResources(), result)
Assuming you're supporting API 18+, otherwise you need to handle both version depending on the runtime API.
Use Glide to load image from URL, Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.
Glide takes care of making scrolling any list of images as smooth as possible and also receive, resize and display remote image.
For more information refer here
Add below dependencies in build.gradle:
dependencies {
compile 'com.github.bumptech.glide:glide:3.6.0'
compile 'com.android.support:support-v4:19.1.0'
}
Eg project https://github.com/chrisbanes/cheesesquare
Eg usage:
#Override
public void onCreate(Bundle savedInstanceState) {
...
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
}
In the load method just pass the URL of the image and in into just pass the view, in you case currentview.
For your scenario:
Glide.with(this).load("http://goo.gl/gEgYUd").into(currentView);