Sim, é preciso permissão de leitura/escrita no SD (podes configurar isto via FB ou via xml).
2013/1/22 Luis Costa <[email protected]> > Boas, continuando neste tópico. > Já tenho a app criada, mas não me está a escrever na BD. É necessário > algum tipo de permissões no tablet para tal ? > > O meu código de mysql: > > > private var sqlc:SQLConnection = new SQLConnection(); > // sqlc is an SQLStatment which we need to execute our sql commands > private var sqls:SQLStatement = new SQLStatement(); > // ArrayCollection used as a data provider for the datagrid. It has to be > bindable so that data in datagrid changes automatically when we change the > ArrayCollection > [Bindable] > private var dp:ArrayCollection = new ArrayCollection(); > > // function we call at the begining when application has finished loading > and bulding itself > private function start():void > { > // first we need to set the file class for our database (in this > example test.db). If the Database doesn't exists it will be created when we > open it. > var db:File = > File.applicationStorageDirectory.resolvePath("booksapp.db"); > // after we set the file for our database we need to open it with our > SQLConnection. > sqlc.openAsync(db); > // we need to set some event listeners so we know if we get an sql > error, when the database is fully opened and to know when we recive a > resault from an sql statment. The last one is uset to read data out of > database. > sqlc.addEventListener(SQLEvent.OPEN, db_opened); > sqlc.addEventListener(SQLErrorEvent.ERROR, error); > sqls.addEventListener(SQLErrorEvent.ERROR, error); > sqls.addEventListener(SQLEvent.RESULT, resault); > > } > > private function db_opened(e:SQLEvent):void > { > // when the database is opened we need to link the SQLStatment to our > SQLConnection, so that sql statments for the right database. > // if you don't set this connection you will get an error when you > execute sql statment. > sqls.sqlConnection = sqlc; > // in property text of our SQLStatment we write our sql command. We > can also combine sql statments in our text property so that more than one > statment can be executed at a time. > // in this sql statment we create table in our database with name > "test_table" with three columns (id, first_name and last_name). Id is an > integer that is auto incremented when each item is added. First_name and > last_name are columns in which we can store text > // If you want to know more about sql statments search the web. > sqls.text = "CREATE TABLE IF NOT EXISTS books_table ( id INTEGER > PRIMARY KEY AUTOINCREMENT, title TEXT,author TEXT,year TEXT, spot TEXT, > borrowed TEXT, readed TEXT, avaliation TEXT)"; > // after we have connected sql statment to our sql connection and > writen our sql commands we also need to execute our sql statment. > // nothing will change in database until we execute sql statment. > sqls.execute(); > //Test on Insert > sqls.text = "INSERT INTO books_table > VALUES('11','22','33','44','55','66','77')"; > sqls.execute(); > // after we load the database and create the table if it doesn't > already exists, we call refresh method which i have created to populate our > datagrid > refresh(); > } > // function to add item to our database > private function addItem(title:String ,author:String ,year:String , > spot:String, borrowed:String, readed:String , avaliation:String):void > { > // in this sql statment we add item at the end of our table with > values first_name.text in column first_name and last_name.text for column > last_name > sqls.text = "INSERT INTO books_table > VALUES('"+title+"','"+author+"','"+year+"','"+spot+"','"+borrowed+"','"+readed+"','"+avaliation+"')"; > sqls.execute(); > > refresh(); > } > > // function to call when we want to refresh the data in datagrid > private function refresh(e:TimerEvent = null):void > { > // timer object which we need if sql statment is still executing so > that we can try again after 10 milliseconds. > var timer:Timer = new Timer(10,1); > timer.addEventListener(TimerEvent.TIMER, refresh); > > if ( !sqls.executing )// we need to check if our sql statment is still > executing our last sql command. If so we use Timer to try again in 10 > milliseconds. If we wouldn't check we could get an error because > SQLStatment can't execute two statments at the same time. > { > // sql statment which returns all the data from our "test_table". > To retrive only data from first_name and last_name columns we would use > "SELECT first_name,last_name FROM test_table" > sqls.text = "SELECT * FROM books_table" > sqls.execute(); > } > else > { > timer.start(); > } > } > > // method that gets called if we recive some resaults from our sql > commands. > //this method would also get called for sql statments to insert item and > to create table but in this case sqls.getResault().data would be null > private function resault(e:SQLEvent):void > { > // with sqls.getResault().data we get the array of objects for each > row out of our database > var data:Array = sqls.getResult().data; > // we pass the array of objects to our data provider to fill the > datagrid > dp = new ArrayCollection(data); > } > > // method to remove row from database. > private function remove(selIndex:Number):void > { > // sql statment to delete from our test_table the row that has the > same number in number column as our selected row from datagrid > sqls.text = "DELETE FROM books_table WHERE id="+dp[selIndex].id; > sqls.execute(); > refresh(); > } > // method which gets called when we recive an error from sql connection > or sql statment and displays the error in the alert > private function error(e:SQLErrorEvent):void > { > > }// ActionScript file > > > 2013/1/21 Luis Costa <[email protected]> > >> São os meus primeiros passos em programar para Android, todos as dicas >> são bem vindas :-) >> >> >> 2013/1/21 Hugo Ferreira <[email protected]> >> >>> OK. >>> Outra coisa importante a ter em atenção: Cache de dados. >>> Pequenas tabelas de dados que não sejam alvo de alterações frequentes e >>> que são de consulta frequente, deverão ficar em memória, poupando o acesso >>> ao cartão SD, no entanto isto tem de ser feito com peso e medida pois como >>> bem sabemos, a memória é um recurso escasso :) >>> >>> Programar "qualquer um" faz mas desenvolver uma aplicação com pinta :) >>> (funcionalidades completas e úteis e ao mesmo tempo rápida pode-se tornar >>> um grande desafio e a cereja no topo de bolo é faze-lo com um código de >>> fácil legibilidade e manutenção). >>> >>> >>> >>> No dia 21 de Janeiro de 2013 à36 18:48, Luis Costa <[email protected] >>> > escreveu: >>> >>> É apenas uma biblioteca, mas quando esta app ficar boa depois passo para >>>> outras secalhar mais pesadas. >>>> Vou optar por ver como gravar os dados no SQLite. >>>> >>>> >>>> 2013/1/21 Hugo Ferreira <[email protected]> >>>> >>>>> Boa tarde Luís. >>>>> >>>>> Se queres guardar um grande volume de dados no cartão SD, recomendo o >>>>> uso do SQLite mas atenção que o acesso ao cartão é lento pelo que aqui >>>>> toda >>>>> e qualquer técnica de tunning deverá ser aplicada. >>>>> >>>>> Posso te dizer que numa das minhas primeiras aplicações nos >>>>> marketplaces chegou a demorar mais de 5 segundos ao carregar dados >>>>> auxiliares no arranque, após a bd ter ganho um grande volume de dados. >>>>> Após >>>>> estudar e aplicar todas as técnicas de tunning de sqlite, passou a demorar >>>>> microsegundos. >>>>> >>>>> O Google aqui é teu amigo para descobrires como usar o SQLite e como >>>>> aplicar estas técnicas logo de ínicio. >>>>> >>>>> Se quiseres apenas guardar variáveis (por exemplo para o estado de um >>>>> jogo), então podes usar um processo menos pesado como o shared object. >>>>> >>>>> >>>>> Cumprimentos, >>>>> Hugo. >>>>> >>>>> >>>>> No dia 21 de Janeiro de 2013 à44 18:33, Luis Costa < >>>>> [email protected]> escreveu: >>>>> >>>>>> Boas pessoal, >>>>>> Estou a fazer a minha primeira experiência de aplicação para Android >>>>>> com Adobe Flash Builder, >>>>>> Qual a melhor maneira de guardar os dados no Android ? Mysql ? >>>>>> Alguém sabe de um bom tutorial para estar parte ? >>>>>> Cumprimentos >>>>>> >>>>>> -- >>>>>> Luís Medeiro Costa >>>>>> >>>>>> Flex Front-End Developer >>>>>> URL: http://www.luiscostaweb.com/ >>>>>> E-mail: [email protected] >>>>>> MSN: [email protected] >>>>>> Twitter: http://twitter.com/LTostas >>>>>> >>>>>> -- >>>>>> Recebeu esta mensagem porque está inscrito no grupo "Mailing List da >>>>>> Comunidade Portuguesa de Rich Internet Applications - www.riapt.org" >>>>>> dos Grupos do Google. >>>>>> Para publicar uma mensagem neste grupo, envie um e-mail para >>>>>> [email protected]. >>>>>> Para anular a inscrição neste grupo, envie um e-mail para >>>>>> [email protected]. >>>>>> Para ver mais opções, visite este grupo em >>>>>> http://groups.google.com/group/riapt?hl=pt-PT. >>>>>> >>>>> >>>>> -- >>>>> Recebeu esta mensagem porque está inscrito no grupo "Mailing List da >>>>> Comunidade Portuguesa de Rich Internet Applications - www.riapt.org" >>>>> dos Grupos do Google. >>>>> Para publicar uma mensagem neste grupo, envie um e-mail para >>>>> [email protected]. >>>>> Para anular a inscrição neste grupo, envie um e-mail para >>>>> [email protected]. >>>>> Para ver mais opções, visite este grupo em >>>>> http://groups.google.com/group/riapt?hl=pt-PT. >>>>> >>>> >>>> >>>> >>>> -- >>>> Luís Medeiro Costa >>>> >>>> Flex Front-End Developer >>>> URL: http://www.luiscostaweb.com/ >>>> E-mail: [email protected] >>>> MSN: [email protected] >>>> Twitter: http://twitter.com/LTostas >>>> >>>> -- >>>> Recebeu esta mensagem porque está inscrito no grupo "Mailing List da >>>> Comunidade Portuguesa de Rich Internet Applications - www.riapt.org" >>>> dos Grupos do Google. >>>> Para publicar uma mensagem neste grupo, envie um e-mail para >>>> [email protected]. >>>> Para anular a inscrição neste grupo, envie um e-mail para >>>> [email protected]. >>>> Para ver mais opções, visite este grupo em >>>> http://groups.google.com/group/riapt?hl=pt-PT. >>>> >>> >>> -- >>> Recebeu esta mensagem porque está inscrito no grupo "Mailing List da >>> Comunidade Portuguesa de Rich Internet Applications - www.riapt.org" >>> dos Grupos do Google. >>> Para publicar uma mensagem neste grupo, envie um e-mail para >>> [email protected]. >>> Para anular a inscrição neste grupo, envie um e-mail para >>> [email protected]. >>> Para ver mais opções, visite este grupo em >>> http://groups.google.com/group/riapt?hl=pt-PT. >>> >> >> >> >> -- >> Luís Medeiro Costa >> >> Flex Front-End Developer >> URL: http://www.luiscostaweb.com/ >> E-mail: [email protected] >> MSN: [email protected] >> Twitter: http://twitter.com/LTostas >> > > > > -- > Luís Medeiro Costa > > Flex Front-End Developer > URL: http://www.luiscostaweb.com/ > E-mail: [email protected] > MSN: [email protected] > Twitter: http://twitter.com/LTostas > > -- > Recebeu esta mensagem porque está inscrito no grupo "Mailing List da > Comunidade Portuguesa de Rich Internet Applications - www.riapt.org" dos > Grupos do Google. > Para publicar uma mensagem neste grupo, envie um e-mail para > [email protected]. > Para anular a inscrição neste grupo, envie um e-mail para > [email protected]. > Para ver mais opções, visite este grupo em > http://groups.google.com/group/riapt?hl=pt-PT. > -- Recebeu esta mensagem porque está inscrito no grupo "Mailing List da Comunidade Portuguesa de Rich Internet Applications - www.riapt.org" dos Grupos do Google. Para publicar uma mensagem neste grupo, envie um e-mail para [email protected]. Para anular a inscrição neste grupo, envie um e-mail para [email protected]. Para ver mais opções, visite este grupo em http://groups.google.com/group/riapt?hl=pt-PT.
