Upload multiple photos to facebook from android (facebook sdk 3) - java

I am trying to upload all photos in my sdcard folder to facebook album . I have written the following code for the same. is the list of all the image files. But, programs runs in to exception. I am not able to figure out the reason. Any inputs in this regard are welcome .
RequestBatch requestBatch = new RequestBatch();
for (final String requestId : fileNames) {
Bitmap image = BitmapFactory.decodeFile(requestId);
Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), image, new Request.Callback() {
#Override
public void onCompleted(Response response) {
showPublishResult("Photo Post ", response.getGraphObject(), response.getError());
}
});
requestBatch.add(request);
}
requestBatch.executeAsync();
}
Update :
It is running into OutOfMemoryException. That means, the sdk is caching the files, and as a result this is happening . Is there any other way to achieve the same, rather than sending the bitmap image as request ?

The issue with above approach was executeAsync.
We need to create a new thread, make it a daemon(so that even on app exit, the upload can finish the queue), and to publish use executeAndWait. This way , all the files are serially uploaded.
If some one need the new code, Message here, i will post it

Related

How an app open custom action after install

Suppose an user wants to download a music from example.com. User goes to example.com from browser and clicks "download sample.mp3".Now instead of downloading the sample.mp3,the browser downloads an android app. When the user installs the app, the app downloads exactly the same 'sample.mp3' that the user clicked from the browser.
So, how do i make an app like this? Note: i can use download Api to download a music inside onCreate of the app without any views or anything.
But the key challenge here is to get the data that the user clicked in the browser (when my app was not even installed). Is it do-able somehow?
You can use firebase dynamic links for that.
You can pass the songId with the link and google play will pass that link into the app after installation. There you can extract the songId and start downloading the song.
One more advantage of the dynamic link is that google play will check if your app is already installed or not. If it is already installed then it will open the app directly else it will redirect to playstore page of the app.
To extract the songId in the app you can use below code:
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.w(TAG, "getDynamicLink:onFailure", e);
}
});

How to resume upload with AWS S3 Android

I am using AWS S3 bucket for Uploading list of files, I am using MultipleFileUpload and here is my request, while uploading the files if the internet gets disconnected and again came back then uploading process is not getting updated. How can I do so when internet is coming back, it should automatically get uploaded from the last position.
final ObjectMetadataProvider metadataProvider = new ObjectMetadataProvider() {
public void provideObjectMetadata(File file, ObjectMetadata metadata) {
}
};
final MultipleFileUpload multipleFileUpload = transferManager.uploadFileList(HttpUrls.IMAGE_BUCKET_NAME, "photos/mint_original/", myDir_temp, upload_file, metadataProvider);
The TransferManager component in the AWS Android SDK has been deprecated in favor of the TransferUtility component. The TransferUtility component allows you to pause and resume transfers. It also has support for network monitoring and will automatically pause and resume transfers when the network goes down and comes back up. Here is the link to the TransferUtility documentation - https://aws-amplify.github.io/docs/android/storage

Wicket: AJAXDownload - dowload several files

I am using the wicket framework.
I have a requirement to send to the client browser several individual files (a zip file is not relevant).
I have added to my page an AJAXDownload class that extends AbstractAjaxBehavior - a solution for sending files to the client like this:
download = new AJAXDownload(){
#Override
protected IResourceStream getResourceStream(){
return new FileResourceStream(file){
#Override
public void close() throws IOException {
super.close();
file.delete();
}
};
}};
add(download);
At some other point in my code I am trying to initiate the download of several files to the client using an ajax request whilst looping through an arraylist of files and then each time triggering the AJAXDownload:
ArrayList<File> labelList = printLabels();
for(int i=0; i<labelList.size(); i++){
file = labelList.get(i);
//initiate the download
download.initiate(target);
}
However, it is only sending just one of these files to the client. I have checked and the files have definitely been created on the server side. But only one is of them is being sent to the client.
Can anyone give me an idea what I am doing wrong?
Thanks
You are doing everything correct!
I don't know how to solve your problem but I'll try to explain what happens so someone else could help:
The Ajax response has several entries like:
<evaluate>document.location=/some/path/to/a/file</evaluate>
wicket-ajax.js just loops over the evaluations and executes them. If there is one entry then everything is OK - you have the file downloaded. But if there are more then the browser receives several requests for changing its location in very short time. Apparently it drops all but one of them.
An obvious solution would be to use callbacks/promises - when a download finishes then trigger the next one. The problem is that there is no way how to receive a notification from the browser that such download finished. Or at least I don't know about it.
One can roll a solution based on timeouts (i.e. setTimeout) but it would be error prone.
I hope this information is sufficient for someone else to give you the solution!

Google Drive Api result.getStatus().isSuccess() always true

I'm managing the callback this way but the result is always success when it shouldn't.
Example:
I search a file that doesn't exist and it doesn't show the log
I search a file when disconnected from the internet and still it doesn't show the log
Even if i create a file on drive when disconnected from the internet and set a callback for its creation, the result is success.
Here is the callback code
ResultCallback<DriveApi.DriveContentsResult> searchCallback =
new ResultCallback<DriveApi.DriveContentsResult>() {
#Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "cant open file");
}
}
};
What am i doing wrong?
The Android API has offline support, so performing an operation while offline will not fail. Instead, any changes are queued up to occur when the device comes back online.
Similarly, searching for something that doesn't exist doesn't fail, it just returns an empty result.
You handling of success looks fine, you just aren't testing cases that will actually fail.

jQuery webcam refresh. Wait for request to finish

As I talk about befor I'm using to jQuery to refresh / update a webcam image.
This works just fine if you wanna update the image every 5th or 10sec.
But when your gonna do a stream with 10-15fps it gets into problems with most browsers
it seems. The problem seem to be that it sends a request befor the first one was done.
Is there a way to wait for the first request to be done befor sending a new update request for the webcam image? Because to me it seems to stack up requests if there is alittle delay on the server with the image.
Sorry if I did explain it alittle bad but... I'm norwegian and blode. Not the best combination. :)
Webcam Image is a single url
ex. http://www.ohoynothere.com/image.jpg
Old code I use.
$(document).ready(function() {
setInterval('updateCamera()',3000);
});
function updateCamera() {
$('.online2').each(function() {
var url = $(this).attr('src').split('&')[0];
$(this).attr('src', url + '&rand=' + new Date().getTime());
})
}
Definitely!
It sounds like your best bet would be to use the jQuery.ajax() method ( http://api.jquery.com/jQuery.ajax/ ) or .get() method to chain your requests. Basically, you want a JavaScript function that does a request for the image using the .ajax() call. In the response handler, simply call the function again:
function getMyImage() {
jQuery.get(image_url, function(response) {
jQuery('#img-name').attr('src', response);
getMyImage();
});
}
Whenever getMyImage successfully returns the image's src value from the webcam, it will immediately go out and try to retrieve a new image, but not before the previous one is loaded.
If I haven't understood what you're trying to do, please let me know. It would be helpful to know more about how the webcam image is retrieved (i.e. is it the same image src returned every time, etc.).

Categories

Resources