[android-beginners] Re: IOException with BufferedReader
Hi Yousuf, Thank you very much for the answer. However, I don't know in which directory i should put the file? I don't want to save the file from my application - it should just be there when the application is installed. I don't think I can access this file with the context.openFileInput() method? Or am I wrong? //Kaloer On 15 Dec., 16:44, Yousuf Syed yousuf.syed@gmail.com wrote: Hi, You cannot use the regular java IO for res/raw. folder. only if you are using /sd/card you can use regular java.io here is some code that might help you FileInputStream fin = context.openFileInput(sitestore); InputStreamReader br = new InputStreamReader(fin); String readString = ; int i; while((i = br.read()) != -1){ inputBuffer = (char)i; readString = readString + inputBuffer; } FileOutputStream fOut = context.openFileOutput(sitestore, context.MODE_WORLD_READABLE); OutputStreamWriter bw = new OutputStreamWriter(fOut); write the code for writting to file here... Regards, Yousuf. On Mon, Dec 14, 2009 at 4:03 PM, kaloer mkal...@gmail.com wrote: Hi, I have a problem when I'm trying to read a file from the res/raw folder. When I get the file as an InputStream and try reading it line for line with a BufferedReader, I get an IOException when I'm calling the br.readLine(). I do no get any additional information in the exception. Are there anything wrong with this code: private void readFile(InputStream mFile) { DataInputStream in = new DataInputStream(mFile); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { Log.i(line, strLine); } in.close(); } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.comandroid-beginners%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: IOException with BufferedReader
Hi again, I've just tried putting a simple file with the Hello, world text into the raw folder, and this works as it should. The other file is 1.1 megabyte. Can the error be caused because of the size? On 15 Dec., 19:52, Yousuf Syed yousuf.syed@gmail.com wrote: Hi Kaloer, The procedure is as follows: 1. create a raw folder, 2. place a file.(txt or regular file with no extension) in the raw folder. 3.write the code as said earlier. 4 one more thing that you can do is push the file through eclipse's ddms to data/data/your application dir/files directory. (Your file in the DDMS will be updated not the one contained in /res/raw/ folder so look for the size of the file present in ddms under /data/data/com.app.files/files/ ) 5 path to be specified: just give the file name that is present in the raw folder. if the name of file is sample.txt which is present in /res/raw/ folder FileInputStream fin = context.openFileInput(sample.txt); // if used within a adapter class or somewhere outside the activity class if you are using this within the activity it should be FileInputStream fin = openFileInput(sample.txt); I guess step 4 is needed for the first time since your read is performed before your write. if you are writing before reading then the FileOutputStream object either writes to a existing file or creates a new one( FileInputStream object cannot create a new file). Do remember that raw folder has a limit to the data that it can contain so files with large amount of data cant be stored there. For your convenience I am attaching my filehandling projected that reads and writes to file. This is a working example. for some reason if this is not working try using permissions. read_owner_data write_owner_data write_external_storage but these permissions are for files stored on /sdcard/filename Hope this would help. Regards, Yousuf. On Tue, Dec 15, 2009 at 12:28 PM, kaloer mkal...@gmail.com wrote: Hi Yousuf, Thank you very much for the answer. However, I don't know in which directory i should put the file? I don't want to save the file from my application - it should just be there when the application is installed. I don't think I can access this file with the context.openFileInput() method? Or am I wrong? //Kaloer On 15 Dec., 16:44, Yousuf Syed yousuf.syed@gmail.com wrote: Hi, You cannot use the regular java IO for res/raw. folder. only if you are using /sd/card you can use regular java.io here is some code that might help you FileInputStream fin = context.openFileInput(sitestore); InputStreamReader br = new InputStreamReader(fin); String readString = ; int i; while((i = br.read()) != -1){ inputBuffer = (char)i; readString = readString + inputBuffer; } FileOutputStream fOut = context.openFileOutput(sitestore, context.MODE_WORLD_READABLE); OutputStreamWriter bw = new OutputStreamWriter(fOut); write the code for writting to file here... Regards, Yousuf. On Mon, Dec 14, 2009 at 4:03 PM, kaloer mkal...@gmail.com wrote: Hi, I have a problem when I'm trying to read a file from the res/raw folder. When I get the file as an InputStream and try reading it line for line with a BufferedReader, I get an IOException when I'm calling the br.readLine(). I do no get any additional information in the exception. Are there anything wrong with this code: private void readFile(InputStream mFile) { DataInputStream in = new DataInputStream(mFile); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { Log.i(line, strLine); } in.close(); } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.comandroid-beginners%2bunsubscr...@googlegroups.com android-beginners%2bunsubscr...@googlegroups.comandroid-beginners%252bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.comandroid-beginners%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en filehandling.zip 59KVisDownload
[android-beginners] Re: IOException with BufferedReader
Oh okay.. But how can I use it them? Do I need to download it from a server or so? I have tried putting it into the assets folder but this seems to have the same limit. On 15 Dec., 20:04, Yousuf Syed yousuf.syed@gmail.com wrote: yes, For sure. the raw folder has a limit to the amount of data that it can hold. It cant hold large data files. Regards, Yousuf. On Tue, Dec 15, 2009 at 1:58 PM, kaloer mkal...@gmail.com wrote: Hi again, I've just tried putting a simple file with the Hello, world text into the raw folder, and this works as it should. The other file is 1.1 megabyte. Can the error be caused because of the size? On 15 Dec., 19:52, Yousuf Syed yousuf.syed@gmail.com wrote: Hi Kaloer, The procedure is as follows: 1. create a raw folder, 2. place a file.(txt or regular file with no extension) in the raw folder. 3.write the code as said earlier. 4 one more thing that you can do is push the file through eclipse's ddms to data/data/your application dir/files directory. (Your file in the DDMS will be updated not the one contained in /res/raw/ folder so look for the size of the file present in ddms under /data/data/com.app.files/files/ ) 5 path to be specified: just give the file name that is present in the raw folder. if the name of file is sample.txt which is present in /res/raw/ folder FileInputStream fin = context.openFileInput(sample.txt); // if used within a adapter class or somewhere outside the activity class if you are using this within the activity it should be FileInputStream fin = openFileInput(sample.txt); I guess step 4 is needed for the first time since your read is performed before your write. if you are writing before reading then the FileOutputStream object either writes to a existing file or creates a new one( FileInputStream object cannot create a new file). Do remember that raw folder has a limit to the data that it can contain so files with large amount of data cant be stored there. For your convenience I am attaching my filehandling projected that reads and writes to file. This is a working example. for some reason if this is not working try using permissions. read_owner_data write_owner_data write_external_storage but these permissions are for files stored on /sdcard/filename Hope this would help. Regards, Yousuf. On Tue, Dec 15, 2009 at 12:28 PM, kaloer mkal...@gmail.com wrote: Hi Yousuf, Thank you very much for the answer. However, I don't know in which directory i should put the file? I don't want to save the file from my application - it should just be there when the application is installed. I don't think I can access this file with the context.openFileInput() method? Or am I wrong? //Kaloer On 15 Dec., 16:44, Yousuf Syed yousuf.syed@gmail.com wrote: Hi, You cannot use the regular java IO for res/raw. folder. only if you are using /sd/card you can use regular java.io here is some code that might help you FileInputStream fin = context.openFileInput(sitestore); InputStreamReader br = new InputStreamReader(fin); String readString = ; int i; while((i = br.read()) != -1){ inputBuffer = (char)i; readString = readString + inputBuffer; } FileOutputStream fOut = context.openFileOutput(sitestore, context.MODE_WORLD_READABLE); OutputStreamWriter bw = new OutputStreamWriter(fOut); write the code for writting to file here... Regards, Yousuf. On Mon, Dec 14, 2009 at 4:03 PM, kaloer mkal...@gmail.com wrote: Hi, I have a problem when I'm trying to read a file from the res/raw folder. When I get the file as an InputStream and try reading it line for line with a BufferedReader, I get an IOException when I'm calling the br.readLine(). I do no get any additional information in the exception. Are there anything wrong with this code: private void readFile(InputStream mFile) { DataInputStream in = new DataInputStream(mFile); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { Log.i(line, strLine); } in.close(); } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.comandroid-beginners%2bunsubscr...@googlegroups.com android-beginners
[android-beginners] Re: IOException with BufferedReader
Thank you very much for your help! No problem, I know how to do this. Best regards, Kaloer On 15 Dec., 20:22, Yousuf Syed yousuf.syed@gmail.com wrote: Hi, Write another supporting application to download them and save it to the location used in your main application. then install the main applicaiton. This should do. but I have not worked on downloading files from server. So cant help you in this regard. Sorry for that. Regards, Yousuf. On Tue, Dec 15, 2009 at 2:11 PM, kaloer mkal...@gmail.com wrote: Oh okay.. But how can I use it them? Do I need to download it from a server or so? I have tried putting it into the assets folder but this seems to have the same limit. On 15 Dec., 20:04, Yousuf Syed yousuf.syed@gmail.com wrote: yes, For sure. the raw folder has a limit to the amount of data that it can hold. It cant hold large data files. Regards, Yousuf. On Tue, Dec 15, 2009 at 1:58 PM, kaloer mkal...@gmail.com wrote: Hi again, I've just tried putting a simple file with the Hello, world text into the raw folder, and this works as it should. The other file is 1.1 megabyte. Can the error be caused because of the size? On 15 Dec., 19:52, Yousuf Syed yousuf.syed@gmail.com wrote: Hi Kaloer, The procedure is as follows: 1. create a raw folder, 2. place a file.(txt or regular file with no extension) in the raw folder. 3.write the code as said earlier. 4 one more thing that you can do is push the file through eclipse's ddms to data/data/your application dir/files directory. (Your file in the DDMS will be updated not the one contained in /res/raw/ folder so look for the size of the file present in ddms under /data/data/com.app.files/files/ ) 5 path to be specified: just give the file name that is present in the raw folder. if the name of file is sample.txt which is present in /res/raw/ folder FileInputStream fin = context.openFileInput(sample.txt); // if used within a adapter class or somewhere outside the activity class if you are using this within the activity it should be FileInputStream fin = openFileInput(sample.txt); I guess step 4 is needed for the first time since your read is performed before your write. if you are writing before reading then the FileOutputStream object either writes to a existing file or creates a new one( FileInputStream object cannot create a new file). Do remember that raw folder has a limit to the data that it can contain so files with large amount of data cant be stored there. For your convenience I am attaching my filehandling projected that reads and writes to file. This is a working example. for some reason if this is not working try using permissions. read_owner_data write_owner_data write_external_storage but these permissions are for files stored on /sdcard/filename Hope this would help. Regards, Yousuf. On Tue, Dec 15, 2009 at 12:28 PM, kaloer mkal...@gmail.com wrote: Hi Yousuf, Thank you very much for the answer. However, I don't know in which directory i should put the file? I don't want to save the file from my application - it should just be there when the application is installed. I don't think I can access this file with the context.openFileInput() method? Or am I wrong? //Kaloer On 15 Dec., 16:44, Yousuf Syed yousuf.syed@gmail.com wrote: Hi, You cannot use the regular java IO for res/raw. folder. only if you are using /sd/card you can use regular java.io here is some code that might help you FileInputStream fin = context.openFileInput(sitestore); InputStreamReader br = new InputStreamReader(fin); String readString = ; int i; while((i = br.read()) != -1){ inputBuffer = (char)i; readString = readString + inputBuffer; } FileOutputStream fOut = context.openFileOutput(sitestore, context.MODE_WORLD_READABLE); OutputStreamWriter bw = new OutputStreamWriter(fOut); write the code for writting to file here... Regards, Yousuf. On Mon, Dec 14, 2009 at 4:03 PM, kaloer mkal...@gmail.com wrote: Hi, I have a problem when I'm trying to read a file from the res/raw folder. When I get the file as an InputStream and try reading it line for line with a BufferedReader, I get an IOException when I'm calling the br.readLine(). I do no get any additional information in the exception. Are there anything wrong with this code: private void readFile(InputStream mFile) { DataInputStream in = new DataInputStream(mFile
[android-beginners] IOException with BufferedReader
Hi, I have a problem when I'm trying to read a file from the res/raw folder. When I get the file as an InputStream and try reading it line for line with a BufferedReader, I get an IOException when I'm calling the br.readLine(). I do no get any additional information in the exception. Are there anything wrong with this code: private void readFile(InputStream mFile) { DataInputStream in = new DataInputStream(mFile); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { Log.i(line, strLine); } in.close(); } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: Flickering camera preview in SurfaceView
I'm using an HTC Hero with the 1.5 cupcake firmware. I just tried different options to get it working, and this works.. On 9 Dec., 11:58, Wu-cheng Li (李務誠) wuchen...@google.com wrote: This is really strange. Which phone and release are you running on? I don't know any phone that supports JPEG preview frame. On Wed, Dec 9, 2009 at 12:25 AM, kaloer mkal...@gmail.com wrote: It works now. Should simply set the parameters.setPreviewFormat(); to PixelFormat.JPEG. On 5 Dec., 13:05, kaloer mkal...@gmail.com wrote: I have a screenshot of the flicker here:http://tinypic.com/r/35003lv/6 On 5 Dec., 12:59, kaloer mkal...@gmail.com wrote: Hi, I have an Dialog with a custom view. This view has a SurfaceView which shows a camera preview. However, the preview is very flickering. The taken photo does not contain flicker. It looks as it should. Why does the preview flicker? (The camera does work :-) ) This is my custom view: - public class CameraView extends LinearLayout implements SurfaceHolder.Callback, OnClickListener, PictureCallback { private SurfaceView surfView; private SurfaceHolder previewHolder; private Camera camera; OnProfilePictureTakenListener onProfilePictureTakenListener = null; public CameraView(Context context) { super(context); setOnClickListener(this); surfView = new SurfaceView(getContext()); addView(surfView); previewHolder = surfView.getHolder(); previewHolder.addCallback(this); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(width, height); parameters.setPictureFormat(PixelFormat.JPEG); camera.setParameters(parameters); camera.startPreview(); } @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); try { camera.setPreviewDisplay(previewHolder); } catch(Throwable t) { Log.e(surfaceCallback, Exception, t); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show (); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); camera = null; } @Override public void onClick(View v) { takePicture(); } private void takePicture() { camera.stopPreview(); camera.takePicture(null, null, this); } @Override public void onPictureTaken(byte[] data, Camera camera) { new SavePhotoTask().execute(data); camera.startPreview(); } public void setOnPictureTakenListener(OnProfilePictureTakenListener lis) { onProfilePictureTakenListener = lis; } class SavePhotoTask extends AsyncTaskbyte[], String, String { @Override protected String doInBackground(byte[]... jpeg) { File photo = new File(Environment.getExternalStorageDirectory(), /.addMePictures/ + System.currentTimeMillis()); if(photo.exists()) { photo.delete(); } try { FileOutputStream fos = new FileOutputStream(photo.getPath()); fos.write(jpeg[0]); fos.close(); } catch(IOException e) { e.printStackTrace(); } if(onProfilePictureTakenListener != null) { onProfilePictureTakenListener.onProfilePictureTaken(photo); } return null; } } public interface OnProfilePictureTakenListener { public abstract void onProfilePictureTaken(File imgFile); } } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android
[android-beginners] Re: Flickering camera preview in SurfaceView
It works now. Should simply set the parameters.setPreviewFormat(); to PixelFormat.JPEG. On 5 Dec., 13:05, kaloer mkal...@gmail.com wrote: I have a screenshot of the flicker here:http://tinypic.com/r/35003lv/6 On 5 Dec., 12:59, kaloer mkal...@gmail.com wrote: Hi, I have an Dialog with a custom view. This view has a SurfaceView which shows a camera preview. However, the preview is very flickering. The taken photo does not contain flicker. It looks as it should. Why does the preview flicker? (The camera does work :-) ) This is my custom view: - public class CameraView extends LinearLayout implements SurfaceHolder.Callback, OnClickListener, PictureCallback { private SurfaceView surfView; private SurfaceHolder previewHolder; private Camera camera; OnProfilePictureTakenListener onProfilePictureTakenListener = null; public CameraView(Context context) { super(context); setOnClickListener(this); surfView = new SurfaceView(getContext()); addView(surfView); previewHolder = surfView.getHolder(); previewHolder.addCallback(this); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(width, height); parameters.setPictureFormat(PixelFormat.JPEG); camera.setParameters(parameters); camera.startPreview(); } @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); try { camera.setPreviewDisplay(previewHolder); } catch(Throwable t) { Log.e(surfaceCallback, Exception, t); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show (); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); camera = null; } @Override public void onClick(View v) { takePicture(); } private void takePicture() { camera.stopPreview(); camera.takePicture(null, null, this); } @Override public void onPictureTaken(byte[] data, Camera camera) { new SavePhotoTask().execute(data); camera.startPreview(); } public void setOnPictureTakenListener(OnProfilePictureTakenListener lis) { onProfilePictureTakenListener = lis; } class SavePhotoTask extends AsyncTaskbyte[], String, String { @Override protected String doInBackground(byte[]... jpeg) { File photo = new File(Environment.getExternalStorageDirectory(), /.addMePictures/ + System.currentTimeMillis()); if(photo.exists()) { photo.delete(); } try { FileOutputStream fos = new FileOutputStream(photo.getPath()); fos.write(jpeg[0]); fos.close(); } catch(IOException e) { e.printStackTrace(); } if(onProfilePictureTakenListener != null) { onProfilePictureTakenListener.onProfilePictureTaken(photo); } return null; } } public interface OnProfilePictureTakenListener { public abstract void onProfilePictureTaken(File imgFile); } } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Flickering camera preview in SurfaceView
Hi, I have an Dialog with a custom view. This view has a SurfaceView which shows a camera preview. However, the preview is very flickering. The taken photo does not contain flicker. It looks as it should. Why does the preview flicker? (The camera does work :-) ) This is my custom view: - public class CameraView extends LinearLayout implements SurfaceHolder.Callback, OnClickListener, PictureCallback { private SurfaceView surfView; private SurfaceHolder previewHolder; private Camera camera; OnProfilePictureTakenListener onProfilePictureTakenListener = null; public CameraView(Context context) { super(context); setOnClickListener(this); surfView = new SurfaceView(getContext()); addView(surfView); previewHolder = surfView.getHolder(); previewHolder.addCallback(this); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(width, height); parameters.setPictureFormat(PixelFormat.JPEG); camera.setParameters(parameters); camera.startPreview(); } @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); try { camera.setPreviewDisplay(previewHolder); } catch(Throwable t) { Log.e(surfaceCallback, Exception, t); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show (); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); camera = null; } @Override public void onClick(View v) { takePicture(); } private void takePicture() { camera.stopPreview(); camera.takePicture(null, null, this); } @Override public void onPictureTaken(byte[] data, Camera camera) { new SavePhotoTask().execute(data); camera.startPreview(); } public void setOnPictureTakenListener(OnProfilePictureTakenListener lis) { onProfilePictureTakenListener = lis; } class SavePhotoTask extends AsyncTaskbyte[], String, String { @Override protected String doInBackground(byte[]... jpeg) { File photo = new File(Environment.getExternalStorageDirectory(), /.addMePictures/ + System.currentTimeMillis()); if(photo.exists()) { photo.delete(); } try { FileOutputStream fos = new FileOutputStream(photo.getPath()); fos.write(jpeg[0]); fos.close(); } catch(IOException e) { e.printStackTrace(); } if(onProfilePictureTakenListener != null) { onProfilePictureTakenListener.onProfilePictureTaken(photo); } return null; } } public interface OnProfilePictureTakenListener { public abstract void onProfilePictureTaken(File imgFile); } } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: Flickering camera preview in SurfaceView
I have a screenshot of the flicker here: http://tinypic.com/r/35003lv/6 On 5 Dec., 12:59, kaloer mkal...@gmail.com wrote: Hi, I have an Dialog with a custom view. This view has a SurfaceView which shows a camera preview. However, the preview is very flickering. The taken photo does not contain flicker. It looks as it should. Why does the preview flicker? (The camera does work :-) ) This is my custom view: - public class CameraView extends LinearLayout implements SurfaceHolder.Callback, OnClickListener, PictureCallback { private SurfaceView surfView; private SurfaceHolder previewHolder; private Camera camera; OnProfilePictureTakenListener onProfilePictureTakenListener = null; public CameraView(Context context) { super(context); setOnClickListener(this); surfView = new SurfaceView(getContext()); addView(surfView); previewHolder = surfView.getHolder(); previewHolder.addCallback(this); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(width, height); parameters.setPictureFormat(PixelFormat.JPEG); camera.setParameters(parameters); camera.startPreview(); } @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); try { camera.setPreviewDisplay(previewHolder); } catch(Throwable t) { Log.e(surfaceCallback, Exception, t); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show (); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); camera = null; } @Override public void onClick(View v) { takePicture(); } private void takePicture() { camera.stopPreview(); camera.takePicture(null, null, this); } @Override public void onPictureTaken(byte[] data, Camera camera) { new SavePhotoTask().execute(data); camera.startPreview(); } public void setOnPictureTakenListener(OnProfilePictureTakenListener lis) { onProfilePictureTakenListener = lis; } class SavePhotoTask extends AsyncTaskbyte[], String, String { @Override protected String doInBackground(byte[]... jpeg) { File photo = new File(Environment.getExternalStorageDirectory(), /.addMePictures/ + System.currentTimeMillis()); if(photo.exists()) { photo.delete(); } try { FileOutputStream fos = new FileOutputStream(photo.getPath()); fos.write(jpeg[0]); fos.close(); } catch(IOException e) { e.printStackTrace(); } if(onProfilePictureTakenListener != null) { onProfilePictureTakenListener.onProfilePictureTaken(photo); } return null; } } public interface OnProfilePictureTakenListener { public abstract void onProfilePictureTaken(File imgFile); } } Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Intent.getIntExtra doesn't find value
Hi, I'm modifying the default Alarm Clock application source, but I have a problem sending an Integer value with an Intent. This is where I put the snooze_duration value into the Intent: static void enableAlert(Context context, int id, String label, long atTimeInMillis, int dismissBehaviour, int snoozeBehaviour, int snoozeDuration) { AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(ALARM_ALERT_ACTION); if (Log.LOGV) Log.v(** setAlert id + id + atTime + atTimeInMillis); intent.putExtra(Alarms.ID, id); intent.putExtra(Alarms.LABEL, label); intent.putExtra(Alarms.TIME, atTimeInMillis); intent.putExtra(Alarms.DISMISS_BEHAVIOUR, dismissBehaviour); intent.putExtra(Alarms.SNOOZE_BEHAVIOUR, snoozeBehaviour); //HERE: intent.putExtra(Alarms.SNOOZE_DURATION, snoozeDuration); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (true) { am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); } else { // a five-second alarm, for testing am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, sender); } setStatusBarIcon(context, true); Calendar c = Calendar.getInstance(); c.setTime(new java.util.Date(atTimeInMillis)); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); } But when I try reading it, it sets the defaultValue instead. The other values works as they should, but the snooze_duration doesn't. I get the values in the OnCreate() method in the activity started by the Intent: Intent i = getIntent(); mAlarmId = i.getIntExtra(Alarms.ID, -1); mDismissBehaviour = i.getIntExtra(Alarms.DISMISS_BEHAVIOUR, 0); mSnoozeBehaviour = i.getIntExtra(Alarms.SNOOZE_BEHAVIOUR, 0); mSnoozeDuration = i.getIntExtra(Alarms.SNOOZE_DURATION, 10); Why doesn't this work? I have tried debugging, and it does put the correct integer value in the Intent.putExtra method. Thank you very much! //Kaloer -- You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] LayoutParams.ScreenBrightness problem
Hi, In my last update, I can't change the screen brightness anymore. I have not changed the code snippet where the brightness is set. Can it be caused by Donut? Here's my code, placed in the onResume() method: if (alwaysBacklight) { WindowManager.LayoutParams lp = getWindow().getAttributes(); final PowerManager pm = (PowerManager) getSystemService (Context.POWER_SERVICE); this.mWakeLock = pm.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, clockTag); this.mWakeLock.acquire(); int value = screenBrightness; if (value 5) value = 5; lp.screenBrightness = (float) value / 100; getWindow().setAttributes(lp); getWindow().setFlags (android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 0); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: LayoutParams.ScreenBrightness problem
Update: I'm sure it is caused by Donut. It works on a 1.5 cupcake device. Is this a bug or can I fix it? Thank you, Kaloer On 7 Okt., 09:41, kaloer mkal...@gmail.com wrote: Hi, In my last update, I can't change the screen brightness anymore. I have not changed the code snippet where the brightness is set. Can it be caused by Donut? Here's my code, placed in the onResume() method: if (alwaysBacklight) { WindowManager.LayoutParams lp = getWindow().getAttributes(); final PowerManager pm = (PowerManager) getSystemService (Context.POWER_SERVICE); this.mWakeLock = pm.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, clockTag); this.mWakeLock.acquire(); int value = screenBrightness; if (value 5) value = 5; lp.screenBrightness = (float) value / 100; getWindow().setAttributes(lp); getWindow().setFlags (android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 0); } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Timeout executing service - how to avoid this?
android.process.acore for activity com.android.launcher/.Launcher: pid=1793 uid=10003 gids={3003} 07-18 20:35:32.327: ERROR/ActivityThread(583): Failed to find provider info for android.server.checkin 07-18 20:35:32.327: WARN/Checkin(583): Can't log event SYSTEM_SERVICE_LOOPING: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/events 07-18 20:35:32.458: INFO/jdwp(1793): received file descriptor 20 from ADB 07-18 20:35:33.317: INFO/ActivityThread(1793): Publishing provider user_dictionary: com.android.providers.userdictionary.UserDictionaryProvider 07-18 20:35:33.428: INFO/ActivityThread(1793): Publishing provider com.android.googlesearch.SuggestionProvider: com.android.googlesearch.SuggestionProvider 07-18 20:35:33.527: INFO/ActivityThread(1793): Publishing provider contacts;call_log: com.android.providers.contacts.ContactsProvider 07-18 20:35:33.667: WARN/ActivityManager(583): Unable to start service Intent { action=android.accounts.IAccountsService comp= {com.google.android.googleapps/ com.google.android.googleapps.GoogleLoginService} }: not found 07-18 20:35:33.677: WARN/AccountMonitor(1793): Couldn't connect to Intent { action=android.accounts.IAccountsService comp= {com.google.android.googleapps/ com.google.android.googleapps.GoogleLoginService} } (Missing service?) 07-18 20:35:33.687: INFO/ActivityThread(1793): Publishing provider com.android.launcher.settings: com.android.launcher.LauncherProvider 07-18 20:35:34.367: DEBUG/dalvikvm(1793): GC freed 2657 objects / 178088 bytes in 145ms 07-18 20:35:34.897: DEBUG/HomeLoaders(1793): load applications 07-18 20:35:34.907: DEBUG/HomeLoaders(1793): loading user items 07-18 20:35:34.917: DEBUG/HomeLoaders(1793): -- starting workspace loader 07-18 20:35:35.147: INFO/ActivityManager(583): Displayed activity com.android.launcher/.Launcher: 3134 ms 07-18 20:35:35.947: DEBUG/HomeLoaders(1793): -- starting applications loader 07-18 20:35:37.017: INFO/ActivityManager(583): Start proc com.kaloersoftware.flickrwall for service com.kaloersoftware.flickrwall/.FlickrWallService: pid=1804 uid=10031 gids={3003} 07-18 20:35:37.188: INFO/jdwp(1804): received file descriptor 10 from ADB Thank you very much, Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Timeout executing service - how to avoid this?
Thank you very much. I put the xml parsing into an AsyncTask, and it works perfectly. //Kaloer On 18 Jul., 22:54, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: When I debug my application, it suddenly disconnects from the DalvikVM without throwing an exception. Regarding this, the emulator shows an ANR dialog. It happens some time after I have started a service to do an operation, by a Broadcast receiver. The operation does take pretty long time, because it is parsing a xml document. It does not stop after a special point in my code. I know that a Broadcast receiver needs to be executed fast, but when I start a service by the context.startService(Intent) method it shouldn't wait for the service's execution, should it? All callbacks from Android need to be done quickly. This includes starting services. Only work done on threads of your own creation can take longer. I've attached the log (which do have a line with 07-18 20:35:24.148: WARN/ActivityManager(583): Timeout executing service: ServiceRecord{43818238 com.kaloersoftware.flickrwall/.FlickrWallService} Something in your service (onCreate() or onStart(), most likely) is taking too long. Can it help if I do the xml parsing in a thread? Yes. Use AsyncTask or something to move the XML parsing off the thread used for the callback. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Need Android talent? Ask on HADO!http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Using Buttons in home screen widgets
It works now, Thank you very much for your help! //Kaloer On 12 Jun., 01:33, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Thanks for the answer, I have tried working with my code and looking at your widget's source. Event though, I can't get it working. I do not use a service as you, but my code looks like this: Off the cuff, I'm not sure what's going on. First, try my code verbatim, and make sure it works in your environment. Then, try morphing my code to look more like what you want. For example, even though you are not using a service, give that a shot -- bear in mind that you can't do much in a BroadcastReceiver before timing out. My guess is that the service is somehow making a difference, but I'm not quite sure why. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Need Android talent? Ask on HADO!http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Using Buttons in home screen widgets
Hi, I'm trying to develop my first home screen widget for android, but don't know how to use buttons. I've followed the tutorial http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html but it doesn't show how to use buttons. Somewhere I read about RemoteViews, PendingIntents and the setOnClickPendingIntent method, but I don't really know how to use them. Therefor, I have some questions: 1) How do I set an onClickListener (or an OnClickPendingIntent() ) for the button? 1,2) where do I set this? There is no onCreate() method.. 2) This method starts an Intent, but how do I use an Intent to just run a method? I do not want to start any activity. Thank you very much - I hope you understand my questions, Best Regards Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Using Buttons in home screen widgets
Thanks for the answer, I have tried working with my code and looking at your widget's source. Event though, I can't get it working. I do not use a service as you, but my code looks like this: package com.kaloersoftware.kaloertimerwidget; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.widget.RemoteViews; import android.widget.Toast; public class KaloerTimer extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Intent i = new Intent(context, KaloerTimer.class); PendingIntent pi = PendingIntent.getBroadcast(context,0, i,0); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.main); rv.setOnClickPendingIntent(R.id.startBtn, pi); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); Toast.makeText(context, It Works, Toast.LENGTH_SHORT).show(); } } Btw, is there any way to debug a widget? Nothing happens when I place a breakpoint in the onUpdate() method. //Kaloer On 11 Jun., 18:35, Mark Murphy mmur...@commonsware.com wrote: I'm trying to develop my first home screen widget for android, but don't know how to use buttons. I've followed the tutorial http://android-developers.blogspot.com/2009/04/introducing-home-scree... but it doesn't show how to use buttons. Somewhere I read about RemoteViews, PendingIntents and the setOnClickPendingIntent method, but I don't really know how to use them. Therefor, I have some questions: 1) How do I set an onClickListener (or an OnClickPendingIntent() ) for the button? In the tutorial you cite, Jeff Sharkey uses setOnClickPendingIntent() for clicks on the widget as a whole. However, that works just as well for clicks just on a button -- provide the button's ID as the first parameter. 1,2) where do I set this? There is no onCreate() method.. You would set it wherever you are building your RemoteViews. 2) This method starts an Intent, but how do I use an Intent to just run a method? I do not want to start any activity. You can't use an Intent to just run a method. However, an Intent does not need to start an activity. Jeff's example uses PendingIntent.getActivity() to launch an activity, but you could use PendingIntent.getService() or PendingIntent.getBroadcast() to communicate with other components. I can point you at some source code for an app widget that demonstrates the use of buttons communicating with a back-end service -- visit: http://commonsware.com/AdvAndroid/ and download the source code to my one book. In the ZIP file, you will find an AppWidget/TwitterWidget project. As the name suggests, it is a widget that displays the latest tweet in your friends' timeline. It also has a button to refresh and a button to configure the widget. The configure button pops an activity, but the refresh button triggers the same logic as is invoked when updateTimeMillis elapses. -- Mark Murphy (a Commons Guy)http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Best way to add 100.000 words to database
I think you are right. I'll look at it, Thank you very much //Kaloer On 2 Jun., 13:05, kaloer mkal...@gmail.com wrote: Btw, this is how the app works: There is a text view and a button. The user will enter a single word, and when he presses the button, the application checks whether this is actually a real word. On 2 Jun., 09:27, kaloer mkal...@gmail.com wrote: It is a list of english words, that shall be used as a spell checker. I have tried to use a txt file and put the data to a List, but this is too slow because it needs to read all the data. But Maybe I should create a table in the database for each letter (and every second, if necessary) , so that it doesn't need to read all the data. On 1 Jun., 18:28, Raphael r...@android.com wrote: This begs to a different kind of question: do you really need to store this data in an sqlite3 database? There are other alternatives, it all depends on your data and how you want to use it so you might want to help us here. Example: you mention words, just not any string, so your data might be a dictionary. Then in this case you could simply use a binary file, in your own format, packaged in your project/res/raw directory, which you can retrieve withhttp://d.android.com/reference/android/content/res/Resources.html#ope...) -- the file is added uncompressed to your APK but the APK itself is a zip file, which is why you get an input stream. That also means if you need direct random access you'll probably want to write it somewhere, such as on the sdcard. Make sure to write an index for fast lookup, for example the offset of words starting by A, by B, etc. You will probably need to experiment a bit to get a tradeof between simplicity of the index and lookup time, e.g. a tree will have faster lookup times but is more tricky to get right, etc. R/ On Sun, May 31, 2009 at 6:11 AM, kaloer mkal...@gmail.com wrote: Okay, I'll look at it.. Thank you very much for your help On 31 Maj, 14:59, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Well, of course I shouldn't. This only adds one line when it's called. Should I call it before the while-loop begins? You're right -- I skimmed it too quickly. It's actually a bit more complicated than that. The flow is: begin-transaction insert 100 rows worth of stuff set-transaction-successful and do that whole block 1000 times for 100,000 words. So you're probably going to wind up with something like: while ((line=input.readLine())!=null) { DB.beginTransaction(); DB.execSQL(...); for (int i=0;i99 (line=input.readLine())!=null; i++) { DB.execSQL(...); } DB.setTransactionSuccessful(); } plus an appropriate try/catch in there. However, bear in mind that this will still take a very long time, so unless you're trying this for educational purposes, I'd move along to one of the other options. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Get unread messages in inbox
Hi, Is it possible to get the unread sms messages? I know that I can get all messages using the content://sms/inbox uri, but how do I check whether it is unread? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Best way to add 100.000 words to database
It is a list of english words, that shall be used as a spell checker. I have tried to use a txt file and put the data to a List, but this is too slow because it needs to read all the data. But Maybe I should create a table in the database for each letter (and every second, if necessary) , so that it doesn't need to read all the data. On 1 Jun., 18:28, Raphael r...@android.com wrote: This begs to a different kind of question: do you really need to store this data in an sqlite3 database? There are other alternatives, it all depends on your data and how you want to use it so you might want to help us here. Example: you mention words, just not any string, so your data might be a dictionary. Then in this case you could simply use a binary file, in your own format, packaged in your project/res/raw directory, which you can retrieve withhttp://d.android.com/reference/android/content/res/Resources.html#ope...) -- the file is added uncompressed to your APK but the APK itself is a zip file, which is why you get an input stream. That also means if you need direct random access you'll probably want to write it somewhere, such as on the sdcard. Make sure to write an index for fast lookup, for example the offset of words starting by A, by B, etc. You will probably need to experiment a bit to get a tradeof between simplicity of the index and lookup time, e.g. a tree will have faster lookup times but is more tricky to get right, etc. R/ On Sun, May 31, 2009 at 6:11 AM, kaloer mkal...@gmail.com wrote: Okay, I'll look at it.. Thank you very much for your help On 31 Maj, 14:59, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Well, of course I shouldn't. This only adds one line when it's called. Should I call it before the while-loop begins? You're right -- I skimmed it too quickly. It's actually a bit more complicated than that. The flow is: begin-transaction insert 100 rows worth of stuff set-transaction-successful and do that whole block 1000 times for 100,000 words. So you're probably going to wind up with something like: while ((line=input.readLine())!=null) { DB.beginTransaction(); DB.execSQL(...); for (int i=0;i99 (line=input.readLine())!=null; i++) { DB.execSQL(...); } DB.setTransactionSuccessful(); } plus an appropriate try/catch in there. However, bear in mind that this will still take a very long time, so unless you're trying this for educational purposes, I'd move along to one of the other options. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Best way to add 100.000 words to database
Btw, this is how the app works: There is a text view and a button. The user will enter a single word, and when he presses the button, the application checks whether this is actually a real word. On 2 Jun., 09:27, kaloer mkal...@gmail.com wrote: It is a list of english words, that shall be used as a spell checker. I have tried to use a txt file and put the data to a List, but this is too slow because it needs to read all the data. But Maybe I should create a table in the database for each letter (and every second, if necessary) , so that it doesn't need to read all the data. On 1 Jun., 18:28, Raphael r...@android.com wrote: This begs to a different kind of question: do you really need to store this data in an sqlite3 database? There are other alternatives, it all depends on your data and how you want to use it so you might want to help us here. Example: you mention words, just not any string, so your data might be a dictionary. Then in this case you could simply use a binary file, in your own format, packaged in your project/res/raw directory, which you can retrieve withhttp://d.android.com/reference/android/content/res/Resources.html#ope...) -- the file is added uncompressed to your APK but the APK itself is a zip file, which is why you get an input stream. That also means if you need direct random access you'll probably want to write it somewhere, such as on the sdcard. Make sure to write an index for fast lookup, for example the offset of words starting by A, by B, etc. You will probably need to experiment a bit to get a tradeof between simplicity of the index and lookup time, e.g. a tree will have faster lookup times but is more tricky to get right, etc. R/ On Sun, May 31, 2009 at 6:11 AM, kaloer mkal...@gmail.com wrote: Okay, I'll look at it.. Thank you very much for your help On 31 Maj, 14:59, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Well, of course I shouldn't. This only adds one line when it's called. Should I call it before the while-loop begins? You're right -- I skimmed it too quickly. It's actually a bit more complicated than that. The flow is: begin-transaction insert 100 rows worth of stuff set-transaction-successful and do that whole block 1000 times for 100,000 words. So you're probably going to wind up with something like: while ((line=input.readLine())!=null) { DB.beginTransaction(); DB.execSQL(...); for (int i=0;i99 (line=input.readLine())!=null; i++) { DB.execSQL(...); } DB.setTransactionSuccessful(); } plus an appropriate try/catch in there. However, bear in mind that this will still take a very long time, so unless you're trying this for educational purposes, I'd move along to one of the other options. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Best way to add 100.000 words to database
Hi, I am developing an application that, as the first thing, puts all lines from a txt-file to a sqlite database. There is about 100.000 words that should be added to the database, and this takes almost an hour to do. Is there a better way to do this, fx. to have a database in the res/ raw resources if it is possible. This is my currently way to do it: public void getWords(final Context context, final InputStream aFile) { try { InputStreamReader reader = new InputStreamReader(aFile, Charset.forName(UTF-8)); BufferedReader input = new BufferedReader(reader); try { DB = context.openOrCreateDatabase(DATABASE_NAME, 1, null); DB.execSQL(DELETE FROM english); String line = input.readLine(); int i = 0; while (( line = input.readLine()) != null){ try { DB.execSQL(INSERT OR IGNORE INTO english(word) VALUES (' + line + ')); } catch (Exception e) { Log.e(kaloer, e.getMessage()); } if(i % 100 == 0) { Log.d(progress, Integer.toString(i)); try { Thread.sleep(100); } catch(InterruptedException e) { } } i++; } } catch (IOException e) { e.printStackTrace(); } finally { try { input.close(); } catch (IOException e) { e.printStackTrace(); } DB.close(); } } return; } Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Best way to add 100.000 words to database
How does the transaction work? I'm new to databases. I found this on the android documentation db.beginTransaction(); try { ... db.setTransactionSuccessful(); } finally { db.endTransaction(); } Should I implement it like this: int i = 0; while (( line = input.readLine()) != null){ if(i % 100 == 0) { DB.beginTransaction(); Try { DB.execSQL(INSERT OR IGNORE INTO english(word) VALUES DB.setTransactionSuccessfull (); } Finally { DB.endTransaction(); } On 31 Maj, 14:13, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Hi, I am developing an application that, as the first thing, puts all lines from a txt-file to a sqlite database. There is about 100.000 words that should be added to the database, and this takes almost an hour to do. Is there a better way to do this, fx. to have a database in the res/ raw resources if it is possible. This is my currently way to do it: public void getWords(final Context context, final InputStream aFile) { try { InputStreamReader reader = new InputStreamReader(aFile, Charset.forName(UTF-8)); BufferedReader input = new BufferedReader(reader); try { DB = context.openOrCreateDatabase(DATABASE_NAME, 1, null); DB.execSQL(DELETE FROM english); String line = input.readLine(); int i = 0; while (( line = input.readLine()) != null){ try { DB.execSQL(INSERT OR IGNORE INTO english(word) VALUES (' + line + ')); } catch (Exception e) { Log.e(kaloer, e.getMessage()); } if(i % 100 == 0) { Log.d(progress, Integer.toString(i)); try { Thread.sleep(100); } catch(InterruptedException e) { } } i++; } } catch (IOException e) { e.printStackTrace(); } finally { try { input.close(); } catch (IOException e) { e.printStackTrace(); } DB.close(); } } return; } 1. Right now, you are doing 100,000 transactions. Wrap your own transaction around the INSERT loop, one for every 1,000 words or something. 2. Create the SQLite database on your development PC and package it as a raw resource or asset. Then, before you need it, copy it from the resource to the appropriate databases/ directory by reading from a raw resource or asset stream. Downside #1: if SQLite ever changes its database format, you're in trouble. Downside #2: you take up double the memory. 3. Create the SQLite database on your development PC and download it off the Internet before first use. Downside: if SQLite ever changes its database format, you're in trouble. 4. Use some other data structure and library than SQLite. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Best way to add 100.000 words to database
Well, of course I shouldn't. This only adds one line when it's called. Should I call it before the while-loop begins? On 31 Maj, 14:47, kaloer mkal...@gmail.com wrote: How does the transaction work? I'm new to databases. I found this on the android documentation db.beginTransaction(); try { ... db.setTransactionSuccessful(); } finally { db.endTransaction(); } Should I implement it like this: int i = 0; while (( line = input.readLine()) != null){ if(i % 100 == 0) { DB.beginTransaction(); Try { DB.execSQL(INSERT OR IGNORE INTO english(word) VALUES DB.setTransactionSuccessfull (); } Finally { DB.endTransaction(); } On 31 Maj, 14:13, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Hi, I am developing an application that, as the first thing, puts all lines from a txt-file to a sqlite database. There is about 100.000 words that should be added to the database, and this takes almost an hour to do. Is there a better way to do this, fx. to have a database in the res/ raw resources if it is possible. This is my currently way to do it: public void getWords(final Context context, final InputStream aFile) { try { InputStreamReader reader = new InputStreamReader(aFile, Charset.forName(UTF-8)); BufferedReader input = new BufferedReader(reader); try { DB = context.openOrCreateDatabase(DATABASE_NAME, 1, null); DB.execSQL(DELETE FROM english); String line = input.readLine(); int i = 0; while (( line = input.readLine()) != null){ try { DB.execSQL(INSERT OR IGNORE INTO english(word) VALUES (' + line + ')); } catch (Exception e) { Log.e(kaloer, e.getMessage()); } if(i % 100 == 0) { Log.d(progress, Integer.toString(i)); try { Thread.sleep(100); } catch(InterruptedException e) { } } i++; } } catch (IOException e) { e.printStackTrace(); } finally { try { input.close(); } catch (IOException e) { e.printStackTrace(); } DB.close(); } } return; } 1. Right now, you are doing 100,000 transactions. Wrap your own transaction around the INSERT loop, one for every 1,000 words or something. 2. Create the SQLite database on your development PC and package it as a raw resource or asset. Then, before you need it, copy it from the resource to the appropriate databases/ directory by reading from a raw resource or asset stream. Downside #1: if SQLite ever changes its database format, you're in trouble. Downside #2: you take up double the memory. 3. Create the SQLite database on your development PC and download it off the Internet before first use. Downside: if SQLite ever changes its database format, you're in trouble. 4. Use some other data structure and library than SQLite. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Best way to add 100.000 words to database
Okay, I'll look at it.. Thank you very much for your help On 31 Maj, 14:59, Mark Murphy mmur...@commonsware.com wrote: kaloer wrote: Well, of course I shouldn't. This only adds one line when it's called. Should I call it before the while-loop begins? You're right -- I skimmed it too quickly. It's actually a bit more complicated than that. The flow is: begin-transaction insert 100 rows worth of stuff set-transaction-successful and do that whole block 1000 times for 100,000 words. So you're probably going to wind up with something like: while ((line=input.readLine())!=null) { DB.beginTransaction(); DB.execSQL(...); for (int i=0;i99 (line=input.readLine())!=null; i++) { DB.execSQL(...); } DB.setTransactionSuccessful(); } plus an appropriate try/catch in there. However, bear in mind that this will still take a very long time, so unless you're trying this for educational purposes, I'd move along to one of the other options. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Open txt file from res/raw
Hi, How do I read a txt-file from the res/raw-directory? Is it possible to get the file's directory, or how do I add it as a File? I guess I should do something like this: Resources myResources = getResources(); File myFile = new File(myResources.openRawResource(R.raw.myFile); But it returns an InputStream. Is it possible to convert this to a File, or get it's directory? Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Open txt file from res/raw
I followed a tutorial that was using a File. I'm new to java and did not know that I could use the InputStream instead. It works now - thank you for making me considering it again.. //Kaloer On 25 Maj, 20:15, Jack Ha (T-Mobile USA) jack...@t-mobile.com wrote: Is there a specific reason why you would like to convert it to a File? -- Jack Ha Open Source Development Center ・T・ ・ ・Mobile・ stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On May 25, 10:57 am, kaloer mkal...@gmail.com wrote: Hi, How do I read a txt-file from the res/raw-directory? Is it possible to get the file's directory, or how do I add it as a File? I guess I should do something like this: Resources myResources = getResources(); File myFile = new File(myResources.openRawResource(R.raw.myFile); But it returns an InputStream. Is it possible to convert this to a File, or get it's directory? Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Open txt file from res/raw
I need to read every line of the txt-file, and I currently have this method: public ListString getWords(File aFile) { ListString contents = new ArrayListString(); try { BufferedReader input = new BufferedReader(new FileReader (aFile)); try { String line = null; while (( line = input.readLine()) != null){ contents.add(line); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents; } I have tried to edit it, but I don't get the data I want. The first entry of the contents-list is #!/usr/bin/env xdg-open and none of them is what the txt-file contains: public ListString getWords(InputStream aFile) { ListString contents = new ArrayListString(); try { BufferedReader input = new BufferedReader(new InputStreamReader (aFile)); try { String line = null; //not declared within while loop while (( line = input.readLine()) != null){ contents.add(line); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents; } Maybe I do something wrong - I'm new to java. On 25 Maj, 20:15, Jack Ha (T-Mobile USA) jack...@t-mobile.com wrote: Is there a specific reason why you would like to convert it to a File? -- Jack Ha Open Source Development Center ・T・ ・ ・Mobile・ stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On May 25, 10:57 am, kaloer mkal...@gmail.com wrote: Hi, How do I read a txt-file from the res/raw-directory? Is it possible to get the file's directory, or how do I add it as a File? I guess I should do something like this: Resources myResources = getResources(); File myFile = new File(myResources.openRawResource(R.raw.myFile); But it returns an InputStream. Is it possible to convert this to a File, or get it's directory? Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Speech recognizing in final 1.5 cupcake
Hi, In the 1.5 pre SDK there was a speech-recognizing feature in the google search widget, but in the final 1.5 I cannot see the icon beside the normal search button. There only is one icon. Does the 1.5 not have this function, or is it my avd there has the wrong target? I'm developing an application that should recognize speech, but it throws an ActivityNotFoundExeption. Is it not possible to develop using this feature? Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Start application when device is on power
Hi, How do I start an application when the device runs on ac-power? It should start when the cable has been plugged in.. Is this possible? Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Remove Bundle savedInstanceState
Hi, How do I remove the savedInstanceState Bundle so that the activity restarts every time it is called? I have some settings that requires the activity to be restarted before they works. I don't want to restart the whole application, but just run the code in my main activity from start every time it is called. Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get preferences from xml/preferences.xml
Hi, thank for your help, I have tried the getBaseContext() method, but I get my application stops unexpectedly. When I debug, I get a RuntimeExeption before I get to the SharedPreferences [...] code. This is what the Debug window says: DalvikVM[localhost:8609] Thread [3 main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2194 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) //Kaloer On 11 Maj, 19:52, Cass Surek cass.su...@gmail.com wrote: You could get the context by calling getBaseContext(). Please be more specific on what exactly does not work as your problem might be in another place. Cass On May 11, 5:28 pm, kaloer mkal...@gmail.com wrote: Hi, How do I get the preferences from the preferences.xml file? I have tried with this code: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences (this); but it does not work. I think the error is coursed by the use of the Context this, because the preferences are set by an other class. How can I access this preferences? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get preferences from xml/preferences.xml
Yeah, thank you very much! It works now. I simply made a method like yours in the main method.. //Kaloer On 11 Maj, 22:43, Cass Surek cass.su...@gmail.com wrote: I had to roll back to version 1.1 due to not being able to use the emulator with sensors, but this works fine for me : private void getPrefs(){ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); this.prefsAudioEnabled = sharedPref.getBoolean (audio_enabled, true); } Placed within the main activity of my application. What is right before the call to the prefs? That could be the culprit. Cass On May 11, 7:18 pm, kaloer mkal...@gmail.com wrote: Hi, thank for your help, I have tried the getBaseContext() method, but I get my application stops unexpectedly. When I debug, I get a RuntimeExeption before I get to the SharedPreferences [...] code. This is what the Debug window says: DalvikVM[localhost:8609] Thread [3 main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2194 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) //Kaloer On 11 Maj, 19:52, Cass Surek cass.su...@gmail.com wrote: You could get the context by calling getBaseContext(). Please be more specific on what exactly does not work as your problem might be in another place. Cass On May 11, 5:28 pm, kaloer mkal...@gmail.com wrote: Hi, How do I get the preferences from the preferences.xml file? I have tried with this code: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences (this); but it does not work. I think the error is coursed by the use of the Context this, because the preferences are set by an other class. How can I access this preferences? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Force alarm sound
Thank you, it works. Yes, I'll let the user choose this feature :) On 9 Maj, 23:35, Raphael r...@android.com wrote: On Sat, May 9, 2009 at 12:31 PM, kaloer mkal...@gmail.com wrote: Hi, Is it possible to force the volume up? I have an alarm that should wake the user even if the phone is on silent mode.. Is that possible? AudioManager manager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); int max = manager.getStreamMaxVolume(AudioManager.STREAM_RING); manager.setStreamVolume(AudioManager.STREAM_RING, new_volume, 0 /*flags*/); See the AudioManager API for more details, especially which stream to use and of course you might have to change the ringer mode, cf manager.setRingerMode(AudioManager.RINGER_MODE_NORMAL). Please be nice to the user: only do so if the user checks a pref to allow your app to modify his/her settings and remember to revert the volume to what it was before ;-) R/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] File picker in preferenceScreen
Hi, How do I show an open file dialog in a preferenceScreen - and is there an open file dialog-intent in android? I need to let the user choose a mp3 file. I can use the RingtonePreference, but then the user needs to add the file as a ringtone. Isn't it possible to show an open file dialog? Thank you very much, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Force alarm sound
Hi, Is it possible to force the volume up? I have an alarm that should wake the user even if the phone is on silent mode.. Is that possible? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] A lot of graphics in drawable-folder
Hi, I have plenty of image files in my drawable folder because my application has different skins. This makes it very unmanageable. But is there a better to organize the graphics, like folders, groups or such things? Or is it a good idea to not use the drawable resource, but instead create a xml file in the application directory for each skin with the image-links? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: A lot of graphics in drawable-folder
Hmm.. Okay. Then I keep using the drawable folder :-) On 8 Maj, 17:18, Romain Guy romain...@google.com wrote: There is no other way at the moment. For what it's worth, the framework's drawables folders contains about 700 files :) On Fri, May 8, 2009 at 7:05 AM, kaloer mkal...@gmail.com wrote: Hi, I have plenty of image files in my drawable folder because my application has different skins. This makes it very unmanageable. But is there a better to organize the graphics, like folders, groups or such things? Or is it a good idea to not use the drawable resource, but instead create a xml file in the application directory for each skin with the image-links? -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Get alarms from Alarm Clock application
Hi, Is it possible to access the alarms from the Alarm Clock application, so i can use them in my application? And can I create an alarm in my application, which is visible in the Alarm Clock app? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get alarms from Alarm Clock application
Okay thank you, I'll look at it .. On 7 Maj, 18:45, Jack Ha (T-Mobile USA) jack...@t-mobile.com wrote: As far as I know, you are able to do that since the Alarm Clock app doesn't expose those specific intents. -- Jack Ha Open Source Development Center ・T・ ・ ・Mobile・ stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On May 7, 5:55 am, kaloer mkal...@gmail.com wrote: Hi, Is it possible to access the alarms from the Alarm Clock application, so i can use them in my application? And can I create an alarm in my application, which is visible in the Alarm Clock app? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Call method from Broadcast Receiver
Hi, Is it possible to call a method that finds a view by id and changes it, from a broadcast receiver? For example: I have the default class that extends Activity and contains a setContentView method. In the layout i have set as the contentView, i have a TextView. Then i have a method that should change the text to something, but this should be called from a broadcast receiver and not in the default class. But when the broadcast receiver-class extends BroadcastReceiver it cannot use the findViewById method because it requires the class to extend the Activiy class. I have tried to initialize the default class, but then the application stops unexpectedly when the broadcast receiver is called. How can i call the method? //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Best way to update clock
Hi, I have a method in my application which updates a clock. But what is the best way to run the method so that it automatically updates the clock? Should i use a Timer (i have heard, that it does not work very well in android) or what should i use? I will be glad if you could please post a simple example :-) Currently the part of my code that contains the thread looks like this, but it does not work (I don't get an exeption, but it simply does not run the updateTime() method.) : public class NightClock extends Activity { private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); ScheduledFuture? updateHandle; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Calendar cal = Calendar.getInstance(); updateTime(); long toTimerStart = ( 60 - cal.get(Calendar.SECOND) ) * 1000; Runnable mUpdateTimeTask = new Runnable() { public void run() { updateTime(); } }; updateHandle = scheduler.scheduleAtFixedRate(mUpdateTimeTask, toTimerStart, 1000, TimeUnit.MILLISECONDS); } Thank you very much! //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get phone number from sms
Hi Avron, Thank you very much, just what i was looking for :) //Kaloer On 19 Apr., 17:05, avrono avr...@mail.com wrote: Kaloer, You need to set a URI to the SMS Inbox Content and then create a cursor (i.e a query to the the SQLLite DB) and iterate over it. If you are in your activity, it would be somthing like this.getContentResolver().query( Uri.parse(content://sms/inbox), null, null, null, null); You then have access to the full SMS content and phone number etc. Hope this helps ! Avron On Apr 18, 8:52 am, kaloer mkal...@gmail.com wrote: Hi, Is it possible to get the phone number of a received sms within code? Look at this example at the if-statement: @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Object messages[] = (Object[]) bundle.get(pdus); SmsMessage smsMessage[] = new SmsMessage[messages.length]; for (int n = 0; n messages.length; n++) { smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages [n]); } if([HOW DO I GET THE NUMBER]) { Toast toast = Toast.makeText(context, New SMS: + smsMessage [0].getMessageBody(), Toast.LENGTH_LONG); toast.show(); } } Thank you very much! Best regards Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Get phone number from sms
Hi, Is it possible to get the phone number of a received sms within code? Look at this example at the if-statement: @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Object messages[] = (Object[]) bundle.get(pdus); SmsMessage smsMessage[] = new SmsMessage[messages.length]; for (int n = 0; n messages.length; n++) { smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages [n]); } if([HOW DO I GET THE NUMBER]) { Toast toast = Toast.makeText(context, New SMS: + smsMessage [0].getMessageBody(), Toast.LENGTH_LONG); toast.show(); } } Thank you very much! Best regards Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Horizontal RadioGroup
Thank you, I already had tried the getOrientation method, but did not know how to use it. But i found out, that you simply write getOrientation(0) for horizontal and getOrientation(1) for vertical :-) //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Change TextView text in code
Hi, I have made a layout in Xml, which includes a TextView. The TextView should show some text that is found in a database. Therefore, i cannot find the text by using the @string/something. How can i define the text from my code, without creating the whole layout in code? My TextView has the id currentRankLabel. I think i shall do something like this: View currentRankText = this.findViewById(R.id.currentRankLabel); currentRankText.setText(some text); Best Regards, Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Change TextView text in code
Thank you! It works now :-) //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Horizontal RadioGroup
Hi! I'm new to Android Developing, and don't know how to list the RadioButtons in a RadioGroup horizontal instead of the default vertical way. Default it is like this: (o) XX (o) XX (o) XX How can i do this: (o) X (o) X (o) X I am doing the layout in code, so please answer using that instead of xml :-) Best Regards Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---