我从XML创建一个RadioGroup
<RadioGroup android:id="@+id/option"
android:layout_width="match_parent"
android:orientation="horizontal"
android:checkedButton="@+id/block_scenario_off"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="0dip"
android:layout_weight="1"
android:text="@string/option1"
android:layout_height="wrap_content"
android:id="@+id/option1"
android:layout_gravity="center|left"
android:onClick="@string/on_click"/>
<RadioButton
android:layout_width="0dip"
android:layout_weight="1"
android:text="@string/option2"
android:onClick="@string/on_click"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/option2"/>
<RadioButton
android:layout_width="0dip"
android:layout_weight="1"
android:text="@string/option3"
android:onClick="@string/on_click"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:id="@+id/option3" />
</RadioGroup>
Run Code Online (Sandbox Code Playgroud)
在Java代码中,我以编程方式检查有关活动创建的第一个(onCreate()),如下所示:
mOption = (RadioGroup) findViewById(R.id.option);
mOption.check(R.id.option1);
Run Code Online (Sandbox Code Playgroud)
但是当显示活动时,不会检查单选按钮.有帮助吗?
我写了一个试图修改电话呼叫状态的应用程序.它在Android 2.2或更低版本上运行良好,但在Android 2.3上抛出异常,因为缺少对android.permission.MODIFY_PHONE_STATE权限的许可(我在AndroidManifest.xml上声明了此权限).任何的想法?以下是异常日志:
01-15 09:14:23.210: ERROR/AndroidRuntime(404): FATAL EXCEPTION: main
01-15 09:14:23.210: ERROR/AndroidRuntime(404): java.lang.RuntimeException: Unable to start receiver test.PhoneReceiver: java.lang.SecurityException: Neither user 10031 nor current process has android.permission.MODIFY_PHONE_STATE.
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1780)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:978)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.os.Looper.loop(Looper.java:123)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at java.lang.reflect.Method.invoke(Method.java:507)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-15 09:14:23.210: …Run Code Online (Sandbox Code Playgroud) 我有一个使用Gradle和Android Studio的库和Android应用程序.我可以将库直接包含在项目中,如下所示
compile project(':library')
Run Code Online (Sandbox Code Playgroud)
因为我不想与库源代码相结合,所以我想将库发布到本地存储库中,以便我可以使用as
compile 'com.mygroup:library:1.0'
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
我是Polymer的新手.我开始编写一个简单的webapp,其中1.用户首先登陆登录页面2.如果用户通过登录,则将用户引导至内容页面
我写了一个元素"登录"
<dom-module id="login">
<template>
<!-- local DOM for your element -->
<p>Username</p>
<input class="paper-font-body2" value="{{email::change}}" type="email">
<br/>
<p>Password</p>
<input class="paper-font-body2" value="{{password::change}}" type="password">
<p>{{errorMessage}}</p>
<iron-ajax
id="ajax"
url=""
method="POST"
on-response="signInResponse"
debounce-duration="300">
</iron-ajax>
<button on-click="signIn">Signin</button>
</template>
</dom-module>
<script>
// element registration
Polymer({
is: "login",
// add properties and methods on the element's prototype
properties: {
// declare properties for the element's public API
email: {
type: String,
value: "username"
},
password: {
type: String,
value: "password"
},
errorMessage: {
type: String,
value: …Run Code Online (Sandbox Code Playgroud) 我使用BroadcastReceiver拦截Android手机上的来电,如下所示
tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Bundle bundle = intent.getExtras();
String number = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Run Code Online (Sandbox Code Playgroud)
在"私人号码"的情况下,我在两个设备上进行了测试,它在HTC Wildfire上显示数字为-1,在Galaxy S上显示为-2.我检查过android.telephony.PhoneNumberUtils但它无法帮助我.
是否有功能或通用方法来检测Android手机上的私人号码?
我有一个项目列表,其中每个项目的.content html值如下所示.
<template is="dom-repeat" items="{{entries}}">
<li><p class="paper-font-body2">{{item.title}}</p>
<div>{{item.content}}</div></li>
</template>
Run Code Online (Sandbox Code Playgroud)
内容字段有点像这样
Hello <strong>Polymer</strong>
Run Code Online (Sandbox Code Playgroud)
它在浏览器中显示为纯文本.如何将其显示为安全的HTML?
编辑:这个问题被提出,但它没有帮助我.
我为我的应用程序使用Android 音效/均衡器API.但是,它限制为5个频段.是否有任何文档/库有助于调整更多频段以实现更精细的均衡器实现?
最新的Android SDK(R22)已删除android.renderscript.RSSurfaceView和android.renderscript.RenderScriptGL类.我们如何在SurfaceView或常规Android View上直接使用RenderScript?
我正在写一个音频播放器,音频时间很短(通常为1-5秒),如下所示
//start media player
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(context, Uri.fromFile(audioCache));
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
stopPlaying(true);
}
});
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
startPlayingTimer();
}
});
mediaPlayer.prepareAsync();
int UI_UPDATE_FREQ = 1000/ 60 + 1;
private void startPlayingTimer() {
playerRunnable = new Runnable() {
@Override
public void run() {
uiHandler.post(updateWaveRunnable);
handler.postDelayed(this, UI_UPDATE_FREQ);
}
};
handler.postDelayed(playerRunnable, UI_UPDATE_FREQ);
}
Runnable updateWaveRunnable = new Runnable() {
@Override
public void run() {
int position = …Run Code Online (Sandbox Code Playgroud) 我迁移到Android studio 3并使用gradle插件v3.0.0-beta6.我想重写输出.apk文件的versionName/vesionCode.我在Android应用模块的build.gradle中使用了以下代码来获取gradle插件2.x.
applicationVariants.all { variant ->
def flavor = variant.mergedFlavor
flavor.versionName="${VERSION_NAME}"
if (variant.buildType.isDebuggable()) {
flavor.versionCode=9999
} else {
flavor.versionCode=Integer.parseInt(gitCommitCount)
}
}
Run Code Online (Sandbox Code Playgroud)
它不适用于gradle插件v3.0.0-beta6.对于versionCode,我使用此Gradle 3.0.0 alpha变体输出问题中的解决方案成功重写了它
当我尝试将文件(图像,音频)上传到S3时偶尔会遇到此异常.这有什么解决方案吗?
配置:Android 4x,5x,aws-android-sdk-s3 2.2.14版.
Unable to execute HTTP request: Write error: ssl=0x9ab52680: I/O error during system call, Connection reset by peer
javax.net.ssl.SSLException: Write error: ssl=0x9ab52680: I/O error during system call, Connection reset by peer
at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:766)
at com.android.okhttp.okio.Okio$1.write(Okio.java:76)
at com.android.okhttp.okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
at com.android.okhttp.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
at com.android.okhttp.okio.RealBufferedSink.write(RealBufferedSink.java:46)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302)
at com.android.okhttp.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
at com.android.okhttp.okio.RealBufferedSink$1.write(RealBufferedSink.java:198)
at com.amazonaws.http.UrlHttpClient.write(UrlHttpClient.java:172)
at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:129)
at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:65)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:360)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4221)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1628)
at net.tandem.ext.aws.AmazonUtil.uploadFile(AmazonUtil.java:131)
at net.tandem.ext.aws.AmazonUtil.uploadFile(AmazonUtil.java:65)
at net.tandem.service.MessageService$2.doInBackground(MessageService.java:323)
at net.tandem.service.MessageService$2.doInBackground(MessageService.java:315)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at …Run Code Online (Sandbox Code Playgroud) 我会创建一个宽度为70%的视图,并使用约束布局对齐其父级的右侧,如下所示
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Hello text"
app:layout_constraintLeft_toRightOf="@+id/guideline"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
TextView始终占用完整的父宽度.知道我做错了什么吗?
android ×10
polymer ×2
telephony ×2
amazon-s3 ×1
audio ×1
build.gradle ×1
c ×1
c++ ×1
equalizer ×1
exception ×1
gradle ×1
io ×1
linux ×1
permissions ×1
phone-call ×1
radio-group ×1
renderscript ×1
surfaceview ×1