public void showResponse() { runOnUiThread(new Runnable() { // from class: com.zj.lx.activity.MainActivity.2 @Override // java.lang.Runnable public void run() { if (ContextCompat.checkSelfPermission(MainActivity.this, "android.permission.READ_CONTACTS") != 0) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_CONTACTS"}, 1); } else { try { String information = new ContactType(MainActivity.this).getInformation(); if (information != null) { MainActivity.this.tv_show.setText(SecurityCore.encrypt(information)); MainActivity.this.img_bj.setVisibility(8); } else { MainActivity.this.tv_show.setText(MainActivity.this.rc4.encrypt("{\"name\":\"2\",\"mobileEmail\":\"09876543210\",\"phoneNumber\":\"09876543210\"}", MainActivity.rc4_key)); MainActivity.this.img_bj.setVisibility(8); } } catch (JSONException e) { e.printStackTrace(); } catch (Exception e2) { e2.printStackTrace(); } } Toast.makeText(MainActivity.this, "请求数据成功", 0).show(); } }); } }
时间: 2024-02-10 11:27:56 浏览: 35
这段代码是一个 Android 应用程序中的方法 `showResponse()` 的实现。在这个方法中,通过调用 `runOnUiThread()` 方法在主线程上运行一个匿名的 `Runnable` 对象。
在 `run()` 方法中,首先检查当前应用是否具有读取联系人权限。如果没有权限,则调用 `requestPermissions()` 方法请求获取读取联系人权限。如果已经具有权限,则执行以下逻辑:
1. 通过 `ContactType` 类获取联系人信息,并将其存储在 `information` 字符串中。
2. 检查 `information` 是否为空。如果不为空,则使用 `SecurityCore.encrypt()` 方法对其进行加密,并将结果设置为 `tv_show` 控件的文本内容。同时隐藏 `img_bj` 控件。
3. 如果 `information` 为空,则使用 `MainActivity.rc4_key` 作为密钥,使用 `MainActivity.rc4.encrypt()` 方法对预先定义的 JSON 字符串进行加密,并将结果设置为 `tv_show` 控件的文本内容。同时隐藏 `img_bj` 控件。
最后,在主线程中显示一个 Toast 通知,提示请求数据成功。
请注意,上述代码片段是从您提供的代码中提取的,并且可能缺少一些上下文信息。如果您有任何其他问题,请随时提问。
相关问题
Java实现美团验劵功能
美团验劵功能的实现可以分为以下几个步骤:
1. 用户输入优惠券码,并提交验证请求。
2. 服务端接收到优惠券码,查询数据库判断优惠券码是否有效。
3. 如果优惠券码无效,则返回错误信息;如果有效,则返回优惠券的详细信息给客户端。
4. 客户端展示优惠券的详细信息给用户。
下面是一个简单的 Java 实现示例:
1. 用户提交优惠券码验证请求:
```
// 假设用户提交的优惠券码为 code
String code = "XXXXX";
// 构建请求 URL
String url = "http://your_server/check_coupon?code=" + code;
// 发送 HTTP 请求获取响应
String response = sendHttpRequest(url);
// 解析响应,展示给用户
showResponse(response);
```
2. 服务端接收到请求并验证优惠券码:
```
// 假设使用 JDBC 连接数据库,查询优惠券码是否有效
String code = request.getParameter("code");
String sql = "SELECT * FROM coupons WHERE code = ?";
Connection conn = DriverManager.getConnection("jdbc:mysql://your_database", "username", "password");
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, code);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
// 优惠券码有效,返回详细信息
String couponName = rs.getString("name");
int discount = rs.getInt("discount");
String response = "恭喜您,优惠券 " + couponName + " 有效,可享受 " + discount + " 折优惠!";
out.print(response);
} else {
// 优惠券码无效,返回错误信息
String response = "抱歉,该优惠券码无效!";
out.print(response);
}
```
3. 客户端展示优惠券的详细信息给用户:
```
// 假设展示优惠券详细信息的控件为 TextView
TextView textView = findViewById(R.id.text_view);
textView.setText(response);
```
编写一段HTML代码 可以在ipad打开 首先输出一段文字 "是否还生气" 下面两个按钮 一个为“是” 一个为“否” 如果选择“是” 输出文本框 内容为“不要生气了,请选择否” 并且有一个“返回上一页面”的按钮 功能是返回上一个页面 如果选择“否” 输出文本框 内容为“感谢”
以下是一个可以在iPad上打开的HTML代码,实现了您描述的功能:
```html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>是否还生气</title>
</head>
<body>
<h1>是否还生气</h1>
<button onclick="showResponse(true)">是</button>
<button onclick="showResponse(false)">否</button>
<div id="responseContainer"></div>
<script>
function showResponse(isAngry) {
var responseContainer = document.getElementById("responseContainer");
if (isAngry) {
responseContainer.innerHTML = '<input type="text" value="不要生气了,请选择否"><br>' +
'<button onclick="goBack()">返回上一页面</button>';
} else {
responseContainer.innerHTML = '<input type="text" value="感谢">';
}
}
function goBack() {
window.history.back();
}
</script>
</body>
</html>
```
您可以将上述代码保存为一个名为`index.html`的文件,并在iPad上打开该文件,即可看到相应的界面和功能。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)