我在Neura中找到了auth的例子,然后创建了一个活动并粘贴了这段代码:
public class NeuraActivity extends AppCompatActivity {
private NeuraApiClient mNeuraApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_neura);
Builder builder = new Builder(getApplicationContext());
mNeuraApiClient = builder.build();
mNeuraApiClient.setAppUid("APP_UID");
mNeuraApiClient.setAppSecret("APP_SECRET"); //here is my app secret, I dont want to show it
mNeuraApiClient.connect();
auth();
}
public void auth() {
mNeuraApiClient.authenticate(new AuthenticateCallback() {
@Override
public void onSuccess(AuthenticateData authenticateData) {
Log.i(getClass().getSimpleName(), "Successfully authenticate with neura. " +
"NeuraUserId = " + authenticateData.getNeuraUserId() + " " +
"AccessToken = " + authenticateData.getAccessToken());
//If you're using firebase for receiving the moment, make sure to call this method.
//Plus, make sure you've registered your firebase server key for your project in our dev site :
//https://dev.theneura.com/docs/guide/android/pushnotification
//If you're putting this code in an activity : ACTIVITY_CONTEXT = YourActivityName.this.
//If you're putting this code in an fragment : ACTIVITY_CONTEXT = getActivity()
mNeuraApiClient.registerFirebaseToken(NeuraActivity.this,
FirebaseInstanceId.getInstance().getToken());
ArrayList<EventDefinition> events = authenticateData.getEvents();
//Subscribe to the events you wish Neura to alert you :
for (int i = 0; i < events.size(); i++) {
mNeuraApiClient.subscribeToEvent(events.get(i).getName(),
"com.chopikus.schoolhelperse" + events.get(i).getName(),
new SubscriptionRequestCallbacks() {
@Override
public void onSuccess(String eventName, Bundle bundle, String s1) {
Log.i(getClass().getSimpleName(), "Successfully subscribed to event " + eventName);
}
@Override
public void onFailure(String eventName, Bundle bundle, int i) {
Log.e(getClass().getSimpleName(), "Failed to subscribe to event " + eventName);
}
});
}
}
@Override
public void onFailure(int i) {
Log.e(getClass().getSimpleName(), "Failed to authenticate with neura. "
+ "Reason : " + SDKUtils.errorCodeToString(i));
}
});
}
}
这是我的gradle依赖项:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// this line must be included to integrate with Firebase
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.koushikdutta.ion:ion:2.+'
compile 'com.github.barteksc:android-pdf-viewer:2.5.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.kenglxn.QRGen:android:2.2.0'
compile 'me.dm7.barcodescanner:zxing:1.9'
compile 'com.google.zxing:core:3.2.1'
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.1'
compile 'com.afollestad.material-dialogs:core:0.9.4.5'
compile 'com.github.clans:fab:1.6.2'
compile 'com.google.android.gms:play-services-auth:11.0.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.github.chrisbanes:PhotoView:2.0.0'
compile 'me.grantland:autofittextview:0.2.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.theneura:android-sdk:+'
testCompile 'junit:junit:4.12'
}
当我开始活动时,我收到错误:
java.lang.NoSuchMethodError:没有静态方法zzw(Ljava / lang / Object;)Ljava / lang / Object;在课堂Lcom / google / android / gms / common / internal / zzac;
请帮帮我。
答案 0 :(得分:0)
在你的gradle中添加它
compile "com.google.android.gms:play-services-base:+"
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-maps:+'
答案 1 :(得分:0)
我刚刚添加了playservices-analytics,base,location,maps library,一切正常。