我正在尝试使用从developer.android.com下载的contactList示例代码。 它显示联系人列表但没有显示联系人缩略图?
http://developer.android.com/training/contacts-provider/retrieve-names.html
有时当我滚动整个手机屏幕边框显示红色闪烁线。
编辑: - 找到缩略图未加载的解决方案。这只是android 4.4上的一个问题,以下解决方案解决了这个问题。 NewFromFD failed in nativeDecodeFileDescriptor - Android 4.4
但我仍然遇到这个闪烁的问题。这是堆栈跟踪。
08-27 00:01:15.042 19477-19477/com.example.android.contactslist D/StrictMode﹕ StrictMode policy violation; ~duration=7 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2335 violation=1
at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1130)
at libcore.io.BlockGuardOs.write(BlockGuardOs.java:196)
at libcore.io.IoBridge.write(IoBridge.java:450)
at java.io.FileOutputStream.write(FileOutputStream.java:187)
at java.io.OutputStream.write(OutputStream.java:82)
at com.android.server.ssrm.SSRMUtil.writeSysfs(SSRMUtil.java:135)
at com.android.server.ssrm.CustomFrequencyManagerService.releaseCpuDvfsLock(CustomFrequencyManagerService.java:2334)
at com.android.server.ssrm.CustomFrequencyManagerService.releaseDVFSLockLocked(CustomFrequencyManagerService.java:2029)
at com.android.server.ssrm.CustomFrequencyManagerService.releaseDVFSLock(CustomFrequencyManagerService.java:1958)
at android.os.ICustomFrequencyManager$Stub.onTransact(ICustomFrequencyManager.java:285)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
# via Binder call with stack:
android.os.StrictMode$LogStackTrace
at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1726)
at android.os.Parcel.readExceptionCode(Parcel.java:1447)
at android.os.Parcel.readException(Parcel.java:1416)
at android.os.ICustomFrequencyManager$Stub$Proxy.releaseDVFSLock(ICustomFrequencyManager.java:782)
at android.os.CustomFrequencyManager$CPUDVFSControlRequest.cancelFrequencyRequestImpl(CustomFrequencyManager.java:485)
at android.os.CustomFrequencyManager$FrequencyRequest.cancelFrequencyRequest(CustomFrequencyManager.java:223)
at android.os.DVFSHelper.release(DVFSHelper.java:532)
at android.widget.AbsListView.reportScrollStateChange(AbsListView.java:5456)
at android.widget.AbsListView.onTouchUp(AbsListView.java:4888)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:4605)
at android.view.View.dispatchTouchEvent(View.java:8149)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2140)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2295)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1622)
at android.app.Activity.dispatchTouchEvent(Activity.java:2565)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2243)
at android.view.View.dispatchPointerEvent(View.java:8357)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4778)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4644)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4336)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4393)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
at android.view.ViewRootImp
答案 0 :(得分:0)
我找到了缩略图无法加载的解决方案。
此问题仅在4.4上可见,将文件作为InputStream而不是AssetFileDescriptor打开修复了此问题。
1)用这个替换ContactListFragment.java中的原始函数。
private Bitmap loadContactPhotoThumbnail(String photoData) {
InputStream is = null;
try {
Uri thumbUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
thumbUri = Uri.parse(photoData);
} else {
final Uri contactUri = Uri.withAppendedPath(
Contacts.CONTENT_URI, photoData);
thumbUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
}
is = getActivity().getContentResolver().openInputStream(thumbUri);
if (is != null) {
return BitmapFactory.decodeStream(is);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
我在这里找到了这个解决方案
NewFromFD failed in nativeDecodeFileDescriptor - Android 4.4
但我已根据更新的示例代码更新了该答案。
闪烁是由于StrictMode策略违规造成的,这是从堆栈跟踪中清楚的。 所以要按照以下步骤进行修复