当前位置: 编程技术>移动开发
本页文章导读:
▪仅供参考 大图展示其中一小部分 仅供参考 大图显示其中一小部分
如果我有一个很大的图 我想显示一个很小的部分 在其中
可以使用scrollX 和scrollY 我没有测试不对到对错
后来经过测试这两个属性是一个偏移属性 通过计.........
▪ 施用SoundPool播放游戏音效 使用SoundPool播放游戏音效
在Android开发中我们经常使用MediaPlayer来播放音频文件,但是MediaPlayer存在一些不足,例如:资源占用量较高、延迟时间较长、不支持多个音频同时播放.........
▪ 装配或卸载一个apk以及简单发动一个网页 安装或卸载一个apk以及简单发动一个网页
这里可以参看http://www.anddev.org/viewtopic.php?p=23928
权限之类的不比说了
Java:
URL sourceUrl = new URL(/blog_article/source/index.html);
Object data = sourceUrl.getContent();
String fileName = sourceUr.........
[1]仅供参考 大图展示其中一小部分
来源: 互联网 发布时间: 2014-02-18
仅供参考 大图显示其中一小部分
如果我有一个很大的图 我想显示一个很小的部分 在其中
可以使用scrollX 和scrollY 我没有测试不对到对错
后来经过测试这两个属性是一个偏移属性 通过计算偏移来产生所要选择的部分还是可以的 效果还好了 。
[2] 施用SoundPool播放游戏音效
来源: 互联网 发布时间: 2014-02-18
使用SoundPool播放游戏音效
在Android开发中我们经常使用MediaPlayer来播放音频文件,但是MediaPlayer存在一些不足,例如:资源占用量较高、延迟时间较长、不支持多个音频同时播放等。这些缺点决定了MediaPlayer在某些场合的使用情况不会很理想,例如在对时间精准度要求相对较高的游戏开发中。
在游戏开发中我们经常需要播放一些游戏音效(比如:子弹爆炸,物体撞击等),这些音效的共同特点是短促、密集、延迟程度小。在这样的场景下,我们可以使用SoundPool代替MediaPlayer来播放这些音效。
SoundPool(android.media.SoundPool),顾名思义是声音池的意思,主要用于播放一些较短的声音片段,支持从程序的资源或文件系统加载。与MediaPlayer相比,SoundPool的优势在于CPU资源占用量低和反应延迟小。另外,SoundPool还支持自行设置声音的品质、音量、播放比率等参数,支持通过ID对多个音频流进行管理。下面是SoundPool基本使用方法的例子代码:
遗憾的是SoundPool目前存在的问题还比较多,我们需要谨慎使用,尽量避免程序在调用SoundPool过程中出现异常关闭的情况。相信Google在Android的后续版本中会将这些问题修复(或者推出一个功能类似、健壮度更高的API),但是如果你现在就需要使用SoundPool开发你的程序,也许你需要知道这些问题:
1. SoundPool最大只能申请1M的内存空间,这就意味着我们只能使用一些很短的声音片段,而不是用它来播放歌曲或者游戏背景音乐(背景音乐可以考虑使用JetPlayer来播放)。
2. SoundPool提供了pause和stop方法,但这些方法建议最好不要轻易使用,因为有些时候它们可能会使你的程序莫名其妙的终止。还有些朋友反映它们不会立即中止播放声音,而是把缓冲区里的数据播放完才会停下来,也许会多播放一秒钟。
3. 音频格式建议使用OGG格式。在我的小游戏Agile Buddy中,我一开始使用WAV格式的音频文件存放游戏音效。经过反复测试,在音效播放间隔较短的情况下会出现异常关闭的情况(有说法是SoundPool目前只对16bit的WAV文件有较好的支持)。后来将文件转成OGG格式,问题得到了解决。
在Android开发中我们经常使用MediaPlayer来播放音频文件,但是MediaPlayer存在一些不足,例如:资源占用量较高、延迟时间较长、不支持多个音频同时播放等。这些缺点决定了MediaPlayer在某些场合的使用情况不会很理想,例如在对时间精准度要求相对较高的游戏开发中。
在游戏开发中我们经常需要播放一些游戏音效(比如:子弹爆炸,物体撞击等),这些音效的共同特点是短促、密集、延迟程度小。在这样的场景下,我们可以使用SoundPool代替MediaPlayer来播放这些音效。
SoundPool(android.media.SoundPool),顾名思义是声音池的意思,主要用于播放一些较短的声音片段,支持从程序的资源或文件系统加载。与MediaPlayer相比,SoundPool的优势在于CPU资源占用量低和反应延迟小。另外,SoundPool还支持自行设置声音的品质、音量、播放比率等参数,支持通过ID对多个音频流进行管理。下面是SoundPool基本使用方法的例子代码:
public static final int SOUND_EXPLOSION = 1;
public static final int SOUND_YOU_WIN = 2;
public static final int SOUND_YOU_LOSE = 3;
private SoundPool soundPool;
private HashMap<Integer, Integer> soundPoolMap;
private void initSounds() {
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(SOUND_EXPLOSION, soundPool.load(getContext(),
R.raw.explosion, 1));
}
public void playSound(int sound) {
AudioManager mgr = (AudioManager) getContext().getSystemService(
Context.AUDIO_SERVICE);
int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1,
0, 1f);
}
public void update() {
if (isExploding()) {
playSound(SOUND_EXPLOSION);
}
}
遗憾的是SoundPool目前存在的问题还比较多,我们需要谨慎使用,尽量避免程序在调用SoundPool过程中出现异常关闭的情况。相信Google在Android的后续版本中会将这些问题修复(或者推出一个功能类似、健壮度更高的API),但是如果你现在就需要使用SoundPool开发你的程序,也许你需要知道这些问题:
1. SoundPool最大只能申请1M的内存空间,这就意味着我们只能使用一些很短的声音片段,而不是用它来播放歌曲或者游戏背景音乐(背景音乐可以考虑使用JetPlayer来播放)。
2. SoundPool提供了pause和stop方法,但这些方法建议最好不要轻易使用,因为有些时候它们可能会使你的程序莫名其妙的终止。还有些朋友反映它们不会立即中止播放声音,而是把缓冲区里的数据播放完才会停下来,也许会多播放一秒钟。
3. 音频格式建议使用OGG格式。在我的小游戏Agile Buddy中,我一开始使用WAV格式的音频文件存放游戏音效。经过反复测试,在音效播放间隔较短的情况下会出现异常关闭的情况(有说法是SoundPool目前只对16bit的WAV文件有较好的支持)。后来将文件转成OGG格式,问题得到了解决。
[3] 装配或卸载一个apk以及简单发动一个网页
来源: 互联网 发布时间: 2014-02-18
安装或卸载一个apk以及简单发动一个网页
这里可以参看http://www.anddev.org/viewtopic.php?p=23928
权限之类的不比说了
Java:
URL sourceUrl = new URL(/blog_article/source/index.html);
Object data = sourceUrl.getContent();
String fileName = sourceUrl.getFile().substring(fileName.lastIndexOf('/') + 1);
// create/open file in the 'data/data/<app namespace>/files' directory
FileOutputStream fos = openFileOutput(fileName, Context.MODE_PRIVATE);
int read = 0;
byte[] buffer = new byte[512];
BufferedInputStream bis = new BufferedInputStream((InputStream) data);
do{
read = bis.read(buffer);
if(read > 0){
fos.write(buffer, 0, read);
}
}while(read != -1);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
哲理诗关键 装的
<activity android:name=".PackageInstallerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
</activity>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
</activity>
卸载的
<activity android:name=".UninstallerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
2.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://Yoururl.com")));
最新技术文章: