-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
executable file
·64 lines (54 loc) · 1.84 KB
/
MainActivity.java
File metadata and controls
executable file
·64 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package net.learn2develop.lbsreceiver_datalogging;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
public void CopyDB(InputStream inputStream,
OutputStream outputStream) throws IOException {
//---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String destDir = "/data/data/" + getPackageName() +
"/databases/";
String destPath = destDir + "MyDB";
File f = new File(destPath);
if (!f.exists()) {
//---make sure directory exists---
File directory = new File(destDir);
directory.mkdirs();
//---copy the db from the assets folder into
// the databases folder---
try {
CopyDB(getBaseContext().getAssets().open("mydb"),
new FileOutputStream(destPath));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void onStart(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
public void onStop(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
}