1
2
package com.ondaysteve.administrator.myapplication;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class MyReceiver extends BroadcastReceiver {
public static final String ROOT_DIR = "/data/data/com.ondaysteve.administrator.myapplication/databases/";
public SQLiteDatabase db;
public Cursor cursor;
ProductDBHelper mHelper;
@Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, MyService.class);
context.startService(startServiceIntent);
setDB(this); //여기
mHelper = new ProductDBHelper(this); //여기
db = mHelper.getWritableDatabase();
cursor = db.rawQuery("SELECT * FROM tb_onedaysteve", null);
startManagingCursor(cursor); //여기
}
public static void setDB(Context ctx) {
File folder = new File(ROOT_DIR);
if(folder.exists()) {
} else {
folder.mkdirs();
}
AssetManager assetManager = ctx.getResources().getAssets();
File outfile = new File(ROOT_DIR+"onedaysteve5.sqlite");
InputStream is = null;
FileOutputStream fo = null;
long filesize = 0;
try {
is = assetManager.open("onedaysteve5.sqlite", AssetManager.ACCESS_BUFFER);
filesize = is.available();
if (outfile.length() <= 0) {
byte[] tempdata = new byte[(int) filesize];
is.read(tempdata);
is.close();
outfile.createNewFile();
fo = new FileOutputStream(outfile);
fo.write(tempdata);
fo.close();
} else {}
} catch (IOException e) {}
}
public class ProductDBHelper extends SQLiteOpenHelper { //새로 생성한 adapter 속성은 SQLiteOpenHelper이다.
public ProductDBHelper(Context context) {
super(context, "onedaysteve5.sqlite", null, 1); // db명과 버전만 정의 한다.
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
}


메인엑티비티에서는 오류안뜨는데 리시버에서는 오류나네요 제가 이것저것해봤는데 this대신에 다른거 써야될거같은데 뭘써야되는지 모르겠고 startmanagingcursor은 무슨역활을하는건지 여기서 삭제해도되는건지 궁금합니다.
1.this는 뭘 뜻하며 어떻게 오류 해결해야되는지?
2.startmanagingcursor 는 뭘 하는애며 삭제해도 되는지?