Reputation: 73
I tried below code to start downloading an mp3 file in android, it was right until this morning, now it throws this exeption android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= http://snd.tebyan.net/1388/03/Baz Amadam55055.mp3 }
both in emulator and real device, I did not change the code, what happened? what is wrong?
String url = " http://snd.tebyan.net/1388/03/Baz Amadam55055.mp3";
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Upvotes: 2
Views: 2229
Reputation: 5108
As Hariharan and Artoo pointed out, there are several bugs in the piece of code
There is a space in string url
. Change it to
String url = "http://snd.tebyan.net/1388/03/Baz Amadam55055.mp3";
.
Moreover, you can't pass a String
to start an intent. Convert it to a Uri
object and then pass it to the Intent
constructor. That is probably the line you accidentally deleted. Add the line Uri uri = Uri.parse(url)
to your code. The final solution is something like:
String url = "http://snd.tebyan.net/1388/03/Baz Amadam55055.mp3";
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
One last point is that the particular Url requires your emulator/device to contain an SD card. Go through your emulator's details and check if SD card is ticked and has a reasonable size in MB.
Upvotes: 3
Reputation: 38098
String url = " http://snd.tebyan.net/1388/03/Baz Amadam55055.mp3";
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
Here you're using two different names: uri != url...
And, as Hariharan said, there's an extra space in the uri (here called "url") definition.
Upvotes: 1
Reputation: 24853
Try removing the space before http
in your string:
String url = "http://snd.tebyan.net/1388/03/Baz Amadam55055.mp3";
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Upvotes: 3