Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23494] Android: Support #createFile() method on Ti.Filesystem.File

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-10-31T14:52:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsparity
ReporterChristopher Williams
AssigneeFrankie Merzadyan
Created2016-06-10T18:59:11.000+0000
Updated2017-01-31T19:55:19.000+0000

Description

Android is the only platform that doesn't support Ti.Filesystem.File#createFile(). We should ideally support it for parity's sake.

Comments

  1. Chee Kiat Ng 2016-10-17

    PR here: https://github.com/appcelerator/titanium_mobile/pull/8514
  2. Farzad Merzadyan 2016-10-18

    PR: https://github.com/appcelerator/titanium_mobile/pull/8514
  3. Lokesh Choudhary 2017-01-31

    Verified the implementation. createFile() works as expected in android.
       var win = Ti.UI.createWindow({
       	layout:'vertical'
       });
       
       var b1 = Ti.UI.createButton({
       	title:"tempdir",
       	top:30
       });
       
       var b2 = Ti.UI.createButton({
       	title:"appdatadir",
       	top:20
       });
       
       var b3 = Ti.UI.createButton({
       	title:"extstrdir",
       	top:20
       });
       
       var b4 = Ti.UI.createButton({
       	title:"appcachedir",
       	top:20
       });
       
       function tempFile(){
       	var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
       	Ti.API.info("Created Settings: " + Settings.createDirectory());
       	Ti.API.info('Settings ' + Settings);
       	var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
       	newFile.createFile();
       	
       	if (newFile.exists()){
       	    newFile.write('I am in temp dir.');
       	    alert('newfile: '+newFile.read());
       	}
       }
       
       function appdatadir(){
       	var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'Settings');
       	Ti.API.info("Created Settings: " + Settings.createDirectory());
       	Ti.API.info('Settings ' + Settings);
       	var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
       	
       	newFile.createFile();
       	
       	if (newFile.exists()){
       	    newFile.write('I am in appl data dir.');
       	    alert('newfile: '+newFile.read());
       	}
       }
       
       function extstrdir(){
       	if(Ti.Filesystem.isExternalStoragePresent()){
       	var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
       		Ti.API.info("Created Settings: " + Settings.createDirectory());
       		Ti.API.info('Settings ' + Settings);
       		var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
       		
       		newFile.createFile();
       		
       		if (newFile.exists()){
       		    newFile.write('I am in ext str dir.');
       		    alert('newfile: '+newFile.read());
       		}
       	}
       	else{
       		alert("No ext storage present");
       	}
       }
       
       function appcachedir(){
       	var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
       	Ti.API.info("Created Settings: " + Settings.createDirectory());
       	Ti.API.info('Settings ' + Settings);
       	var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
       	
       	newFile.createFile();
       	
       	if (newFile.exists()){
       	    newFile.write('I am in app cache dir.');
       	    alert('newfile: '+newFile.read());
       	}
       }
       
       b1.addEventListener('click',function(){
       	tempFile();
       });
       
       b2.addEventListener('click',function(){
       	appdatadir();
       });
       
       b3.addEventListener('click',function(){
       	extstrdir();
       });
       
       b4.addEventListener('click',function(){
       	appcachedir();
       });
       
       win.add([b1,b2,b3,b4]);
       win.open();
       
    Closing. Appc Studio : 4.8.1.201612050850 SDK Version : 6.1.0.v20170130073612 Mac OS Version : 10.12.2 Xcode Version : Xcode 8.2.1 Build version 8C1002 Appc CLI AND Appc NPM : {"NPM":"4.2.9-1","CLI":"6.1.0"} Ti CLI : 5.0.11 Alloy : 1.9.5 Node : v4.6.0 Nexus 6 running 6.0.1, Android emulator 7.1.1, android emulator 4.4.2

JSON Source