Android错误日志文件:权限被拒绝

时间:2011-12-13 09:22:10

标签: android

我在android中创建一个应用程序。在第一个活动中,它显示视频列表并在youtube上...

但是,当我点击该列表并控制转移到下一个活动时,我正在将该视频的URL转移到下一个活动。每件事情都正常但视频没有显示......我正在使用视频视图控件。但是当我看到LogCat文件时,会向我显示以下错误...

我已将互联网许可写入我的清单文件

 <uses-permission android:name="android.permission.INTERNET" />

但仍然有错误。(应用程序不显示错误)

logcat的:

12-09 21:13:10.905: V/VideoViewDemo(2559): path: http://www.youtube.com/watch?v=i5Fsnv6wHJo
12-09 21:13:12.865: E/VideoViewDemo(2559): error: Permission denied
12-09 21:13:12.865: E/VideoViewDemo(2559): java.io.IOException: Permission denied
12-09 21:13:12.865: E/VideoViewDemo(2559):  at java.io.File.createNewFileImpl(Native Method)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at java.io.File.createNewFile(File.java:1257)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at java.io.File.createTempFile(File.java:1322)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at java.io.File.createTempFile(File.java:1278)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.pxr.tutorial.xmltest.Watch_Video.getDataSource(Watch_Video.java:180)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.pxr.tutorial.xmltest.Watch_Video.playVideo(Watch_Video.java:157)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.pxr.tutorial.xmltest.Watch_Video.access$0(Watch_Video.java:141)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.pxr.tutorial.xmltest.Watch_Video$5.run(Watch_Video.java:135)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.Activity.runOnUiThread(Activity.java:3717)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.pxr.tutorial.xmltest.Watch_Video.onCreate(Watch_Video.java:133)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.os.Looper.loop(Looper.java:123)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at java.lang.reflect.Method.invokeNative(Native Method)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at java.lang.reflect.Method.invoke(Method.java:507)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-09 21:13:12.865: E/VideoViewDemo(2559):  at dalvik.system.NativeStart.main(Native Method)

主文件代码:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listplaceholder);

    String str=getIntent().getExtras().getString("Category").toString();

    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();


    String xml = XMLfunctions.getXML(str);
    Document doc = XMLfunctions.XMLfromString(xml);

    int numResults = XMLfunctions.numResults(doc);

    if((numResults <= 0)){
        Toast.makeText(CategoryDetail.this, "Geen resultaten gevonden", Toast.LENGTH_LONG).show();  
        finish();
    }

    NodeList nodes = doc.getElementsByTagName("video1");

    for (int i = 0; i < nodes.getLength(); i++) {                           
        HashMap<String, String> map = new HashMap<String, String>();    

        Element e = (Element)nodes.item(i);
        map.put("iVid", XMLfunctions.getValue(e, "iVid"));
        map.put("vVName", XMLfunctions.getValue(e, "vVName"));
        map.put("vSource", XMLfunctions.getValue(e, "vSource"));

        mylist.add(map);            
    }       

    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.category_detail, 
                    new String[] { "vVName" }, 
                    new int[] { R.id.item_title });



    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
            //Toast.makeText(CategoryDetail.this, "Video '" + o.get("vVName") + "' is just clicked.", Toast.LENGTH_LONG).show();

            Intent intent=new Intent(CategoryDetail.this, Watch_Video.class);

            intent.putExtra("url", o.get("vSource"));
            startActivity(intent);
            //Toast.makeText(CategoryDetail.this,"This is Url" + o.get("vSource"), Toast.LENGTH_LONG).show();

            //Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=nLJYkat4HpE"));
            //startActivity(intent);


        }       

    });
    }

第二个活动文件:

    mVideoView = (VideoView) findViewById(R.id.surface_view);

    mPath=getIntent().getExtras().getString("url");
    //mPath = (EditText) findViewById(R.id.path);
    //mPath.setText("http://daily3gp.com/vids/747.3gp");
    Toast.makeText(Watch_Video.this,"This is Url" + mPath.toString(), Toast.LENGTH_LONG).show();

    mPlay = (ImageButton) findViewById(R.id.play);
    mPause = (ImageButton) findViewById(R.id.pause);
    mReset = (ImageButton) findViewById(R.id.reset);
    mStop = (ImageButton) findViewById(R.id.stop);

    mPlay.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            playVideo();
        }
    });
    mPause.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                mVideoView.pause();
            }
        }
    });
    mReset.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                mVideoView.seekTo(0);
            }
        }
    });
    mStop.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                current = null;
                mVideoView.stopPlayback();
            }
        }
    });
    runOnUiThread(new Runnable(){
        public void run() {
            playVideo();

        }});

}

private void playVideo() {
    try {
        final String path = mPath.toString();
        Log.v(TAG, "path: " + path);
        if (path == null || path.length() == 0) {
            Toast.makeText(Watch_Video.this, "File URL/path is empty",
                    Toast.LENGTH_LONG).show();

        } else {
            // If the path has not changed, just start the media player
            if (path.equals(current) && mVideoView != null) {
                mVideoView.start();
                mVideoView.requestFocus();
                return;
            }
            current = path;
            mVideoView.setVideoPath(getDataSource(path));
            mVideoView.start();
            mVideoView.requestFocus();

        }
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
        if (mVideoView != null) {
            mVideoView.stopPlayback();
        }
    }
}

private String getDataSource(String path) throws IOException {
    if (!URLUtil.isNetworkUrl(path)) {
        return path;
    } else {
        URL url = new URL(path);
        URLConnection cn = url.openConnection();
        cn.connect();
        InputStream stream = cn.getInputStream();
        if (stream == null)
            throw new RuntimeException("stream is null");
        File temp = File.createTempFile("mediaplayertmp", "dat");
        temp.deleteOnExit();
        String tempPath = temp.getAbsolutePath();
        FileOutputStream out = new FileOutputStream(temp);
        byte buf[] = new byte[128];
        do {
            int numread = stream.read(buf);
            if (numread <= 0)
                break;
            out.write(buf, 0, numread);
        } while (true);
        try {
            stream.close();
        } catch (IOException ex) {
            Log.e(TAG, "error: " + ex.getMessage(), ex);
        }
        return tempPath;
    }

1 个答案:

答案 0 :(得分:7)

尝试将以下权限添加到清单文件中:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />