質問

このアルバイトコード化方法メインの活動が決定いきます。

これが私のコー---openFileOutputとopenFileInputは定義されていません。う??かなサービスまたはアクティビティ---??

    package spexco.hus.system;

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Date;
    import spexco.hus.cepvizyon.CepVizyon;
    import android.content.Context;

    public class LicenseIDB {
    private String PHONECODEFILE = "CepVizyonCode";
    private static String PhoneCode = null;

    public LicenseIDB() {
    if (readLocal(PHONECODEFILE, 8) == null)
        createSystemCode();
}

public static long getDate() {
    Date currentTime = new Date();
    return currentTime.getTime();
}

public void createSystemCode() {
    long date = getDate();
    String str = Integer.toHexString(Integer.MAX_VALUE - (int) date);
    for (int i = str.length(); i < 8; i++) {
        str += "" + i;
    }
    PhoneCode = str.substring(0, 8);
    saveLocal(PhoneCode, PHONECODEFILE);

}

public static String getPhoneCode() {

    return PhoneCode;
}

public void saveLocal(String fileString, String Adress) {

    try {
        FileOutputStream fos = openFileOutput(Adress, Context.MODE_PRIVATE);
        fos.write(fileString.getBytes());
        fos.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public String readLocal(String Adress, int lenght) {
    byte[] buffer = new byte[lenght];
    String str = new String();
    try {
        FileInputStream fis = openFileInput(Adress);
        fis.read(buffer);
        fis.close();
        str = new String(buffer);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return str;
}

}

役に立ちましたか?

解決

それで定義されている方法に Context クラスな方法で定義されたクラスです。時にコードされた 活動, でも便利なメソッド openFileInput() その Activity 基底クラスへのアクセスの基礎 コンテキストgetApplicationContext().openFileInput() (同様に、 openFileOutput()).

今だけの交換の直接の電話で基本となる 文脈 ます。

他のヒント

タグに置き換え
FileOutputStream fos = openFileOutput(Adress, Context.MODE_PRIVATE);
線の下の

FileOutputStream fos = getApplicationContext().openFileOutput(filename, getActivity().MODE_PRIVATE);

断片の内部で使用される場合は、

FileOutputStream fos =getActivity().openFileOutput(filename, getActivity().MODE_PRIVATE);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top