Android: Downloading flickr images - java

I have a project that I'm having trouble with (for an internship). My assignment is to create an Android app that downloads a random image from Flickr after running a search for a specified tag.
I know Flickr has an API, and I have an api key, but I'm struggling with understanding how to integrate this into an app, as it seems examples in Java are a bit sparse. Does anyone know the process of using the API to download an image after running a search? (Or if there's an easier way to do it without the API/being authenticated, that works too).
I should also mention that I can't use any external libraries.

For searching public photos you don't need to authenticate yourself with Flickr service API. First you have to register an API key for your apps, call the correct API function from the list
http://www.flickr.com/services/api/
and parse the result in format of JSON. But you can't use 3rd library in your project, you can follow this post
http://hintdesk.com/android-show-images-from-flickr-with-imagegridview/
it uses only Android libraries.

Well I can feel the difficulty of doing this w/o the so sweet and easy Flickrj-Android or Flickr4Java :)
The method you need is flickr.photos.getSizes.
Returns the available sizes for a photo. The calling user must have permission to view the photo.
You do not need to authenticate your API key if you do not want to download non-public photos.
Just get the wanted photo-id with a simple search (flickr.photos.search) and download the wanted photo with a simple URL file stream.
The returned data has the wanted download URL. So just run a parser and download away.

Related

How to prevent direct URL access of a file which is used in an Android app?

I have an mp3 file in a server, Example: www.example.com/Album/Songs/abc.mp3.
I am building an android app to list all files under 'Songs' folder and then play the selected ones.
Now, is there a way to prevent direct access to the mp3 file incase if someone gets hold of the URL?
I tried the usual methods like rewrite engine. It prevents direct URL access but it also blocks my app from using the files.
Here's my android code to play the files:
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(song_path);
player.prepare();
player.start();
The song_path is simply http://www.example.com/Album/Songs/abc.mp3
PS: I understand that encrypting through ProGuard will make it nearly impossible to get the direct URL through reverse engineering. I still wanted to check if there is any other way to make it work.
there is nothing you an do about it in your android app. its a policy the server side should take to prevent this. even if you proguard your APK there apps like wireShark which can sniff your app and find what APIs you are calling.
there are some ways to do this. some try to generate temprory links whenever the app (with a user that is logged in) calls a say play API they provide the app wit ha temporary link that will invalidates some minuets (or hour) later. then app uses that link to play the music or whatever.
another scenario is to encrypt the music bytes and decrypt in the application side that has more complicated considerations.
You can use player.setDataSource(Context context, Uri uri, Map<String, String> headers) to send a custom header. You can then check for that custom header in PHP or in Apache before returning the mp3.
To check in Apache, you would use a rewrite rule to check for and allow only connections with the correct header.
In PHP, you could use $_SERVER['HTTP_*YOUR_HEADER_HERE*'] and then echo the MP3 file along with the correct headers. Might be a bit tricky if you allow seeking.
The Apache rewrite rule may be the easiest to implement.

Android - Dropbox: Check for differences

Is it possible to check for differences between local and Dropbox?
Hello. I am currently working on a simple gallery App which displays all Dropbox images.
The workflow so far:
I log into Dropbox. The App scans recursively through all Dropbox folders and checks for images, then takes the metadata and displays the images.
Now I want to know if it is possible to check for differences so the App does not need to run through all folders every time but only if something has changed (for example if new images have been added to a Dropbox folder).
Thank you in advance.
The best way to keep track of changes in a Dropbox account when using the Dropbox API is by using /2/files/list_folder and /2/files/list_folder/continue:
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue
You should store the latest returned cursor, and then call back to /2/files/list_folder/continue using that cursor. It will returned only the changes since you last called.
For client-side apps, you can use /2/files/list_folder/longpoll to efficiently know when there are changes to retrieve:
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-longpoll
There are also corresponding methods if you're using an SDK. For example, in the Dropbox Java SDK for API v2, these are listFolder, listFolderContinue, and listFolderLongpoll, respectively.

Download Google Tag Manager container binary file with Google's API Client Library for Java

I use the TagManager API to retrieve/manipulate data in my Google Tag Manager configuration. The only problem I have now is that I can't download the binary file generated for each container version using that api (it is used by Android SDK). To be clear, I'm talking about the file which can be downloaded via:
https://tagmanager.google.com/api/accounts/[accountId]/containers/[container_id]/versions/[version_id]/download
The base URL of the TagManager API is different to the one above (https://www.googleapis.com/tagmanager/v1/), so the GoogleCredential I've generated using my service account doesn't work for this download, as it is out of scope (TagManagerScopes to be specific).
I tried to find something in Google Developers Console to allow arbitrary url's like the one for the binary file, but I couldn't find anything. I might be approaching the OAuth part from a wrong angle altogether, this API is still very new to me.
Is it even possible to download this file programmatically? If yes, could you please explain how to achieve this?

How do you upload a file using an app created in Android Studio to Google Cloud Storage?

Would anyone please take the time to step-by-step document this seemingly simple task?
I am new to java and the latest Google Cloud Platform APIs. I cannot figure out how to do the simple task of uploading a file to Google Cloud Platform from an Android App. Most examples are three years old or are not end-to-end. Either way, they fail so mysteriously at some point that I cannot figure out how to proceed. For example, the exception I'm getting with using the simple-cloud-storage demo is "null." I can't even figure out what is generating "null."
So far I've only been successful in doing something by using the endpoints tutorial: https://cloud.google.com/appengine/docs/python/endpoints/getstarted/clients/android/ But there is no talk about exchanging files in that demo.
Complete code example is here. This code example was created from the Google HelloEndpoints tutorial. This is probably a terrible implementation of using GCS in Android, but it works unlike most examples currently available.
Steps to achieve this:
Create a GCS bucket with service account credentials.
Get a .p12 private key and place that into src/main/res/raw. You have to remove the .p12 extension and replace the - with a _. You
need the password, too, so keep that handy.
Look in MainActivity.java at public void onClickFileChooser(View view). What this does is call a class that allows you to
navigate and select a file. There's some commented-out code that
checks with the server for an upload URL in case you want to try to
store the file with the blobstore API. I could not figure that out,
so I tried GCS. The GCS stuff is the next bit of code. You'll notice
it's a two step process. There are some globals defined for GCS
because I'm not a good programmer.
The first step is getting a "Google credential." The code loads the private key with keystore.load(getResources().openRawResource(R.raw.thomasmhardy_ebc515c808a6)
and does some other stuff. You might have to change the key
password. Look for "notasecret" and replace that with your password.
The actual storage of the file is next. You'll see the URI is set per the Google example. Next, I set up an asynchronous
task because Android does not want you doing anything on the network
in the main thread. The task first refreshes the GoogleCredential.
Once's that's complete, it uses android-async-http to post the
file to GCS. Note, the header for Authorization concatenates "Bearer
" before the access token. That uploads the file.
All this requires a few dependencies. Check out the gradle.
I also had to enable multiDex.
Note: I removed the contents of my private key "thomasmhardy_ebc515c808a6."

Downloading from website with Request/Intent

I am making an app that will connect to a website and download an mp3 file.
Can you use intents along with a HttpUrlConnection/jsoup request (or is another way to accomplish this?) I am planning on using Jsoup to connect to this site, pass the url parameter, and somehow initiate the download (not sure how to acquire necessary url). I'm not sure how to implement this. I'd like to avoid using a webview to accomplish this, though that would be easy.
If you just want to download an mp3 file with a URL from the web, you could use the built-in download manager of android.
See #3 answer of this
It's easy to implement and works well.

Categories

Resources