1
目標:Pusher正在使用android 5.0及以上版本,但4.0及以下版本未連接推送服務器。推不工作在Android 4.4.4版本?
我使用下面的代碼
if(Utils.isOnline(mcontext)) {
try {
PusherOptions pOptions = new PusherOptions();
pOptions.setAuthorizer(new HttpAuthorizer(Constants.PUSHER_AUTH_SRC_URL + "/auth.php"));
pusher = new Pusher(Constants.PUSHER_KEY, pOptions);
/* pusher.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange connectionStateChange) {
}
@Override
public void onError(String s, String s1, Exception e) {
}
}, ConnectionState.ALL);*/
pusher.connect();
//com.pusher.client.util.Factory factory;
channel = pusher.subscribe(Utils.getPref(mcontext,"channel_name", ""));
Utils.setPref(mcontext, "OtherUserId", "");
}catch(Exception e){
e.printStackTrace();
}
}
使用搖籃庫低於Commen庫已經嘗試
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile files('libs/afilechooser.jar')
//compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.pusher:pusher-java-client:1.4.0'
//compile 'com.pusher:pusher-websocket-android:0.5.0'
//compile 'org.java-websocket:java-websocket:1.3.1'
//compile 'com.squareup.picasso:picasso:2.1.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
//compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
//compile 'commons-io:commons-io:20030203.000550'
//compile 'org.apache.commons:commons-lang3:3.4'
//compile 'org.slf4j:slf4j-api:1.7.22'
//compile 'org.slf4j:slf4j-simple:1.7.22'
//compile 'com.google.code.gson:gson:2.8.0'
**致命異常:主要**
Process: com.driversafe, PID: 12897
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at com.pusher.client.connection.websocket.WebSocketConnection.<clinit>(WebSocketConnection.java:29)
at com.pusher.client.util.Factory.getConnection(Factory.java:53)
at com.pusher.client.Pusher.<init>(Pusher.java:102)
at com.pusher.client.Pusher.<init>(Pusher.java:83)
at com.driversafe.chat.MessageStatusApiCalling.pusherConnect(MessageStatusApiCalling.java:67)
at com.driversafe.chat.ApplicationLifeCycleHandler.onActivityCreated(ApplicationLifeCycleHandler.java:27)
at android.app.Application.dispatchActivityCreated(Application.java:189)
at android.app.Activity.onCreate(Activity.java:903)
at android.support.v4.app.BaseFragmentActivityDonut.onCreate(BaseFragmentActivityDonut.java:39)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:298)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:84)
at com.driversafe.SplashActivity.onCreate(SplashActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)