In Android: I would like to get dummy icon assign to a contact. I'm able to get if there's any image assign to the contact with contact-id.
Try this url Retrieve System Default Android Contact Picture.
I think this image is private to Contacts application and you may get the image from
\android-sdk\platforms\android-v#\data\res\drawable\
Related
I am working on an app which saves users social networks links in the default contacts app provided by Android OS.
I am able to save link in the app but I am not able to customize the title as you can check in the image below of Default Contacts App:
I am using below code to save linkedin url as an example for now but I want to save it as linkedin title instead of Website and also linkedin icon.
Current Code block:
if (loginResponseData.getLinkedin() != null) {
ContentValues values = new ContentValues();
values.put(ContactsContract.Data.RAW_CONTACT_ID, contactid);
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
values.put(ContactsContract.CommonDataKinds.Website.DATA, loginResponseData.getLinkedin());
fragmentActivity.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
}
For each Data type you want to persist into the Database, you should go into the documentation and check which fields it supports and you might want to fill them in your insert call.
You can check here: https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Website
That CommonDataKinds.Website supports the fields URL, TYPE and LABEL.
The text that appears below the url in the contacts app is the label field.
So your code can look something like this:
ContentValues values = new ContentValues();
values.put(Data.RAW_CONTACT_ID, contactid);
values.put(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE);
values.put(Website.URL, loginResponseData.getLinkedin());
values.put(Website.TYPE, Website.TYPE_CUSTOM); // when this is set to CUSTOM, the contacts app will display the label field
values.put(Website.LABEL, "Linkedin");
contentResolver.insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
I am trying to change photos in android studio by clicking on my button.
When I put code for changing the photo in my MainActivity.java I keep getting this type of error messages and it says :
Cannot resolve symbol "image"
image.setImageResource(R.drawable.xxx);
I am watching Udemy course for android development and I have done everything same like the professor on that video.
I have tried to restart android studio.
I have tried to make new project.
I have tried to clear invalidate caches and restart.
public void changeImage(View view)
{
ImageView bitcoin = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
}
I hope there is actual error with android studio,because code is clone of the video that I am watching.
You are binding your layout's ImageView in Java file with bitcoin variable and you are trying to set an image on an unknown variable 'image'(maybe it's not defined in the class). So you have to set as below.
ImageView bitcoin = findViewById(R.id.bitcoin);
bitcoin.setImageResource(R.drawable.xxx);
Set Your Code Like this
ImageView image = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
change your this line
image.setImageResource(R.drawable.xxx)
to this one:
bitcoin.setImageResource(R.drawable.xxx)
I know this question may seem ambiguous to many users, but I'll try to elaborate the question in brief. I'm trying to build an object recognition application through android. The photo captured by the camera will be send to firebase database and from there the photo will be fetched by python script and recognition of image will be done. So my question is how can I code for an application which will push image from application to the database such as key of captured images by user(any application user) will be in sequence:
image1, image2, image3....
It implies that if 'a' user capture an image, photo will be uploaded to database with key 'image1'. After when user 'b' takes a photo, image will be pushed with the key 'image2'. Note that the application can be used by number of users simultaneously. So any suggestions on how should I implement this in android?
First, authenticate the user then get the id of each user and store in the database that way its easier to retrieve later on.
like this:-
DatabaseReference ref =
FirebaseDatabase.getInstance().getReference("users");
Firebase user=FirebaseAuth.getInstance().getCurrentUser();
//to send to database
ref.child("uid").setValue(user.getUID());
Now you have the userid under users, then under userid add an image.
So example:
{
"users":{
"userid":{
"name": "peter"
"image": "link_from_storage"
}
}
}
This way everytime a user captures an image he will have a userid for him.
Now for the image, you have to send it to the firebase storage and then take the link from there and store it in the database.
Example:
StorageReference filepath=mStorage.child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String downloaduri=taskSnapshot.getDownloadUrl().toString();
Basically the first line, you are adding the image to the firebase storage.Then you do a listener to get the image url from storage and put it in downloaduri.
Then to add image in database:-
ref.child("image").setValue(downloaduri);
Hope this helps!
The last time I used firebase was about 8-10 months back so I do not remember the syntaxes.
You can use Firebase's could storage to upload your images to cloud when users upload it. You can generate an id (key) accordingly and save it in the database with the reference to that image as the value to that key. You can read here how to do that.
Fortunately, Firebase functions can then be used with the Cloud storage to access and process the image. You just need to read about Cloud storage triggers.
you have to maintain some thing like this if im not wrong
Place holder folder image in firebase file system.
Place holder forder image_name, uploaded user_name(if required based on your needs) and time_stamp at what time uploaded.
Now first fetch the image_names, with timestamps and then based time stamp fetch images files.
I am building my application using Android Studio, this app can upload an image from raspberry to my emulator. It works fine. What I want to do now is uploading this image and showing it directly to the user without searching it in the gallery. I thought about creating another class and setting this image as a background image in my xml file, but this is too much like I have to create another class every time I want to upload an image from my raspberry.
Can someone help me please. Thank you
If I'm understanding your question correctly, you'd like to load an image from the Android filesystem into your app and display it to the user.
Drawable, Android's generalized image class, allows you to load from file via Drawable#createFromPath.
This SO question suggests Drawable#createFromPath doesn't work on paths beginning with file://, so depending on your use case you may want to precede that with Uri#parse/Uri#getPath.
Once you have a Drawable, you can display it in one of two ways: put an ImageView in your app and call its setImageDrawable method, or set the Drawable as your background image via View#setBackground (note that setBackground was only added in API 16 - in prior versions, you should call View#setBackgroundDrawable).
Putting all of this together, we end up with the following (untested):
private void loadImage(String imagePath) {
Uri imageUri;
String fullImagePath;
Drawable image;
ImageView imageDisplay;
imageUri = Uri.parse(imagePath);
fullImagePath = imageUri.getPath();
image = Drawable.createFromPath(fullImagePath);
imageDisplay = (ImageView) findViewById(R.id.imageDisplay);
/*if image is null after Drawable.createFromPath, this will simply
clear the ImageView's background */
imageDisplay.setImageDrawable(image);
/*if you want the image in the background instead of the foreground,
comment the line above and uncomment this bit instead */
//imageDisplay.setBackground(image);
}
You should be able to modify this to work with any View just by replacing imageDisplay's declared type with the appropriate View type and changing the cast on findViewById. Just make sure you're calling setBackground, not setImageDrawable, for a non-ImageView View.
I was very excited about Picasso android library . I have an android application that i want to use picasso but i have one problem in a place inside my application
I have a listview (endless) that display images in each item beside some text , now i don't have the Url for each item in the list ( I am using a stupid api ) , I have to hit the server with specific id ,then the server sent me image url(s) that i can use in Picasso .
example :
http://url/id/342
and the response look like
{
"images":["url_large":"http://........","url_medium":"http://........"]
}
I can't pre-load image url . because i have an endless list and for each item i need to call the web service to get it image url .
Can picasso handle this ?