2012年2月26日日曜日

send mail

I try to send text by intent.
I make mail address.
String to = new String("xxxxx@gmail.com");
I make subject.
String title = new String("Hello");
I make text contents.
String text = new String("test");
I make Intent and set action.
Intent in = new Intent();
in.setAction(Intent.ACTION_SENDTO);
I set mail address.
in.setData(Uri.parse("mailto:" + to));
I set subject.
in.putExtra(Intent.EXTRA_SUBJECT, title);
I set text contents.
in.putExtra(Intent.EXTRA_TEXT, text);
I send text.
startActivity(in);
source code is here.
Please suggest your android issue by twitter or mail, I would try to clear up your issue.

play mp3

I try to play mp3 music file.
I create MediaPlayer class.
MediaPlayer mP = new MediaPlayer();
I set mp3 file.
mP.setDataSource("/sdcard/music/sample.mp3");
I call prepare() api and start() api.
mP.prepare();
mP.start();
prepare() and setDataSource() need try and catch.
source code is here.
Please suggest your android issue by twitter or mail, I would try to clear up your issue.

2012年2月19日日曜日

SpeechRecognizer

I check SpeechRecognizer class. This class is Speech Recognizing class.
How to get instance is call createSpeechRecognizer(Context);
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
and make listener class,
class MyRecognitionListener implements RecognitionListener {

 @Override
 public void onBeginningOfSpeech() {
  Log.d("Speech", "onBeginningOfSpeech");
 }

 @Override
 public void onBufferReceived(byte[] buffer) {
  Log.d("Speech", "onBufferReceived");
 }

 @Override
 public void onEndOfSpeech() {
  Log.d("Speech", "onEndOfSpeech");
 }

 @Override
 public void onError(int error) {
  Log.d("Speech", "onError");
 }

 @Override
 public void onEvent(int eventType, Bundle params) {
  Log.d("Speech", "onEvent");
 }

 @Override
 public void onPartialResults(Bundle partialResults) {
  Log.d("Speech", "onPartialResults");
 }

 @Override
 public void onReadyForSpeech(Bundle params) {
  Log.d("Speech", "onReadyForSpeech");
 }
 

 @Override
 public void onResults(Bundle results) {
  Log.d("Speech", "onResults");
  ArrayList strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
  for (int i = 0; i < strlist.size();i++ ) {
   Log.d("Speech", "result=" + strlist.get(i));
  }
 }

 @Override
 public void onRmsChanged(float rmsdB) {
  Log.d("Speech", "onRmsChanged");
 }
 
}
the important method is onResults. There is recognized word in "results".
public void onResults(Bundle results) {
 Log.d("Speech", "onResults");
 ArrayList strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
 for (int i = 0; i < strlist.size();i++ ) {
  Log.d("Speech", "result=" + strlist.get(i));
 }
}
I make the listener.
MyRecognitionListener listener = new MyRecognitionListener();
I set listener.
sr.setRecognitionListener(listener);
I start speech recognizing.
sr.startListening(RecognizerIntent.getVoiceDetailsIntent(getApplicationContext()));
onResults() call only once.
I said "english".
logcat printed.
result=リング
result=english
result=ring
result=イング
result=ing
It is OK!
I must have android.permission.RECORD_AUDIO. and network is enable. source code is here. Please suggest your android issue by twitter or mail, I would try to clear up your issue.

2012年2月9日木曜日

Camera Lock again

I found exception at Camera class Lock() API, then my android version up by 2.3.6.
but, I found it to be good !
My androids, NexusOne and xperia ray are ok follow program.
It is point to do MediaRecorder.setVideoSize().
_mediarecorder = new MediaRecorder();
_mediarecorder.setCamera(_camera);
_mediarecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
_mediarecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
_mediarecorder.setVideoSize(640, 480);//Add
_mediarecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
source code is here.
Please suggest your android issue by twitter or mail, I would try to clear up your issue.

2012年2月5日日曜日

get sdcard path.

I get sdcard path.
File file = Environment.getExternalStorageDirectory();
Log.d("test", file.getPath());
result:
/mnt/sdcard
I do "adb shell", and try "cd /sdcard/" but I could move. why ?
source code is here.
Please suggest your android issue by twitter or mail, I would try to clear up your issue.

2012年2月1日水曜日

getNetworkInfo

I try getNetworkInfo().
I get ConnectivityManager class.
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
I get NetworkInfo class, this is TYPE_MOBILE sample.
NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
In Wifi and mobile active, I try setNetworkPrefernce(), I expect change network interface changing. but No change.
cm.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
If you use setNetworkPreference(), you must add CHANGE_NETWORK_STATE feature.
source code is here.
Please suggest your android issue by twitter or mail, I would try to clear up your issue.