Downloading from website with Request/Intent - java

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.

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.

Reading network traffic from the browser using Java code

Folks,
I was looking for Java capability of reading thru the network tab.
I had a task of hitting a URL in the browser, reading and validate some tags which are fired on page load.
I Know to fetch the View Source Data of the page, but not sure on getting network tab data.
example:
Opening a URL in chrome browser and watching Network tab in the developer tool, i see bunch of Get requests(tags,js etc) getting fired & need to capture this data.
I wanted to know which is the best way to achieve this and great if any code snippet is available.
Cheers
You can use HttpClient to work on api testing. There are many tutorials to work on api testing using Java. For starter you can read about Apache Http client.

Android: Downloading flickr images

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.

Updating a Server Side Text File via Android

I'm building an app that needs to periodically append lines to a server side text file. So far, the best way I've come up with for doing this is using the Dropbox API, where the user has to download the text file, update it, and then upload it back - obviously this is not ideal. What would be the best (free) way to do something like this? I'd like a solution where I don't have to personally host a server, but can use some third party cloud (like Dropbox).
Google's Android Backup Service seems appropriate for this, and is free.

How can I stream video to a browser using Java/Spring?

We a have jboss server running and have a basic web setup using Spring but now I would like to stream video into the browser. I am trying to use xuggle but then I read on their website that you can't put it into an Applet or use it with java webstart, so I'm assuming that means I can stream to a browser, is this assumption correct? If so does anyone else know any libraries or how I should go about doing this? If you need any more info or have questions I'll be happy to answer although I'm very new to streaming video and relatively knew to Spring.
UPDATE: So I'm able to generate a video using xuggle, and then I can embed that video in my html code... but I can't generate and stream at the same time. Does anyone have any ideas how to make xuggle push date out to my tomcat server?
You may want to look at Red5 media server.
Since you are doing jsp, just have your code write out the HTML 5 video element. That will provide basic video functionality. This will work in all HTML 5 compliant browsers as well as all mobile devices.

Categories

Resources