我有一个来自服务器行代码的非常基本的加载映像:
Glide.with(view.getContext()).load(url).placeholder(R.drawable.default_profile).into(view);
出于某种原因,我总是坚持使用显示的占位符而不是真实的图像!
我已经确保传递了一个有效且有效的URL.并且,如果我在没有占位符的情况下使用相同的代码,它可以正常工作
Glide.with(view.getContext()).load(url).into(view);
有什么想法吗?
我跟着这个播放流媒体广播在Android中
在这里它的工作精细但播放器加载位慢点击后我需要等待30秒以上的时间
但是我在控制台中收到此错误
MediaPlayer: setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: http://www.example.com:8000/live.ogg
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1074)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:854)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1087)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1061)
at org.oucho.radio.Player.playLaunch(Player.java:237)
at org.oucho.radio.Playlist.onPostExecute(Playlist.java:98)
at org.oucho.radio.Playlist.onPostExecute(Playlist.java:35)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Run Code Online (Sandbox Code Playgroud)
在链接中您可以看到所有文件,如播放器等
由于此错误,我的流很慢.请任何人帮我这个类型
这里的错误不是.ogg我试过的文件.mp3和Just/live
http://www.example.com:8000/beet.ogg
http://www.example.com:8000/mouthorgan.mp3
http://www.example.com:8000/live
Run Code Online (Sandbox Code Playgroud)
音频正在播放但是在这个错误之后它需要大约30秒的时间有时需要花费太长时间....当我播放它显示此错误然后它连接到服务器..并且播放
请帮我解决这个问题
该resValue方法(或其任何名称)允许您在或中设置资源值. 是否有相应的方法来获取由?设置的资源值?buildTypesproductFlavorsresValue
它似乎productFlavors在之前进行了评估buildTypes,因此resValue设置buildTypes优先.我想在调试版本中将"Debug"附加到应用程序名称,但是我需要获取在产品flavor中设置的值以便附加到它.
编辑:我尝试使用MarcinKoziński建议使用变量,但所有产品口味都在任何构建类型之前进行评估.因此,这不起作用:
android {
String appName = ""
productFlavors {
Foo {
appName = "Foo"
}
Bar {
appName = "Bar"
}
}
buildTypes {
release {
resValue "string", "app_name", appName
}
debug {
resValue "string", "app_name", appName + " Debug"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在buildTypes,appName始终具有最后一个产品风味的价值.因此,在此示例中,所有构建都接收名称"Bar"或 …
我正在尝试使用Retrofit连接到android上的https服务器.这是我的OkHttpClient
@Provides
public OkHttpClient provideContactClient(){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.cipherSuites(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA,
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
.build();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
SSLSocketFactory sslSocketFactory = null;
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
sslSocketFactory = sslContext.getSocketFactory();
}catch (GeneralSecurityException e){
e.printStackTrace();
}
return new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectionSpecs(Collections.singletonList(spec))
.sslSocketFactory(sslSocketFactory)
.authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
if(responseCount(response) >= 5){
return null;
}
String credential = Credentials.basic("user", "pass");
return response.request().newBuilder().header("Authorization", credential).build();
}
})
.build();
} …Run Code Online (Sandbox Code Playgroud) 这是我第一次使用axios而且遇到了错误.
axios.get(
`http://someurl.com/page1?param1=1¶m2=${param2_id}`
)
.then(function(response) {
alert();
})
.catch(function(error) {
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
使用正确的URL和参数,当我检查网络请求时,我确实从我的服务器得到了正确的答案,但是当我打开控制台时,我发现它没有调用回调,而是发现了错误.
错误:网络错误堆栈跟踪:createError @ http:// localhost:3000/static/js/bundle.js:2188:15 handleError @ http:// localhost:3000/static/js/bundle.js:1717:14
我已经定义了一个自定义的网络安全配置,在我的清单包括它作为推荐这里
RES/XML/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
这是我的Android.manifest:
<application android:icon="@drawable/icon"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:persistent="true" >
Run Code Online (Sandbox Code Playgroud)
尝试通过HTTP与127.0.0.1进行通信时,即使有这些更改,我也会在logcat中看到这一点:
08-09 10:50:34.395 30791 3607 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
08-09 10:50:34.397 30791 3607 D NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
08-09 10:50:34.401 30791 3607 W DownloadManager: [647] Stop requested with status HTTP_DATA_ERROR: Cleartext HTTP traffic to 127.0.0.1 not permitted
08-09 10:50:34.402 30791 …Run Code Online (Sandbox Code Playgroud) 上周一切顺利,当我在设备上运行应用程序或使用Genymotion进行模拟时,所有对api的调用都在工作(要么返回数据,要么失败但至少显示一些内容).
我在用
ionic run android
Run Code Online (Sandbox Code Playgroud)
我添加更新全球cordova离子:
npm install -g cordova ionic
Run Code Online (Sandbox Code Playgroud)
因为所有$ http请求都没有处理.当Api仍然正常工作并且CORS完美设置时,我无法得到任何响应.
我找到的唯一方法是使用选项--livereload或-l:
ionic run -l android
Run Code Online (Sandbox Code Playgroud)
我想避免不惜任何代价使用livereload.
我开始使用ionic 1.0.0和cordova lib 4.3.0从头开始创建一个项目.
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $timeout, $http) {
alert('calling api');
// Create an anonymous access_token
$http
.get(domain+'/oauth/v2/token?client_id='+public_id+'&client_secret='+secret+'&grant_type=client_credentials')
.then(function(response){
alert(response.data.access_token);
});
})
Run Code Online (Sandbox Code Playgroud)
所以在使用时:
ionic serve
Run Code Online (Sandbox Code Playgroud)
它正确地警告"调用api"然后响应(该示例的OAuth访问令牌).
但在使用时:
ionic run android
Run Code Online (Sandbox Code Playgroud)
它仅警告'调用api'但似乎不处理http请求.
有人经历过类似的事吗?我对此感到非常头疼.
我是 android 开发的新手,并试图通过改造库在 android 中调用本地 .NET web api 服务。在 IIS 上启动我的 web api 后,我收到此错误无法连接到 localhost/127.0.0.1 android。
当我按照建议的http://themakeinfo.com/2015/04/retrofit-android-tutorial/做同样的事情时,它工作正常,但我的本地主机服务没有从 android 调用
我的服务网址是, http://localhost:52511/api/Values/getAllStudents/5
它也在浏览器中为我提供了 XML 格式的输出。
我也试着用,
public interface gitapi {
@GET("/api/Values/GetProduct/{id}") //here is the other url part.best way is to start using /
public void getFeed(@Path("id") int id, Callback<gitmodel> response);
}
public class gitmodel {
public int studentId;
public String studentName;
public String studentAddress;
}
String API = "http://10.0.2.2:52511";
public void CallService(View view){
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(API).build();
gitapi …Run Code Online (Sandbox Code Playgroud) 这是清单文件
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<application
android:usesCleartextTraffic="true"
android:name=".Dao.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FoundActivity"></activity>
<activity android:name=".LPcapActivity" />
<activity android:name=".RentActivity" />
<activity android:name=".MPxtActivity" />
<activity android:name=".LPanActivity" />
<activity android:name=".LDtileActivity" />
<activity android:name=".TabActivity" />
<activity
android:name=".MainActivity"
android:noHistory="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.stk.android.compapp.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Run Code Online (Sandbox Code Playgroud)
我在 XML 文件夹下创建了 XML 文件(network_security_config.xml)
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">http://121.345.678.90:7744/KBB/Kbblist</domain> …Run Code Online (Sandbox Code Playgroud) 从今天起,每当我尝试登录我的应用程序时,我都会收到 Dio 包抛出的以下错误:SocketException: Insecure socket connections are disallowed by platform: 10.0.2.2
我使用以下设置进行连接:
static BaseOptions options = new BaseOptions(
baseUrl: "http://10.0.2.2:3000", // on android emulator
connectTimeout: 5000,
receiveTimeout: 3000)
Run Code Online (Sandbox Code Playgroud)
因此,类似于(我在 /user/login 处设置了身份验证并正常运行):
var apiLogin = api.dio;
try {
Response response = await apiLogin.post("/user/login",
options: Options(contentType: "application/json"),
data: {"email": email, "password": password});
} on DioError catch (e) {
throw Exception([e]);
}
Run Code Online (Sandbox Code Playgroud)
我有一个在端口 3000 上运行的节点服务器,它连接到(容器化的)mongodb。尝试身份验证时,它立即出现 DioError,我无法在网上的任何地方找到原因。
有谁知道这个错误与什么有关?
编辑[答案]
感谢@lyrics为我指明了正确的方向:从 API 级别 27 及更高级别开始,usesCleartextTraffic 默认为 false,因此阻止传出的 http 请求,需要 HTTPS。
解决方案是将以下内容添加到 AndroidManifest.xml: …