2012-07-13 29 views
0

我想打开文件在数据库中使用默认的安卓程序...但我有麻烦打开它... 我存储文件路径在我的数据库(作为字符串),因为它是更好的存储文件路径,而不是自己的文件...(从我读的) ,但是当我想在android中使用默认的android程序打开它时,它什么也不做......只是空白... 我不知道哪部分我错了,因为日志的猫没有表现出什么... 这里是我的代码...打开的文件,其中存储在数据库中使用默认的安卓程序

String fileId = ((TextView)view.findViewById(R.id.fileid)).getText().toString(); 
String fileName = ((TextView)view.findViewById(R.id.TextView01)).getText().toString(); 
String filePath = ((TextView)view.findViewById(R.id.filepath)).getText().toString(); 

//starting activity intent 
Intent intent= new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 

File file = new File("http://10.0.2.2/" + filePath); 

MimeTypeMap mime = MimeTypeMap.getSingleton(); 
String ext = file.getName().substring(file.getName().indexOf(".")+1).toLowerCase(); 
String type = mime.getMimeTypeFromExtension(ext); 

intent.setDataAndType(Uri.fromFile(file), type); 

try 
{ 
    startActivity(intent); 
} 
catch (ActivityNotFoundException e) 
{ 
    Toast.makeText(FileChooser.this, "No Application available to View this file", Toast.LENGTH_SHORT).show(); 
} 

的文件路径就是Android/untitled.jpg 其实我真的很新的开发Android ...我希望任何人都可以帮助我解决我的问题...

回答

0

我明白了... 终于我完成了我自己的... 如果其中之一你们混淆关于与我同样的事情......希望这将有助于...

public void clearCache() 
    { 
     fileCache.clear(); 
    } 

    private File getFileFromUrl(String url) 
    { 
     File f = fileCache.getFile(url); 
     try 
     { 
      URL docUrl = new URL(url); 
      HttpURLConnection conn = (HttpURLConnection)docUrl.openConnection(); 
      conn.setConnectTimeout(30000); 
      conn.setReadTimeout(30000); 
      conn.setInstanceFollowRedirects(true); 
      InputStream is=conn.getInputStream(); 
      OutputStream os = new FileOutputStream(f); 
      Utils.CopyStream(is, os); 
      os.close(); 
      return f; 
     } 
     catch (Exception ex) 
     { 
      ex.printStackTrace(); 
      return null; 
     } 
    } 

    public String GetExtention(String name) 
    { 
     name = name.replaceAll("%20", " "); 
     MimeTypeMap mime = MimeTypeMap.getSingleton(); 
     String type = name; 
     String filenameArray[] = type.split("\\."); 
     type = filenameArray[filenameArray.length-1]; 
     String ext = mime.getMimeTypeFromExtension(type.toLowerCase()); 
     return ext; 
    } 

而文件缓存类,你让... 更多的帮助this可以帮助你...

相关问题