android - Unable to use openFileInput in a BroadcastReceiver -


im new coding , im trying learn on own have run problem in app developing of being unable use openfileinput in broadcast reciever. here code:

public class alarmreceiver extends broadcastreceiver {

@override public void onreceive(context context, intent intent) {    } 

//end of read froms

dateformat format = dateformat.getdateinstance();  textview text; button btn;  dateformat formate = dateformat.gettimeinstance(); calendar calender2 = calendar.getinstance(); textview txt2; button btn2; 

//read froms start

private string readfromfilename() {      string ret = "";      try {         inputstream inputstream = openfileinput("config.txt");          if (inputstream != null) {             inputstreamreader inputstreamreader = new inputstreamreader(inputstream);             bufferedreader bufferedreader = new bufferedreader(inputstreamreader);             string receivestring = "";             stringbuilder stringbuilder = new stringbuilder();              while ((receivestring = bufferedreader.readline()) != null) {                 stringbuilder.append(receivestring);             }              inputstream.close();             ret = stringbuilder.tostring();         }     } catch (filenotfoundexception e) {         log.e("login activity", "file not found: " + e.tostring());     } catch (ioexception e) {         log.e("login activity", "can not read file: " + e.tostring());     }      return ret; } 

if can appreciate tips or work arounds. exact error gives cannot resolve method. when tried research on own mentioned context couldnt find example of in code.

openfileinput() method on context. notice second parameter onreceive() context. hence, can call openfileinput() on context object.

that being said, please note onreceive() called on main application thread, , doing disk i/o on main application thread not idea.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -