我知道有很多这样的帖子,但没有人帮我...
我的宣言:
<receiver android:name="com.myapp.SMSReciever">
<intent-filter android:priority="99999999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
SMSReciever.java
public class SMSReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if ( extras == null ) {
return;
}
Debug.log("launched..");
abortBroadcast();
... huge block of code ...
if ( a lot of bools are true ) {
this.clearAbortBroadcast();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
是的,我有权允许 RECEIVE_SMS
编辑:添加logcat,如果它有助于调试问题:
09-10 16:27:30.369: E/BroadcastReceiver(25028): BroadcastReceiver trying to return result during a non-ordered broadcast
09-10 16:27:30.369: E/BroadcastReceiver(25028): …Run Code Online (Sandbox Code Playgroud) 由于 Android 从他们的 SDK 中删除了自 6.0 以来的 apache Web 客户端,并且我不希望在我的 apk 中包含该库,因此我正在迁移到 HttpURLConnection 方法。
为了测试,我在我的本地服务器上创建了一个 testPost.php,它除了向我的数据库添加一个日志条目外什么都不做,大致如下:
<?php
require_once(__DIR__ . '/db_interface.php');
$conn = connectToDatabase();
$stmt = $conn->prepare('insert into logs(data) values (?)');
$stmt->bind_param(1, $_POST['data']);
$stmt->execute();
$stmt->close();
Run Code Online (Sandbox Code Playgroud)
当我使用旧的 Web 客户端访问它时,工作正常。我的 PC 的网络浏览器也是如此。
现在,当我尝试这个 android 代码时:
HttpURLConnection connection = null;
try {
URL url = new URL("http://192.168.2.221/testPost.php");
connection = (HttpURLConnection) url.openConnection();
//As soon as the debugger steps over the above line, the
//PHP script executes.
//Line below throws IllegalStateException: Already Connected
connection.setDoOutput(true);
...
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 springfox 3.0.0 进行反应式支持,并@EnableSwagger2WebFlux在我的 swagger 配置中使用。
我的招摇配置如下:
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage(basePackage))
.paths(PathSelectors.any())
.build()
.securityContexts(Lists.newArrayList(securityContext()))
.securitySchemes(Lists.newArrayList(apiKey()))
.globalOperationParameters(operationParameters());
}
Run Code Online (Sandbox Code Playgroud)
我有一个简单的控制器,如下所示:
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 3600)
@RestController
@RequestMapping("/")
public class ApiController {
@ApiOperation(value = "get all partners", authorizations = {@Authorization(value = "Bearer")})
@RequestMapping(value = "/partner",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Request succeeded")
})
public Mono<ResponseEntity<Flux<PartnerDTO>>> getAllPartners(
@ApiIgnore ServerHttpRequest httpRequest
) …Run Code Online (Sandbox Code Playgroud)