Tim Meißner
- Forum-Beiträge: 238
21.11.2010, 15:26:26 via Website
21.11.2010 15:26:26 via Website
Moin!
Habe bei meiner App Meine App ein paar Probleme.
Theoretisch tut dieser Code hier unten was ich möchte. Praktisch funktioniert es nicht auf jedem Gerät. Der Emulator klappt im Moment auch nicht. Vorhin hats aber funktioniert??^^
Manchmal wird einfach nur eine 0KB große Datei erzeugt (die echte ist 21KB groß).
Hat jemand eine Idee?
Wäre euch sehr verbunden wenn ihr mir helfen könntet
Habe bei meiner App Meine App ein paar Probleme.
Theoretisch tut dieser Code hier unten was ich möchte. Praktisch funktioniert es nicht auf jedem Gerät. Der Emulator klappt im Moment auch nicht. Vorhin hats aber funktioniert??^^
Manchmal wird einfach nur eine 0KB große Datei erzeugt (die echte ist 21KB groß).
Hat jemand eine Idee?
Wäre euch sehr verbunden wenn ihr mir helfen könntet
1public static final String MY_STORAGE = Environment
2 .getExternalStorageDirectory().toString() + "/AllgemeinWissen/databases/"; // +
3 // filename
4 public static final String DATA_FILE = "fragen.sqlite";
5 public static final String MY_INTERNAL_STORAGE = "/data/data/de.tm.android.allgemeinwissen/";
6 public static final String WEB_LINK = "http://universe-gamingcentral.com/fragen_release.sqlite";
7
8protected void downloadDatabase() {
9 Toast.makeText(getApplicationContext(), R.string.download_started,
10 Toast.LENGTH_SHORT).show();
11 byte[] buffer = downloadFile(WEB_LINK);
12 try {
13 File file = new File(MY_STORAGE);
14 if (!file.exists())
15 file.mkdirs();
16 file = new File(MY_STORAGE + DATA_FILE);
17 if(file.exists())
18 {
19 file.delete();
20 file = new File(MY_STORAGE + DATA_FILE);
21 }
22 FileOutputStream fos = new FileOutputStream(file);
23 fos.write(buffer);
24 } catch (Exception e) {
25 Log.d("DownloadDatabase", e.toString());
26 e.printStackTrace();
27 Toast.makeText(getApplicationContext(), R.string.download_failed,
28 Toast.LENGTH_LONG).show();
29 return;
30 }
31 Toast.makeText(getApplicationContext(), R.string.download_completed,
32 Toast.LENGTH_SHORT).show();
33 }
34
35 private byte[] downloadFile(String urlString) {
36 BufferedInputStream bis = null;
37
38 try {
39 URL url = new URL(urlString);
40 URLConnection conn = url.openConnection();
41 bis = new BufferedInputStream(conn.getInputStream());
42 } catch (Exception e) {
43 Toast.makeText(getApplicationContext(), R.string.download_failed,
44 Toast.LENGTH_LONG).show();
45 e.printStackTrace();
46 }
47 ByteArrayBuffer baf = new ByteArrayBuffer(50);
48
49 int c;
50 try {
51 while ((c = bis.read()) != -1) {
52 baf.append(c);
53 }
54 } catch (Exception e) {
55 }
56
57 byte[] buffer = baf.toByteArray();
58
59 return buffer;
60
61 }
2 .getExternalStorageDirectory().toString() + "/AllgemeinWissen/databases/"; // +
3 // filename
4 public static final String DATA_FILE = "fragen.sqlite";
5 public static final String MY_INTERNAL_STORAGE = "/data/data/de.tm.android.allgemeinwissen/";
6 public static final String WEB_LINK = "http://universe-gamingcentral.com/fragen_release.sqlite";
7
8protected void downloadDatabase() {
9 Toast.makeText(getApplicationContext(), R.string.download_started,
10 Toast.LENGTH_SHORT).show();
11 byte[] buffer = downloadFile(WEB_LINK);
12 try {
13 File file = new File(MY_STORAGE);
14 if (!file.exists())
15 file.mkdirs();
16 file = new File(MY_STORAGE + DATA_FILE);
17 if(file.exists())
18 {
19 file.delete();
20 file = new File(MY_STORAGE + DATA_FILE);
21 }
22 FileOutputStream fos = new FileOutputStream(file);
23 fos.write(buffer);
24 } catch (Exception e) {
25 Log.d("DownloadDatabase", e.toString());
26 e.printStackTrace();
27 Toast.makeText(getApplicationContext(), R.string.download_failed,
28 Toast.LENGTH_LONG).show();
29 return;
30 }
31 Toast.makeText(getApplicationContext(), R.string.download_completed,
32 Toast.LENGTH_SHORT).show();
33 }
34
35 private byte[] downloadFile(String urlString) {
36 BufferedInputStream bis = null;
37
38 try {
39 URL url = new URL(urlString);
40 URLConnection conn = url.openConnection();
41 bis = new BufferedInputStream(conn.getInputStream());
42 } catch (Exception e) {
43 Toast.makeText(getApplicationContext(), R.string.download_failed,
44 Toast.LENGTH_LONG).show();
45 e.printStackTrace();
46 }
47 ByteArrayBuffer baf = new ByteArrayBuffer(50);
48
49 int c;
50 try {
51 while ((c = bis.read()) != -1) {
52 baf.append(c);
53 }
54 } catch (Exception e) {
55 }
56
57 byte[] buffer = baf.toByteArray();
58
59 return buffer;
60
61 }
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.