설.현.아빠
데이터 다운로드는 내게! - DownloadManager 사용하기(Error 발생) 본문
흠...퍼미션 에런데....퍼미션 설정해줘도 안되네..ㅠㅠ <?xml version="1.0" encoding="utf-8"?> </application> <permission android:name="android.permission.INTERNET"></permission> </manifest> <?xml version="1.0" encoding="utf-8"?> <Button <Button <Button package lee.ex; import java.util.List; import android.app.Activity; public class ex extends Activity implements OnClickListener{ LogCat 01-19 04:09:33.738: ERROR/AndroidRuntime(549): FATAL EXCEPTION: main
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lee.ex"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ex"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-sdk android:minSdkVersion="9" />
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></permission>
<permission android:name="android.permission.ACCESS_ALL_DOWNLOADS"></permission>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Enter URL"
android:id="@+id/MaindownloadUrl"
android:inputType="textUri" />
android:id="@+id/MainaddQueueButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add to download queue" />
android:id="@+id/MaincancelDownloadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel latest download" />
android:id="@+id/MainviewDownloadsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View downloads" />
</LinearLayout>
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
private EditText downloadUrl;
private Button addToQueueButton;
private Button cancelLatestButton;
private Button viewDownloadsButton;
private long latestId = -1;
private DownloadManager downloadmanager;
private DownloadManager.Request request;
private Uri urlTodownload;
private BroadcastReceiver completeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"다운로드가 완료되었습니다.", Toast.LENGTH_SHORT).show();
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
downloadUrl = (EditText)findViewById(R.id.MaindownloadUrl);
addToQueueButton = (Button)findViewById(R.id.MainaddQueueButton);
cancelLatestButton = (Button)findViewById(R.id.MaincancelDownloadButton);
viewDownloadsButton = (Button)findViewById(R.id.MainviewDownloadsButton);
downloadmanager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
addToQueueButton.setOnClickListener(this);
cancelLatestButton.setOnClickListener(this);
viewDownloadsButton.setOnClickListener(this);
}
@Override
public void onResume() {
super.onResume();
IntentFilter completeFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(completeReceiver, completeFilter);
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(completeReceiver);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.MainaddQueueButton:
urlTodownload = Uri.parse(downloadUrl.getText().toString());
List<String> pathSegments = urlTodownload.getPathSegments();
request = new DownloadManager.Request(urlTodownload);
request.setTitle("다운로드예제");
request.setDescription("항목 설명");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, pathSegments.get(pathSegments.size()-1));
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
latestId = downloadmanager.enqueue(request);
downloadUrl.setText("");
break;
case R.id.MaincancelDownloadButton:
downloadmanager.remove(latestId);
break;
case R.id.MainviewDownloadsButton:
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
break;
}
}
}
01-19 04:09:33.738: ERROR/AndroidRuntime(549): java.lang.SecurityException: Permission Denial: opening provider com.android.providers.downloads.DownloadProvider from ProcessRecord{406b2040 549:lee.ex/10041} (pid=549, uid=10041) requires android.permission.ACCESS_ALL_DOWNLOADS or android.permission.ACCESS_ALL_DOWNLOADS
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.os.Parcel.readException(Parcel.java:1322)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.os.Parcel.readException(Parcel.java:1276)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:1882)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.app.ActivityThread.getProvider(ActivityThread.java:3311)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.app.ActivityThread.acquireProvider(ActivityThread.java:3336)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1634)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.content.ContentResolver.acquireProvider(ContentResolver.java:748)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.content.ContentResolver.insert(ContentResolver.java:598)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.app.DownloadManager.enqueue(DownloadManager.java:750)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at lee.ex.ex.onClick(ex.java:76)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.view.View.performClick(View.java:2485)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.view.View$PerformClick.run(View.java:9080)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.os.Handler.handleCallback(Handler.java:587)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.os.Handler.dispatchMessage(Handler.java:92)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.os.Looper.loop(Looper.java:123)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at java.lang.reflect.Method.invoke(Method.java:507)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-19 04:09:33.738: ERROR/AndroidRuntime(549): at dalvik.system.NativeStart.main(Native Method)
'안드로이드 > DownloadManager' 카테고리의 다른 글
데이터 다운로드는 내게! - DownloadManager 사용하기 (0) | 2011.02.11 |
---|