我responseEntity喜欢这个:
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
requestHeaders.setContentType(MediaType.valueOf("text/plain;charset=UTF-8"));
HttpEntity requestEntity = new HttpEntity(jsonQuery, requestHeaders);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
//Not in UTF-8!!
logger.debug("result: " + responseEntity.getBody());
Run Code Online (Sandbox Code Playgroud)
但它没有编码UTF-8并产生这样的字符:Soci?.是否有可能UTF-8在restTemplate中以某种方式进行编码或添加编码?
我们如何通过按后退按钮停止从当前片段重新加载前一个片段
前任。好像我们正在从 List-fragment 移动到 Details Fragment 后按下不需要通过使用 Android Jet Pack 和导航架构再次重新加载 List-fragment
<fragment
android:id="@+id/my_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_graph" />
Run Code Online (Sandbox Code Playgroud) 我有一个用户名和密码XML段
<EditText
android:id="@+id/username"
android:hint="@string/username_hint"
android:layout_width="match_parent"
android:maxLength="9"
android:nextFocusDown="@+id/pswd"
android:layout_height="wrap_content">
</EditText>
<EditText
android:inputType="textPassword"
android:hint="@string/password_hint"
android:id="@+id/pswd"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</EditText>
Run Code Online (Sandbox Code Playgroud)
我希望当用户名字段到达第9个字符时,光标焦点会自动跳转到密码字段
我正在自动查看Focus next textview并尝试:
final EditText usr = (EditText) findViewById (R.id.username);
final EditText pswd = (EditText) findViewById (R.id.pswd);
usr.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() == 9) {
pswd.requestFocus();
}
}
@Override
public void afterTextChanged(Editable arg0) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
} …Run Code Online (Sandbox Code Playgroud) 迁移到Firebase后,我测试了使用firebase控制台发送通知它工作正常,但我需要在特定时间发送每日通知,因此我不使用firebase控制台而是使用我以前的cron作业每天发送通知.我改变了https://android.googleapis.com/gcm/send对https://fcm.googleapis.com/fcm/send,但我的设备没有收到任何通知.
有什么方法可以解决这个问题吗?或者我错过了什么?我的cron工作对我仍在使用GCM的设备工作正常.
这是我的代码
function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);
$message = array(
'registration_ids' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,
),
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($message)
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
Run Code Online (Sandbox Code Playgroud)
}
cron android firebase google-cloud-messaging firebase-cloud-messaging
我有JpaRepository:
@Repository
public interface CardReaderRepository extends JpaRepository<CardReaderEntity, Integer > {
}
Run Code Online (Sandbox Code Playgroud)
当我在这个 repo 中执行查询时:
@Query(
value = "SELECT new ir.server.component.panel.response." +
"InvalidCardReaderDataDigestResponse(" +
" cr.driverNumber, cr.exploiterCode, cr.lineCode, " +
" cr.transactionDate, cr.offLoadingDate, " +
" cr.cardReaderNumber, " +
" sum(cr.count) , sum(cr.remind) " +
") " +
"FROM CardReaderEntity cr " +
"WHERE cr.company.id = :companyId " +
"AND cr.status.id in :statusIds " +
"AND cr.deleted = false " +
"AND (:fromDate is null or cr.offLoadingDate >= :fromDate …Run Code Online (Sandbox Code Playgroud) 我正在使用Open MPI编写并行程序.我正在运行Snow Leopard 10.6.4,我通过自制程序包管理器安装了Open MPI .
当我运行我的程序时Open MPI,每个进程报告它的排名为0,并且认为进程总数为1,并且8个进程Open MPI吐出到控制台.
我知道这不是代码问题,因为完全相同的代码将在我学院的计算机实验室的某些Ubuntu机器上按预期编译和运行.我查看了自制软件的bug跟踪器,没有人报告Open MPI软件包存在问题.我不知所措.
//或者将多部分文件保存到DB中的任何其他解决方案.我试过这种方式,但得到错误.
File fileOne = new File("file.getOrignalFileName");//what should be kept inside this method
byte[] bFile = new byte[(int) fileOne.length()];
try {
FileInputStream fileInputStream = new FileInputStream(fileOne);
//convert file into array of bytes
fileInputStream.read(bFile);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
questionDao.saveImage(bFile);
Run Code Online (Sandbox Code Playgroud) 我在这里看了一个Optional类的教程 - https://www.geeksforgeeks.org/java-8-optional-class/,它有以下内容
String[] words = new String[10];
Optional<String> checkNull = Optional.ofNullable(words[5]);
if (checkNull.isPresent()) {
String word = words[5].toLowerCase();
System.out.print(word);
} else{
System.out.println("word is null");
}
Run Code Online (Sandbox Code Playgroud)
我试图通过ifPresent检查Optionalas 来减少行数
Optional.ofNullable(words[5]).ifPresent(a -> System.out.println(a.toLowerCase()))
Run Code Online (Sandbox Code Playgroud)
但是无法进一步获得其他部分
Optional.ofNullable(words[5]).ifPresent(a -> System.out.println(a.toLowerCase())).orElse();// doesn't work```
Run Code Online (Sandbox Code Playgroud)
有办法吗?
我一直试图通过谷歌的FCM发送数据,该数据将在10秒后过期.我的意思是,如果用户在这10秒内未连接到互联网,他将不会收到它.
这是我Javascript将请求发送到FCM的代码:
var http = new XMLHttpRequest();
http.open("POST", "https://fcm.googleapis.com/fcm/send", true);
http.onreadystatechange = function() {};
http.setRequestHeader("Content-type", "application/json");
http.setRequestHeader("Authorization", "key=*****");
http.send(JSON.stringify({
"to": "/topics/all",
"data": {
"Title": "Test",
"areas": "Dan, Ayalon",
},
"android": {
"ttl": "10s" //I've tried also removing the s, and changing the ttl to TTL and time_to_leave
}
}));
Run Code Online (Sandbox Code Playgroud)
问题是我的Android应用程序仍然在2分钟之后收到数据,在那10秒过去之后.(我在这里做的是关闭我的手机网络并在2分钟后将其关闭)
我尝试通过Firebase控制台发送请求,并且它有效...我一分钟后没有收到消息.我在这做错了什么?
谢谢!
更新:我想到了另一个解决方案.也许我会手动发送当前时间,然后我会让客户端检查已经过了多少时间?这听起来像是一个好的解决方案吗?
更新2:我尝试了Google在其文档中提供的每个示例,但没有一个能够正常运行.我还尝试了一百万种其他方式来编写请求但却没有任何效果.我开始觉得它可能是一个错误.我报告了Google,现在我正在等待他们的回复.我会在这里更新他们的回复.
android ×4
firebase ×2
hibernate ×2
java ×2
spring ×2
cron ×1
focus ×1
homebrew ×1
java-8 ×1
javascript ×1
jpa ×1
json ×1
macos ×1
openmpi ×1
optional ×1
postgresql ×1
spring-boot ×1
sql ×1
telegram ×1
telegram-bot ×1