I have a problem when wanna get my photos from dropbox and load it into GridView and i want use Picasso in adapter too.
method load() will take a downloadable URL ,
PS: i'm using Dropbox Android SDK 1.6.1
if i used method media() and fetch url from dropbox like that :
// Get the metadata for a directory , | request |
DropboxAPI.Entry dirent = Log_in.mApi.metadata(Log_in.APP_DIR + "/images/", 1000, null, true, null);
if (!dirent.isDir || dirent.contents == null) {
// It's not a directory, or there's nothing in it
mErrorMsg = "File or empty directory";
//return false;
}
// Make a list of everything in it that we can get a thumbnail for
thumbs = new ArrayList<>();
imagePath = new ArrayList<>();
for (DropboxAPI.Entry ent : dirent.contents) {
if (ent.thumbExists) {
// Add it to the list of thumbs we can choose from
thumbs.add(ent);
// do another requests (many requests to dropbox to get the urls , and this is terrible it takes request time for each image !
imagePath.add(Log_in.mApi.media(ent.path,true).url);
}
}
it is not practicle at all cuz it would take so much time to get every url this is the scenario :
Search images in Photos folder (1 request)
Using [media][1] for getting direct URL (1 * (images) requests)
Using Picasso in adapter (1 * (images) requests)
I will have count(images) * 2 + 1 requests count
it is terrible , need a better solution .
PS : i tried this https://medium.com/#jpardogo/requesthandler-api-for-picasso-library-c3ee7c4bec25#.wpmea1eci
but the code is not complete there is some classes not resolved/exist and some variables not defined .
so any one got an idea on how to work with dropbox images api using picasso .
i think there is a sample from dropbox about this, try to check this link dropbox sample
there is 2 files that you need to see PicassoClient.java And FileThumbnailRequestHandler.java
Related
Im making and android app which let the user select an image from the phone and load it to an ImageView. The further process is to send the image as a POST request to a PHP script
It all works fine if I load the image to a File object from the file location, but this require that the user open a setting on the phone which allow the app to access and manage local files..
So, is there a way to read the image from the imagview into a File object?
This is my current working code
val fil = File(getRealPathFromURI(imageUri!!).toString())
if (Build.VERSION.SDK_INT >= 30){
if (!Environment.isExternalStorageManager()){
var getpermission = Intent()
getpermission.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
startActivity(getpermission);
}
}
var reqB = RequestBody.create("image/*".toMediaTypeOrNull(),fil)
var part = MultipartBody.Part.createFormData("file",fil.name,reqB)
Kotlin throws an access error if I try to load it to a File object if the users dont allow it through the settings on the phone. I believe its a security issue on android.
Really what I want to do is
Let the user select an existing image on the phone
Display it in an imageview
Create a function which get the selected image into an MultipartBody.part without the user having to grant the app access to special rights
How to get all posts (Post) that have images (Relation) in android Parse
My code
// get their postsList
ParseQuery<Post> query = new ParseQuery<Post>(Post.class);
query.orderByDescending("views");
query.whereExists("images"); // only post with images attached to
query.include("User.profileImage.image");
query.whereEqualTo("isPublic", true);
posts = query.find();
I need to exclude any post that has zero images.
in another words, how to get posts whose images column is Relation with a size of 1 or more
I've one class that is a little like your reported case, but I'll send for you using JS code, at Parse Server, you can upload it at your Cloud Code. Back4App makes available in your features to upload the file in: Server Settings> Cloud code section> Settings or you can use the CLI to upload the files (Command Line Interface), the code to check if the image have relation is:
var Images = Parse.Object.extend("Image");
var query = new Parse.Query(Images);
var object;
query.doesNotExist("image");
query.doesNotExist("picture");
query.find()
.then(function(results) {
for (var i = 0; i < results.length; i++) {
object = results[i];
console.log(object.id);
}
});
At Parse Server Docs, you have a guide to Android, I checked here, will be something like:
query.whereDoesNotExist("image");
If you want to include more columns at yout logic, just insert it before call the find() method :)
I'm developing an Android application I have implemented a custom listview with a header (ImageView) and a content (different textview), all data the data are obtained from a json that contais all text and a link that directs to an image.
I have to implement a function that download images in a local folder and instead of downloading them from the internet to fetch from the local folder.
I have to problem :
1) I have to implement a function that download in local storage the images during the parsing of my JSON. If the parser found an image must be downlaoded.
2) After the parsing the downloaded images must be associated to the local images.
3) When i try to show all the data, the images must be showed from local.
(Actually I use volley to load images from internet)
How i can do this ? How i can maintain the link beetween images and data
[
{
"date":"MY DATE",
"desc":"My description",
"id":"1",
"img":"http:\/\/MYURL\/FOLDER\/homeone.jpg",
"text":" My text",
"title":"My title"
}
]
***** EDIT 1 *****
I have a problem with Picasso library, I don't understand how I can implement the cache. For example, after the parsing of my JSON I can get the url of my JSON item.
In this case http:\/\/MYURL\/FOLDER\/homeone.jpg now I have to save the image to he local storage.
Picasso.with(this)
.load(url)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView);
This is the code that I have found in another question on StackOverflow, this could help me to create the cache ? If yes, how i can specify the cache folder ?
Is is possible only save the images on local storage ? This cache is "permanent" or all data will deleted when the application is re-started ?
What you are trying to achive is implemented in Picasso
Try to avoid wheel inventing :)
UPD:
Picasso cache images automatically and you don't need to care about this thing at all. However, you can try this example to setup cache manuallly.
This is how you can define your cache with a help of OkHTTP:
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(connectTimeOut, TimeUnit.SECONDS);
client.setReadTimeout(readTime, TimeUnit.SECONDS);
File cachePath = FuncFileDownload.getStoragePath(context, "pre");
client.setCache(new com.squareup.okhttp.Cache(cachePath, 30000000));
sPicasso = new Picasso.Builder(context)
.downloader(new OkHttpDownloader(client))
.build();
Picasso.setSingletonInstance(sPicasso);
I am trying to get the image URL from the Dropbox and I followed the below code from the documentation.
try {
Entry directory = dropboxApi.metadata("/", 1000, null, true, null);
directory.mimeType = "image*//*";
for (Entry entry : directory.contents) {
DropboxAPI.DropboxLink link = dropboxApi.media(entry.path, false);
if (link.url.contains(".jpeg") || link.url.contains(".png") || link.url.contains(".jpg"))
files.add(link.url);
}
} catch (DropboxException e) {
e.printStackTrace();
}
Based on this code I can get the image URL. But it is not working after hours.
In my scenario, I want to get the image URL and I will send it to server API. So when I retrieve other API, I will get the image URL, what I sent. Once I got the URL, just I want to set it to imageview.
I have verified this link. I got the different link by using share method. But I don't know how to set that into my ImageView, whereas by using media method I can get the URL and I can set it to ImageView.
Please can someone help me to solve this problem
If i make an Http request for share url then I am getting image name with download option.
I am getting 16 headers.
From this am not getting any clue. There is no header name contains Location.There is one content-piracy-policy which gives some url values combined. But it is also not relevant.
So i am trying to display facebook photos from an album in and Android app.
The problem i am having is if i call this:
facebookAsyncRunner.request(albumId + "/photos", new UserAlbumPhotosFetchListener(JSONResponse, photoView));
i get a JSONResponse of an array of 25 photos. However, i need more than just 25 photos... i need all of them in the album. So i tried calling this:
facebookAsyncRunner.request(albumId + "/photos?limit=50", new UserAlbumPhotosFetchListener(JSONResponse, photoView));
in an attempt to get 50 photos instead of 25. This did not work. Instead i got nothing.
I also tried calling this same thing with limit=0, but this is giving me the same result.
to be specific: JSONResponse.getJSONArray("data") = []
Does anyone have any idea of what is happening/ how to request more than just 25 photos from an album?
thanks!
EDIT: I found a solution!
Bundle params = new Bundle();
params.putString("limit", "10");
facebookAsyncRunner.request(albumId + "/photos", params, new UserAlbumPhotosFetchListener(JSONResponse, photoView));
I have posted an answer which integrates pagination for an Endless Scrolling List here:
https://stackoverflow.com/a/13265776/450534
It is too big to post all over again, so am linking to the original answer instead. The answer is literally a complete a solution on how to make a Facebook query to an Album, fetch all photos (limited initially with a limit=10) and then fetching additional photos from the album when the user has scrolled down to the end and adding them to the existing list of Photos already fetched.
It uses a GridView instead of a ListView but the logic remain the exact same.
Alternatively, if you are looking only for a way to fetch Photos, here is a far simpler solution to get you started.
try {
String test = Utility.mFacebook.request("/10151498156121729/photos&access_token=YOUR_ACCESS_TOKEN?limit=1");
Log.e("TEST", test);
} catch (Exception e) {
// TODO: handle exception
}
The Album ID (10151498156121729) used in the code block above, is a Facebook Public Album.
I use the Utility class from the pre-3.0 Facebook SDK's HackBook example. If you are using the 3.0 SDK, I think you will need to substitute the Utility.mFacebook.request bit with an instance of the Facebook class
You should need to use Pagination for getting more than 25 photos. You can get only 25 items as result for a single query. To load the next 25 you should use the code like below:
facebookAsyncRunner.request(albumId + "/photos?offset=25&limit=25", new UserAlbumPhotosFetchListener(JSONResponse, photoView));
this will return the next 25 items, in this case the photos from 25th position to 50th position.
Try in this way..
Hope this may solve your problem.