Trying to use the following Code to download a remote hosted .apk file.
package com.wireless.wmaa;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
public class UpdateApp extends AsyncTask<String,Void,Void>{
private Context context;
public void setContext(Context contextf){
context = contextf;
}
#Override
protected Void doInBackground(String... arg0) {
try {
URL url = new URL(arg0[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = "/sdcard/Download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "Wireless.apk");
if(outputFile.exists()){
outputFile.delete();
}
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/sdcard/Download/Wireless.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
context.startActivity(intent);
} catch (Exception e) {
Log.e("UpdateAPP", "Update error! " + e.getMessage());
}
return null;
}}
And Here is the Code to start the Task:
UpdateApp myApp = new UpdateApp();
myApp.setContext(getApplicationContext());
myApp.execute("http://some.domain.com/someSite/some.apk");
Able to connect but when trying to use the InputStream throws a file not found exception. I can browse to the file from the Android Default Browser and I am prompted to download the file which is the same functionality I would like in my App. Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wireless.wmaa"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:label="#string/app_name"
android:name=".SelectServer"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>"
</activity>
<activity
android:name=".UpdateApp"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
</intent-filter>
</activity>
<activity
android:name=".WirelessActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
You are wrong at this line File outputFile = new File(file, "Wireless.apk");
just changed it as follows,
File outputFile = new File( PATH + "Wireless.apk");
also change following code
if(outputFile.exists())
{
outputFile.delete();
}
else // Add Else part, it is missing in your code
{
outputFile.createNewFile();
}
Don't use /sdcard/Downloads...this path is different in some devices.
You should use:
File file = Environment.getExternalStorageDirectory();
Ended up being an Issue with IIS. Once I moved my .apk to my apache webserver had no issues...
Related
I've browse two dozens samples, articles and so on trying to see why my code won't work. I have a very simple broadcast listener I'm trying to call with an alarm manager. Here's my code:
Main Activity onCreate and function (MapsActivity.java)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
// Create the LocationRequest object
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(240 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(80 * 1000); // 1 second, in milliseconds
Button clickButton = (Button) findViewById(R.id.search_for_beer);
clickButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent bar = new Intent(MapsActivity.this, SearchBeer.class);
bar.putExtra("tloc", Double.toString(location.getLongitude()) + "," + Double.toString(location.getLatitude()));
startActivity(bar);
}
});
startNotes();
}
public void startNotes() {
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(MapsActivity.this, BeerNotes.class);
PendingIntent pintent = PendingIntent.getService(MapsActivity.this, 12345, intent, 0);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + (5 * 1000), 5 * 1000, pintent);
}
My BroadcastReceiver ... I've commented out code I'm going to want to do and just trying to get a log right now and I'm getting nothing.
package com.tapmap.app.tapmapapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.io.InputStream;
import java.net.HttpURLConnection;
public class BeerNotes extends BroadcastReceiver {
private Exception exception;
private HttpURLConnection urlConnection;
public InputStream in;
private String total;
private static final long REPEAT_TIME = 1000 * 30;
private static final String APP_TAG = "LOG: ";
private static final int EXEC_INTERVAL = 20 * 1000;
#Override
public void onReceive(Context context, Intent intent) {
Log.i(APP_TAG, "onReceive() called");
/*
try {
URL url = new URL("http://fltapmap.com/notes.php");
try {
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
in = new BufferedInputStream(urlConnection.getInputStream());
try {
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String line;
total = "";
while ((line = r.readLine()) != null) {
total += line + "\n";
}
urlConnection.disconnect();
Log.i("TOTAL NOTES", total);
} catch(IOException ioe) {
Log.i("MALFORMED1", ioe.getMessage());
urlConnection.disconnect();
}
} catch (IOException ioe) {
Log.i("MALFORMED2", ioe.getMessage());
urlConnection.disconnect();
}
} catch (MalformedURLException ioex) {
Log.i("MALFORMED3", ioex.getMessage());
}
*/
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tapmap.app.tapmapapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.javapapers.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.javapapers.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.google.android.gms.version"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAksheZLMAALUfLHKWOsfTFCz7iP_KwpCE" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BarBrewry"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_bar_brewry"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name=".SearchBeer"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_search_beer"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name=".ViewBeer"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_search_beer"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider934301593259187"
android:exported="true" />
<receiver
android:name="com.tapmap.app.tapmapapp.BeerNotes"></receiver>
</application>
</manifest>
Change PendingIntent.getService() to PendingIntent.getBroadcast()
EDIT
I notice the commented code in your BroadcastReceiver will try to make a network request. This will cause your app to crash with a NetworkOnMainThread exception. I recommend you create a class that extends IntentService and do your network operations inside of onHandleIntent() instead. In that case, you can use PendingIntent.getService() to have the intent go to the service.
I am develoing small android application in eclipse. In that project i kill the running process in android, i got the Permission Denial error. how can i solve this problem in android.
Anybody help for this problem....
THIS IS MY CODE
package com.example.nuts;
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.Toast;
import android.*;
public class killprocess extends Activity
{
SmsManager smsManager = SmsManager.getDefault();
Recivesms rms=new Recivesms();
String Number="";
int pid=0;
String appname="";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
Number=Recivesms.senderNum;
pid=Integer.parseInt(Recivesms.struid);
appname=getAppName(pid);
Toast.makeText(getBaseContext(),"App Name is "+appname, Toast.LENGTH_LONG).show();
ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = am.getRunningAppProcesses();
if (processes != null){
for (int i=0; i<processes.size(); i++){
RunningAppProcessInfo temp = processes.get(i);
String pName = temp.processName;
if (pName.equals(appname))
{
Toast.makeText(getBaseContext(),"App Name is matched "+appname+" "+pName, Toast.LENGTH_LONG).show();
int pid1 = android.os.Process.getUidForName(pName);
//android.os.Process.killProcess(pid1);
am.killBackgroundProcesses(pName);
Toast.makeText(getBaseContext(), "Killed successfully....", Toast.LENGTH_LONG).show();
}
}
}
smsManager.sendTextMessage(Number, null,"Your process Successfully killed..." , null,null);
}catch(Exception e)
{
Toast.makeText(getBaseContext(),e.getMessage(), Toast.LENGTH_LONG).show();
}
}
private String getAppName(int Pid)
{
String processName = "";
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext())
{
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try
{
if(info.pid == Pid)
{
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
//Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ info.processName +" Label: "+c.toString());
//processName = c.toString();
processName = info.processName;
}
}
catch(Exception e)
{
//Log.d("Process", "Error>> :"+ e.toString());
}
}
return processName;
}
}
After executing the code. i got the following error...
Permission Denial:
killBackgroundProcess() from pid=894,
uid=10052 requires
android.permission.KILL_BACKGROUND_PROCESSES
Also i put the following line on manifest file
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESS" />
Anybody help for how to solve this problem...
Thanking you....
This is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nuts"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESS" ></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/clip1"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.nuts.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.nuts.createpassword"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.nuts.editpassword"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.nuts.processList"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.nuts.killprocess"
android:label="#string/app_name"
>
</activity>
<receiver android:name=".Recivesms">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity
android:name="com.example.nuts.sensSms"
android:label="#string/app_name" >
</activity>
</application>
add permission in your manifest file
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"></uses-permission>
</manifest>
Goto your manifest file and add this
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
You need to add the relevant permission in your AndroidManifest.xml
From the official documentation :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.app.myapp" >
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
...
</manifest>
Add this permission to your manifest file to kill backgroud process
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
Note: If you are getting all the running application on your android then you can kill only manually installed application like subway surfer but you can't kill inbuilt android application like launcher of android.
please take me out this problem ,I am trying to get file from Ftp server .
here is my code which i am continuously getting exception like
java.net.unknownHostException :ftpbrasnet.no-ip.org.
i have tried in browser its working.
FTPClient client = new FTPClient();
FileOutputStream Foutput = null;
try {
client.connect("ftp://ftpbrasnet.no-ip.org/"); // My Exceptionis here
client.login("win7", "123");
// Create an OutputStream for the file
String filename = "files.txt";
Foutput = new FileOutputStream(filename);
// Fetch file from server
client.retrieveFile("/" + filename, Foutput);
}
catch (IOException e)
{
Log.e("ERROR", e.getStackTrace().toString());
}
finally
{
try
{
if (Foutput != null) {
Foutput.close();
}
client.disconnect();
} catch (IOException e) {
Log.e("ERROR", e.getStackTrace().toString());
}
}
}
and here is my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Net.estoque"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="#string/app_name" >
<activity android:name="Netestoque"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
Have you tried removing the protocol from the URL, like so:
client.connect("ftpbrasnet.no-ip.org/");
I am attempting to do a download in an asychronous task in android. Unfortunately I am getting an "unknownHost' error. To me it looks like I have the proper permissions but I am still getting this error. Below is my permissions, my error, and the function. Any thoughts on what I am doing wrong?
Thank you very much.
Craig
11-27 21:51:34.545: D/ImageManager(9381): Error: java.net.UnknownHostException:
public void downloadFromUrl(String strUrl, String fileName) { // this is the downloader
// method
try {
File parentDirectory= new File(PATH);
if (!parentDirectory.exists()) {
System.err
.println("It seems like parent directory does not exist...");
if (!parentDirectory.mkdirs()) {
System.err.println("And we cannot create it...");
// we have to return, throw or something else
}
}
URL url = new URL(strUrl);
File file = new File(PATH + fileName);
if (!file.exists()) {
file.createNewFile();
}
long startTime = System.currentTimeMillis();
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
Log.d("ImageManager",
"download ready in"
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " sec");
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.craig.musicapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
. <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<application
android:icon="#drawable/jerrygarciahand"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SearchMusic"
android:label="#string/search_music"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ConcertDetailActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ItemListActivity" />
</activity>
<activity
android:name=".AppInfo"
android:label="#string/title_item_list" >
</activity>
</application>
</manifest>
use this permission..in your android manifest file
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
So I am a dumb dumb and I figured it out. Amazing what a night of sleep can do.
My url had "///" instead of "//". Obviously this was causing an issue with the download. Thank you for all your help and hopefully I won't get so sleep deprived next time and make such a silly error :).
This function is used to save image on sdcard (I have tested it on the emulator only):
public String SaveImage(String URL,String imagename){
Bitmap bitmap = null;
InputStream in = null;
String path = Environment.getExternalStorageDirectory().toString();
File dir = new File(path + "/bh");
if(!dir.exists())
new File(path + "/bh").mkdir();
Log.i("in save()", "after file");
File mImageFile = new File(path+"/bh/"+imagename);
if(mImageFile.exists())
Toast.makeText(mContext, "Saved", Toast.LENGTH_LONG).show();
try{
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
FileOutputStream out = new FileOutputStream(mImageFile);
bitmap.compress(CompressFormat.JPEG, 100,out);
out.flush();
out.close();
in.close();
return imagename+".jpg";
}catch(IOException ex){
Log.e("==== Error in saving image ====",ex.getMessage());
return "";
}
}
I have added the required permissions like below :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mobile.bh"
android:versionCode="4"
android:versionName="1.0.3" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="mobile.bh.activities.BHActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="mobile.bh.activities.RecipesListActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="mobile.bh.activities.RecipeInfoActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="mobile.bh.activities.IngredientsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="mobile.bh.activities.MethodActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="mobile.bh.activities.SpicesListActivity"
android:screenOrientation="portrait" >
</activity>
<activity android:name=".activities.SpicesCategoriesActivity" >
</activity>
<activity android:name=".activities.CategoryActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You also need to use the Internet permission since you're connecting to the internet.
<uses-permission android:name="android.permission.INTERNET" />
Does your emulator support SDCard ?
Have a look at this great answer, it might be the issue https://stackoverflow.com/a/11468278/1635817