我使用以下代码启动相机,但是,3/4的时间,照片无法保存到内存中.这只发生在Galaxy SIII上.它适用于Nexus S和Nexus One
public void photoNew() {
holdingImage = getContentResolver().insert(MUtil.genImgUri(), new ContentValues());
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Bundle extras = new Bundle();
extras.putParcelable(MediaStore.EXTRA_OUTPUT, holdingImage);
extras.putBoolean("return-data", true);
i.putExtras(extras);
startActivityForResult(i, REQ_PHOTO);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试解析一些HTML代码并检索img标记的内容.我使用以下代码来执行此操作:
Spanned img = Html.fromHtml(sourceText);
Run Code Online (Sandbox Code Playgroud)
当我开始调试并查看Spanned img对象的内容时,我可以看到mSpans包含一个ImageSpan,这个ImageSpans源是正确的url.虽然我在检索源码时遇到了极大的困难.关于从Spanned对象检索ImageSpan的文档非常不清楚.我试过这个方法:
ImageSpan[] spans = img.getSpans(0, img.length(), ImageSpan.class);
Run Code Online (Sandbox Code Playgroud)
但这只会返回一个空数组.
所以要清楚:我想在Spanned对象中检索ImageSpan.
我需要调试我的应用程序,并调试runnable内的代码,并在应用程序中执行一些操作然后再次调试代码,但我不能这样做,我不能做任何操作,调试点立即激活.
代码:
public class UpdateHandler {
public static Handler getHandler() {
if (sHandler == null) {
HandlerThread looper = new HandlerThread("update Handler");
looper.start();
sHandler = new Handler(looper.getLooper());
}
return sHandler;
}
}
UpdateHandler.getHandler().post(new Runnable() {
@Override
public void run() {
update();
}
});
public void update() {
// i put the debug point here .
}
Run Code Online (Sandbox Code Playgroud) 我试图在屏幕上动画卡片.
我的代码看起来像这样:
private void animate(ImageView animationSource, ImageView animationTarget, int animationDuration, int animationDelay) {
int[] animationSourcePosition = {0,0};
int[] animationTargetPosition = {0,0};
animationSource.getLocationInWindow(animationSourcePosition);
animationTarget.getLocationInWindow(animationTargetPosition);
TranslateAnimation cardDealingAnimation = new TranslateAnimation(
Animation.ABSOLUTE,animationSourcePosition[0],
Animation.ABSOLUTE,animationTargetPosition[0],
Animation.ABSOLUTE,animationSourcePosition[1],
Animation.ABSOLUTE,animationTargetPosition[1]);
cardDealingAnimation.setDuration(animationDuration);
cardDealingAnimation.setStartOffset(animationDelay);
animationTarget.startAnimation(cardDealingAnimation);
}
Run Code Online (Sandbox Code Playgroud)
会发生什么,它只是弹出新的地方而不显示中间的位置.有趣的是,在我的一个目标上它有时会显示出来.
通常,单击视图时,文本光标将设置在您单击的位置附近.
我尝试将它始终设置到最后(超过最后一个字符),但除非操作被延迟,否则它什么都不做.
下列:
new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
EditText et = (EditText) v;
et.setSelection(et.getText().length());
}
}
});
Run Code Online (Sandbox Code Playgroud)
不起作用.延迟setSelection部分:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
et.setSelection(et.getText().length());
}
}, 40);
Run Code Online (Sandbox Code Playgroud)
使它工作,但是不好的做法.
还有哪些更好的选择?OnClickListener和OnTouchListener(ACTION_DOWN和ACTION_UP两者)也没有帮助.
是否可以在主屏幕上显示任何类型的通知(来自我的应用程序)?
提前致谢!
我不知道为什么,但我的电池广播接收器不起作用.
AndroidManifest.xml中
<receiver android:name=".BatteryReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BATTERY_CHANGED" />
<action android:name="android.intent.action.BATTERY_LOW" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
BatteryReceiver.java
public class BatteryReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
int level = intent.getIntExtra( "level", 0 );
Log.d("Battery", "level: "+level);
Toast.makeText(context, "Battery low!", Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?我正在使用控制台(telnet)来改变电池电量(电源容量X).
android ×7
animation ×1
breakpoints ×1
debugging ×1
focus ×1
homescreen ×1
html ×1
java ×1
parsing ×1
runnable ×1