2011-04-25 25 views

回答

1

的PhoneGap PhoneGap的使用API​​來創建數據庫都有自己的support Google Group,這是你的地方應該首先考慮PhoneGap的問題。這是關於此主題的recent post over there

Upshot:現在,除非通過修改託管的Android應用程序(DroidGap.java),否則無法執行此操作。

1
public class MainActivity extends DroidGap { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     try 
     { 
      String pName = this.getClass().getPackage().getName(); 
      this.copy("Databases.db","/data/data/"+pName+"/databases/"); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 

     super.loadUrl("file:///android_asset/www/index.html"); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 


    void copy(String file, String folder) throws IOException { 
     File CheckDirectory; 
     CheckDirectory = new File(folder); 
     if (!CheckDirectory.exists()) 
     { 
      CheckDirectory.mkdir(); 
     } 

     InputStream in = getApplicationContext().getAssets().open(file); 
     OutputStream out = new FileOutputStream(folder+file); 

     // Transfer bytes from in to out 
     byte[] buf = new byte[1024]; 
     int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len); 
     in.close(); out.close(); 

    } 
} 
相關問題