我已经读过这个stackoverflow线程,我尝试使用该答案中给出的代码来查明我是在模拟器上还是在真实设备上运行我的代码:
import android.content.ContentResolver;
import android.provider.Settings.Secure;
...
mTextView.setText(Secure.getString(getContentResolver(), Secure.ANDROID_ID));
Run Code Online (Sandbox Code Playgroud)
在我的真实设备上它返回"2bccce3 ...",但是在模拟器上它不会返回null,而是一个字符串"bd9f8 ..."
如何从代码中找出仿真器或真实设备的想法将受到高度赞赏
我想显示一个提示应该如何输入日期.对德国来说可能看起来像
"以这种格式输入日期:dd.mm.yyy"
对于美国
"以这种格式输入日期:mm/dd/yyyy"
我明白了
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
Run Code Online (Sandbox Code Playgroud)
我可以将日期转换为与用户的语言环境匹配的格式.但是如何获得提示的日/月/年字符串?
当然,我也希望类似的东西也有时间的暗示.
谢谢你的任何建议.
第一次使用Android的AudioTrack.我创建了一个类AndroidAudioDevice.我用这个构造函数初始化它:
public AndroidAudioDevice( ){ // constructor
Log.i("Audio", "constructor");
int minSize =AudioTrack.getMinBufferSize( SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT );
track = new AudioTrack( AudioManager.STREAM_MUSIC, SAMPLE_RATE,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,
minSize, AudioTrack.MODE_STATIC);
createSample();
track.write( buffer, 0, buffer.length );
};
Run Code Online (Sandbox Code Playgroud)
(SAMPLE_RATE设置为44100).
我的主要活动只是有一个按钮,可以调用
public void playSound(){
track.play();
Log.i("Audio", "playState: " + track.getPlayState());
};
this works find BUT ONLY ONCE! If I press the button again no sound anymore.
Run Code Online (Sandbox Code Playgroud)
BTW:Log.i为播放状态显示"3"
知道为什么这只能工作一次吗?提前致谢
我创建了一个类MySoundPool(我使用这个类作为sigelton,但不认为这是相关的,因为其他所有工作).我正在初始化SoundPool,一个HashMap,并获取AudioManager的上下文.此后我正在加载两个声音.MySoundpool由方法MySoundPool.playSound(int index,float rate)使用,playSound剪辑率为0.5 <= rate> = 2.0执行语句
float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, index, 0, rate);
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.一切正常.不会发生在前一个声音仍在播放时调用playSound,我想在播放新声音之前停止播放.在上面的代码片段之前,我试过了
mSoundPool.stop(mSoundPoolMap.get(index));
Run Code Online (Sandbox Code Playgroud)
和
mSoundPool.autoPause();
Run Code Online (Sandbox Code Playgroud)
没有成功.声音继续发挥到底.任何意见将不胜感激