最近刚把项目忙完。。。。老大为组内添了一台nexus 7,唉~好了,又有事情做了,开始适配吧!!!android程序猿就是苦逼啊~
2、在代码中获取:
1、刷新媒体库广播问题
/**
* 复制到Camera文件夹后要提醒刷新一下媒体数据库,这样图片才能在图库中显示
*/
private void refreshMediaMounted() {
try {
StringBuilder sb = new StringBuilder();
sb.append("file://");
sb.append(Environment.getExternalStorageDirectory());
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(sb.toString())));
} catch (Exception e) {
e.printStackTrace();
}
}
之前是没有try_catch的,发个刷媒体的广播不至于有异常吧,no~ nexus 7就出异常了!!!因为你Permission Denial,没有权限,呵呵(附上异常的打印)
01-13 15:58:45.204: E/AndroidRuntime(9425): FATAL EXCEPTION: main
01-13 15:58:45.204: E/AndroidRuntime(9425): Process: com.l99.bed.ImageFilter, PID: 9425
01-13 15:58:45.204: E/AndroidRuntime(9425): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=9425, uid=10084
01-13 15:58:45.204: E/AndroidRuntime(9425): at android.os.Parcel.readException(Parcel.java:1465)
01-13 15:58:45.204: E/AndroidRuntime(9425): at android.os.Parcel.readException(Parcel.java:1419)
01-13 15:58:45.204: E/AndroidRuntime(9425): at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2373)
01-13 15:58:45.204: E/AndroidRuntime(9425): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1127)
01-13 15:58:45.204: E/AndroidRuntime(9425): at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
2、nexus 7获取设备id的问题
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
s_deviceId = tm.getDeviceId();
if (null == s_deviceId) {
s_deviceId = tm.getSubscriberId();
}
在其他手机上都没有问题,nexus 4上也没问题,但在nexus 7上就无法获得,纠结啊,现在我只能做的就是,为空,我就不给你传得了,具体怎么获取待以后解决吧~ →_→
3、AnimationDrawable在nexus 7问题
聊天中涉及到了发送语音,我是拿AnimationDrawable来做的,打开聊天页面,发几条语音,我勒个去,小伙伴们都惊呆了,怎么还没点,图片自己就轮循播放开了,当发了多条语音后,一看,所有的都处在播放状态。。。。
原来在nexus 7下AnimationDrawable是一加载就自动播放的,和其他设备不一样,唉~ 好奇葩。。。只好在加载后先调一遍stop()方法,来让其停止;
AnimationDrawable用法参考:
1、在drawable资源文件夹添加一个文件
<?xml version="1.0" encoding="utf-8"?>
<!--
根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
根标签下,通过item标签对动画中的每一个图片进行声明
android:duration 表示展示所用的该图片的时间长度
-->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/chatfrom_voice_playing"
android:duration="300">
</item>
<item
android:drawable="@drawable/chatfrom_voice_playing_f1"
android:duration="300">
</item>
<item
android:drawable="@drawable/chatfrom_voice_playing_f2"
android:duration="300">
</item>
<item
android:drawable="@drawable/chatfrom_voice_playing_f3"
android:duration="300">
</item>
</animation-list>
2、在代码中获取:
public class MainActivity extends Activity implements OnClickListener{
private ImageView mImage;
private AnimationDrawable mAnim;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImage = (ImageView) findViewById(R.id.image);
mAnim = (AnimationDrawable) mImage.getDrawable();
}
@Override
public void onClick(View v) {
if(mAnim.isRunning()) mAnim.stop();
mAnim.start();
}
}
附上layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:padding="10dp"
android:text="start" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/chat_audio_from_animation"/>
</RelativeLayout>