tl; dr:如何在提供活动配置文件的同时基于基于注释的配置类创建Spring上下文?
我正在尝试使用具有使用注释指定的配置的类来创建Spring上下文.
org.springframework.context.ApplicationContext context =
new org.springframework.context.annotation.AnnotationConfigApplicationContext( com.initech.ReleaserConfig.class );
Run Code Online (Sandbox Code Playgroud)
但是当它启动时崩溃,因为它无法找到所需的bean,但该bean确实存在:尽管只在某个配置文件下"myProfile".
如何指定活动配置文件?我有一种感觉,我需要使用一个org.springframework.context.annotation.AnnotationConfigApplicationContext(org.springframework.beans.factory.support.DefaultListableBeanFactory)构造函数,但我不确定哪些是合适的.
PS-我没有使用Spring Boot,但是在Spring 4.2.4.RELEASE上.
我正在制作一个应用程序,我必须在其中记录用户的电话并转换他的声音以检查用户结束词并对这些结束词执行操作。我无法录制电话,如果有人知道如何录制电话,请帮助我。
提前致谢。
String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
File sampleDir = new File(Environment.getExternalStorageDirectory(), "/Test");
if (!sampleDir.exists()) {
sampleDir.mkdirs();
}
String file_name = "Record";
try {
audiofile = File.createTempFile(file_name, ".amr", sampleDir);
} catch (IOException e) {
e.printStackTrace();
}
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
// recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
Run Code Online (Sandbox Code Playgroud)
我已使用此代码录制语音通话,但对我不起作用。
我正在制作一个应用程序,我必须将双卡电话号码保存到数据库中。我需要这些信息,因为当用户设置他的日程安排时,我必须对这些数字触发操作。但是我搜索了很多,但使用电话管理器只找到了一个 SIM 号码。电话管理器只返回 line1Number 但我需要两个 SIM 卡号码。如果有人知道请解决我的问题。提前致谢。
我已经使用了这个代码,但它只返回 line1Number。
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Run Code Online (Sandbox Code Playgroud) 我正在尝试做类似的事情:
def foo(mode= :serial)
if (mode == :serial) then
self.send(:bar, "one_type")
else
self.send(:bar,"second_type",:T5)
end
end
Run Code Online (Sandbox Code Playgroud)
我显然可以这样输入。
但我最近尝试将其扩展为包含这样的第二个功能:
def foo(mode= :serial)
if (mode == :serial) then
self.send(:bar, "one_type")
self.send(:foobar, "one_type",20)
else
self.send(:bar,"second_type",:T5)
self.send(:foobar, "one_type",20,:T5)
end
end
Run Code Online (Sandbox Code Playgroud)
我仍然可以按原样继续,但我对自己想,这里有一个模式,我应该将参数抽象到另一个层中并使这更简单。
所以我想做的是这样的:
arg_arr = [:bar, "one_type"]
arg_arr_2 = [:foobar, "one_type", 20]
if (mode == :serial) then
self.send(arg_arr)
self.send(arg_arr_2)
else
arg_arr << :T5
arg_arr2 << :T5
self.send(arg_arr)
self.send(arg_arr2 )
end
Run Code Online (Sandbox Code Playgroud)
我尝试了一些涉及 .each、.inspect 的其他想法,但没有任何效果(通常的错误是无法将数组转换为字符串,我猜这是指它将数组视为整个函数名称的事实) . 如果我明确说“使用数组元素[0]、[1]等,我可以做到,但这似乎很浪费。
有没有办法在不编写硬编码到参数数量的代码的情况下实现这一目标?
我有一些帖子ID,我想从同一个网址设置这些帖子的特色图片.
这是我添加的邮政编码:
$catid = get_cat_ID("XX Cat");
$my_post = array();
$my_post['post_title'] = $title;
$my_post['post_content'] = $description;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array( $catid );
$post_id = wp_insert_post( $my_post );
Run Code Online (Sandbox Code Playgroud)
示例:post_id = 1我想将精选图像设置为:example.com/image.png
我怎样才能做到这一点?
我有以下渐变
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:centerColor="#42f448"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#000000"
android:startColor="#000000"
android:type="linear" />
Run Code Online (Sandbox Code Playgroud)
我需要做的是基于ListView上的位置更改来更改渐变的中心。是否可以通过编程方式创建此渐变?
我已经尝试过这种方法,但是如果我更改中心值,则什么也没有发生,它将保持不变:
int colors[] = {0xff000000, 0xff42f448, 0xff000000};
GradientDrawable shape = new GradientDrawable();
shape.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM);
shape.setColors(colors);
shape.setGradientCenter(0.3f, 0.3f);
view.setBackgroundDrawable(shape);
Run Code Online (Sandbox Code Playgroud)
我想念什么?谢谢。
我意识到这个问题出现在 SO 的其他地方,但是我已经尝试了我可以在网站上找到的所有解决方案,但仍然遇到困难。这些问题(和他们的回答)也已经有好几年了,与其对旧问题发表评论,我想我会在这里为其他人整合信息,并调查从那时到现在与 Android 相关的潜在变化。不过,如果您觉得这个问题有资格作为重复,请将其标记为重复。
编辑:正如我所说,关于 SO 的其他答案并没有解决问题。我不明白用“对我不起作用”来评论每一个潜在的修复如何有助于帮助自己和其他人解决问题,但如果是这样,那就这样吧。作为参考,有 3 个人将这些问题标记为可能与此问题重复,因此我将这些无效的答案添加到下面的列表中。
我的应用程序有一些非常具体的需求,但为了简洁起见,让我们假设我需要手动将系统时间和日期设置为固定值。下面我详细说明了我在尝试使其工作的过程中取得的一些进展。
该应用程序的最低 SDK 版本为 24,并且目标是 24。其他人发现他们需要将版本增加到这个级别。
设备已root,应用程序正在安装到/system/app,以便我可以更改日期/时间。
有人评论说,应用程序完全不可能设置时间,但是查看诸如 ClockSync 之类的应用程序,情况似乎并非如此。我知道我的应用程序将无法在 Play 商店中使用。
该应用程序必须在没有用户输入的情况下自动设置日期/时间,因此使用以下代码让用户设置它无济于事;
startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));
Run Code Online (Sandbox Code Playgroud)
我以两种方式将设置时间权限添加到清单中,单独添加,然后一起添加。我还尝试添加有关删除 maxSDKversion 的部分。
<uses-permission android:name="android.permission.SET_TIME" tools:remove="android:maxSdkVersion" />
<permission android:name="android.permission.SET_TIME"
android:protectionLevel="signature|system"/>
Run Code Online (Sandbox Code Playgroud)
我读过某些权限不仅需要清单条目,还需要用户接受和允许它们。但是,SET_TIME 并未列在其中。无论如何,我确实尝试过这样做,但是我的许可请求被自动拒绝而没有显示确认框,可能是因为它实际上并不首先需要许可。
我用来尝试设置时间的代码如下:
try {
Calendar c = Calendar.getInstance();
c.set(2017, 11, 21, 12, 32, 30);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setTime(c.getTimeInMillis());
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
失败时我在祝酒中收到的错误是:
java.lang.securityexception: setTime: neither user 10051 nor current process has …Run Code Online (Sandbox Code Playgroud) 我们有一个 Android 应用程序,我们需要以编程方式通过蓝牙在 2 个设备之间建立连接。
String macAddress = android.provider.Settings.Secure.getString(getApplicationContext().getContentResolver(), "bluetooth_address");
Run Code Online (Sandbox Code Playgroud)
但是,上述代码在 Android Oreo 和 Pie 中不再起作用。
有人有解决此问题的方法吗?
到目前为止,我一直在使用反射,因此更新了 editTexts 的选择句柄。在我更新到目标 api 29(Q) 之前,它一直工作正常。
似乎 Google 做了一些更新(或 Java,不完全确定),但我现在收到如下消息:
访问隐藏字段 Landroid/widget/Editor;->mDrawableForCursor:Landroid/graphics/drawable/Drawable; (暗灰名单,反射)
从好的方面来说,api 29(多年后)具有以编程方式设置手柄颜色的稳定方式。不幸的是,它并没有像我发现的那样向后兼容,而且它也破坏了 api 28。低于 api 28 的任何东西都可以通过反射正常工作。在我现在适用于除 api 28 之外的任何代码的代码下方
/**
* Sets the color for the cursor and handles on the {@link EditText editText}.
*
* @throws EditTextTintError if an error occurs while tinting the view.
*/
public void apply() throws EditTextTintError {
try {
// Get the editor
Field field = TextView.class.getDeclaredField("mEditor");
field.setAccessible(true);
Object editor = field.get(editText);
if (cursorColor != null) {
editText.setHighlightColor(ColorUtils.setAlphaComponent(cursorColor, 40));
// …Run Code Online (Sandbox Code Playgroud) 标题是,问题是如何从我的应用程序以编程方式打开蓝牙设置?我检查了stackoverflow上的所有答案,甚至没有一个在iOS 11中工作正常.所有这些都是旧的答案是低于11或没有答案.我所能做的只是带我进入常规设置或应用程序设置,但我希望用户可以直接进入蓝牙设置,这样他就可以打开它.
let alert = UIAlertController(title: "Bluetooth is off", message: "Please turn on your bluetooth", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Go to settings", style: UIAlertActionStyle.default, handler: { (action) in
switch action.style {
case .default:
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting
let app = UIApplication.shared
app.openURL(url!)
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destrucive")
}
Run Code Online (Sandbox Code Playgroud)
我尝试了更多,也没有结果:
UIApplication.shared.openURL(NSURL(string: "prefs:root=General&path=Bluetoth")! as URL)
Run Code Online (Sandbox Code Playgroud)
要么:
let url = URL(string: "App-Prefs:root=Bluetooth")
Run Code Online (Sandbox Code Playgroud)
以上都不起作用
programmatically ×10
android ×6
bluetooth ×2
java ×2
date ×1
gradient ×1
image ×1
ios ×1
mac-address ×1
phone-call ×1
phone-number ×1
php ×1
ruby ×1
spring ×1
swift ×1
time ×1
wordpress ×1