[android-developers] MediaPlayer and IllegalStateException

2011-06-30 Thread John-Z80
I've try to copy a very small and easy sample of using MediaPlayer
(for example in http://developer.android.com/guide/topics/media/index.html)
but I dont know the reason I get an IllegalStateException.

Code can be sumarized as:
MediaPlayer mp = MediaPlayer.create(myclass_name_here.this,
R.raw.clip);
boolean error=true;
try {
mp.prepare();
error=false;
} catch (IOException ioe) {
Log.w(Player,Error: +ioe.getMessage());
}
if(!error) {
mp.start();
}

I have a raw directory under res, it has the clip.mp3 file, I've
check the file is ok, so why I get a java.lang.IllegalStateException
in  mp.prepare(); I've tested in 2 different android phones.

Best regards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Read Barcode

2010-11-15 Thread John-Z80
The best way is to install the BarcodeScanner application from google
(it's free on the market), then you can call it with an Intent, and
get the results back in a String.

Something like:
Call the QRCOde:
Intent intent = new Intent(com.google.zxing.client.android.SCAN);
intent.putExtra(SCAN_MODE, QR_CODE_MODE);
startActivityForResult(intent, CODE_ACTIVITY_QR);

in the onActivityResult:
String contents = intent.getStringExtra(SCAN_RESULT);
contents will have the content of the qrcode.



On 15 nov, 07:56, David Toledo dtole...@gmail.com wrote:
 Hi All

 Exist some way from read the  barcode using the android sdk ?

 Thanks
 David

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: LocationListener and getLastKnownLocation

2010-11-15 Thread John-Z80
Yes the onCreate is called always when the application starts (I've
even tried to uninstall application and install again), but the
getLastKnownLocation does not return the previous positions taken by
my application (positions captured by the activity listener), one
workaround could be to store last position in a preferences file but,
why is not returning getLastKnownLocation  the last position recorded
by the mobile? do I have to do anythimg with the position when it
arrives to my listener so getLastKnownLocation knows about it? what am
I missing?

Best regards.


On 12 nov, 17:20, Frank Weiss fewe...@gmail.com wrote:
 How is the position being passed from the onCreate method to your
 application? I suspect when you restart you app, onCreate is not being
 called. You may need to save it in the savedInstanceState.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] LocationListener and getLastKnownLocation

2010-11-12 Thread John-Z80
In one application, when an activity start I use the
getLastKnownLocation to get the last know position, using something
like:
Location
position=mlocManager.getLastKnownLocation(mlocManager.getBestProvider(new
Criteria(), true));
(in the onCreate)

After this, my application register a listener in the onResume() (and
removes it in the onPause()), something like:

   protected void onPause() {
if(mlocManager!=null) mlocManager.removeUpdates(this);
super.onPause();
}

protected void onResume() {
if(mlocManager!=null)
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
6, this);
super.onResume();
}

And it works ok, I get new position, the problem is that when I close
my application and after some time I restart it and I get the last
know location again it does not take any of the positions I got with
my application.
Why does the mobile does not store these position like the lastknow
positions?
do I have to do anythig more?

(if the problem is not clear this is the time sequence of an example)
Start app, getLastKnownLocation it's from 10:00 for example now it's
12:00
register listener, I got wifi or gps positions until 13:00
close the application, start again and getLastKnownLocation and I got
no position... why?

Regards. Gabi.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: setScaleType for an ImageButton

2010-11-12 Thread John-Z80
Perhaps you want to sacle the image to fit the button, something
like:
The image is in Bitmap bm
int width = bm.getWidth();
int height = bm.getHeight();
int newWidth = 32;
int newHeight = 32;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0,
width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
 
((ImageButton)this.findViewById(R.id.Yourbutton)).setImageDrawable(bmd);

I hope this helps you, this code works great for me to do the task of
scale an image to a size (in the sample 32x32 as you request)

Best regards.
Gabi.


On 12 nov, 01:26, Bret Foreman bret.fore...@gmail.com wrote:
 I'm using the following code, which I expect would scale the
 associated image to fit within the given dimensions of the button:

                                 ImageButton.setMaxHeight(32);
                                 ImageButton.setMaxWidth(32);
                                 
 ImageButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                 
 editButton.setImageResource(R.drawable.ic_menu_edit);

 The image is 64X64 and I was expecting to see 32X32 on the screen.
 However, the button draws with the original 64X64 size. I can re-
 sample the image down and create a new file but I'm curious why this
 approach didn't work.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: setScaleType for an ImageButton

2010-11-12 Thread John-Z80
Sorry the first line should be scale not sacle :-)

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Read from sdcard problem (version 1.6)

2010-08-13 Thread John-Z80
Hello I'm trying to make a photo calling the CAMERA Intent an after
returning to my application read the file, but altough I get a File
like /sdcard/DCIM/camera/.jpg if I try to open the file, it exist
and can be read (check with File.exist or File.canread BUT the length
of the file is always 0...

More or less my code is:
call the camera intent like:
Uri imageUri =
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)

in the onActivityResult I do this:

get the File from the Uri, something like (cutpaste from internet):
Cursor cursor = null;
try {
String [] proj={MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID,
MediaStore.Images.ImageColumns.ORIENTATION};
cursor = activity.managedQuery( imageUri, proj, null, null,
null);
int file_ColumnIndex =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
int orientation_ColumnIndex =
cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION);
if (cursor.moveToFirst()) {
String orientation =
cursor.getString(orientation_ColumnIndex);
return new File(cursor.getString(file_ColumnIndex));
}
return null;
} finally {
if (cursor != null) {
cursor.close();
}
}

So I get a File like /sdcard/DCIM/Camera/X.jpg
So if I do:
file.exists()  -- true
file.canRead() -- true
file.length()  -- 0 !!!
So I cant read the file from sdcard (if I try to ignore the size and
simply open a FileInputStream and read it reads of course 0 bytes...


So where is the problem?
I'm stuck on this...

Best regards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Read from sdcard problem (version 1.6)

2010-08-13 Thread John-Z80
One interesting detail, the code (and some variants tryint to use
Bitmap and BitmapFactory...) did not work in a 1.6 android Tattoo
mobile, BUT I've just tried in a magic (1.6 version too) and another
Android mobile (2.1 version) and the above code WORKED.
Tried in another Tattoo from another frined with another mobile
operator and did not work.

So, perhaps there is some problem with sdcard files in Tattoo?
Or there is another way to do the job that perhaps will work in
Tattoo???

Best regards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Textview with graphic (dynamically changing) inside.

2010-02-04 Thread John-Z80
Hello, I've a TextView that in the onCreate is build with an image to
the left from the static drawables, and with a text in the right.

I want to dynamically change the text and the image, (and maintain the
same image size), I have the image stored in a Bitmap named bm, (yes I
know I could change to a ImageButton and a textview but it has better
layout and I want to know if it's possible what I try to do, the way I
try)

I've tried different thing like:
Option 1:
TextView tv=(TextView)this.findViewById(R.id.TextView01);
BitmapDrawable bmd=new BitmapDrawable(bm);
tv.setCompoundDrawables(bmd.getCurrent(), null, null, null);
With this option the text remains inteact but NO image is draw...

Option 2:
the same but the end line is
tv.setBackgroundDrawable(bmd.getCurrent());
The Textview resizes to the image size and the image is draw and the
text is hidden by the image, not the desired behaviour... :-P

Option 3:
trying with canvas like:
Canvas can = new Canvas(bm);
Drawable d=tv.getBackground();
d.draw(can);
I got an exception so this is far from the solution...


Please any ideas of how can I achieve this?


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en