###前提・実現したいこと
アンドロイドアプリ開発を初めて1週間の初心者です。
UUIDを用いて認証を行おうと思っております。
###発生している問題
とりあえず、Android Developers Blog にあるサンプルコードを動かしてみようと思いましたが、生成されるはずのINSTALLATIONという、UUIDが保存されるファイルも見当たりません。
何か認識が間違っているのでしょうか。どなたかご教授頂ければ幸いです。
###試したこと
サンプルコードのクラスに、getterを設定し、変数sIDの中を確認したところ、nullになっていました。
###該当のソースコード
java
1package jp.test; 2 3import android.content.Context; 4 5import java.io.File; 6import java.io.FileOutputStream; 7import java.io.IOException; 8import java.io.RandomAccessFile; 9import java.util.UUID; 10 11/** 12 * Created by hiromasa-s on 2017/05/28. 13 */ 14 15public class Installation { 16 public static String getsID() { 17 return sID; 18 } 19 20 public static String getINSTALLATION() { 21 return INSTALLATION; 22 } 23 24 private static String sID = null; 25 private static final String INSTALLATION = "INSTALLATION"; 26 27 public synchronized static String id(Context context) { 28 if (sID == null) { 29 File installation = new File(context.getFilesDir(), INSTALLATION); 30 try { 31 if (!installation.exists()) 32 writeInstallationFile(installation); 33 sID = readInstallationFile(installation); 34 } catch (Exception e) { 35 throw new RuntimeException(e); 36 } 37 } 38 return sID; 39 } 40 41 private static String readInstallationFile(File installation) throws IOException { 42 RandomAccessFile f = new RandomAccessFile(installation, "r"); 43 byte[] bytes = new byte[(int) f.length()]; 44 f.readFully(bytes); 45 f.close(); 46 return new String(bytes); 47 } 48 49 private static void writeInstallationFile(File installation) throws IOException { 50 FileOutputStream out = new FileOutputStream(installation); 51 String id = UUID.randomUUID().toString(); 52 out.write(id.getBytes()); 53 out.close(); 54 } 55}
java
1package jp.test; 2 3import android.support.v7.app.AppCompatActivity; 4import android.os.Bundle; 5 6import com.auth0.android.jwt.JWT; 7 8 9public class MainActivity extends AppCompatActivity { 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 setContentView(R.layout.activity_main); 15 Installation isl = new Installation(); 16 System.out.println(isl.getsID()); 17 System.out.println("test test test "); 18 19 } 20} 21 22

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/28 07:31
2017/05/28 07:44
2017/05/28 09:58