I am able to install native apps in Google Glass now. I hope to know how to create a text file using native apps in Google Glass so that I can save data to text files.
Thanks!
I am able to install native apps in Google Glass now. I hope to know how to create a text file using native apps in Google Glass so that I can save data to text files.
Thanks!
Since Glass is an Android device and you are writing native Android apps for it, you should be able to write text files like you would on any other Android device.
The Android documentation on data storage should be helpful.
I tried the following code to create a file in Google Glass. The following code works with Android, which has a sd card. But does not work for Google Glass. Does anyone know how to create a text file in the Glass? Thanks!
public void SaveSubjectID(String filename, Context ctx) {
try {
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
// Toast.makeText(getBaseContext(), "files", Toast.LENGTH_SHORT).show();
//create a folder in a app.
//http://stackoverflow.com/questions/6911041/how-to-create-folder-into-sd-card-in-android
File rootDirect = new File(Environment.getExternalStorageDirectory() + "/SmartTexting");
if(!rootDirect.exists())
{ rootDirect.mkdir() ;
}
File subjectDirect = new File(Environment.getExternalStorageDirectory() + "/SmartTexting/"+"subject");
if(!subjectDirect.exists())
{ subjectDirect.mkdir() ;
}
//File sdcard = Environment.getExternalStorageDirectory();
File file = new File(subjectDirect,filename);
// Toast.makeText(getBaseContext(), "files created", Toast.LENGTH_SHORT).show();
FileOutputStream fos2 = new FileOutputStream(file, true);
String outline = "test"
+ "\n";
fos2.write(outline.getBytes());
fos2.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I hope you have found out the correct answer by now, still this answer goes for all those who haven't found yet.
Code for writing file to google glass:
try {
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File f = new File(path,"file_new.txt");
f.createNewFile();
Log.d("file pathhhh", "result"+f.getAbsolutePath());
Log.d("file created", "result"+f.createNewFile());
FileOutputStream fOut = new FileOutputStream(f);
//FileOutputStream fileout=openFileOutput(f);
OutputStreamWriter outputWriter=new OutputStreamWriter(fOut);
//writer = new FileWriter(file1);
//writer.write(text.toString());
outputWriter.write(text.toString());
/** Closing the writer object */
outputWriter.close();
Log.d("success", "success"+Environment.getExternalStorageState()+Environment.getStorageState(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The key is to write file in DCIM folder and dont expect the file will be created then only.
To see whether the file has been created or not, shut down the glass and power it on again, you will find the new file in the DCIM folder