I'm working with Neura sdk in order to detect special events of my users( arriving/leaving home)
I'm trying to initiate their authentication, as described below (fetchPermissions() and initNeuraConnection() are the same as in the documentations, and mAuthenticationRequest is initiated on fetchPermissions())
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getMainActivity().initNeuraConnection();
fetchPermissions();
getMainActivity().getClient().authenticate(NEURA_AUTHENTICATION_REQUEST_CODE, mAuthenticateRequest);
}
My issue is that once i call authenticate - nothing happens and the neura login screen isn't opened
There are few things you can check :
Have you declared initNueraConnection() and fetchPermissions() as described in the Neura dev site ?
If so, I suspect you're sending authenticate(...) a nullable mAuthenticateRequest instance.
Since fetchPermissions() is asynchronous(its a network call), you're calling authenticate(...) before the results are fetched from fetchPermissions(), so, mAuthenticateRequest is null, since it's not initiated yet.
You should call authenticate(...) only after you recieve the data on fetchPermissions().
For example, you can do this :
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getMainActivity().initNeuraConnection();
fetchPermissions();
}
private void fetchPermissions() {
loadProgress(true);
getMainActivity().getClient().getAppPermissions(new GetPermissionsRequestCallbacks() {
#Override
public void onSuccess(final List<Permission> permissions) throws RemoteException {
if (getActivity() == null)
return;
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
loadProgress(false);
mPermissions = new ArrayList<>(permissions);
mAuthenticateRequest = new AuthenticationRequest();
mAuthenticateRequest.setAppId(getMainActivity().getClient().getAppUid());
mAuthenticateRequest.setAppSecret(getMainActivity().getClient().getAppSecret());
mAuthenticateRequest.setPermissions(mPermissions);
getMainActivity().getClient().authenticate(NEURA_AUTHENTICATION_REQUEST_CODE, mAuthenticateRequest);
}
});
}
#Override
public void onFailure(Bundle resultData, int errorCode) throws RemoteException {
loadProgress(false);
mRequestPermissions.setEnabled(true);
}
#Override
public IBinder asBinder() {
return null;
}
});
}
Fyi, you can check your logcat for this error : authenticationRequest is nullable, couldn't create authenticate request.
Related
I have added a simple non drop-in paypal integration in sandbox mode to my app. Here is a test activity with a single "Pay" button:
public class PaypalPaymentAcivity extends Activity implements PaymentMethodNonceCreatedListener {
private BraintreeFragment mBraintreeFragment;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paypal);
findViewById(R.id.payButton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startPayment();
}
});
}
private void startPayment() {
try {
mBraintreeFragment = BraintreeFragment.newInstance(this, "...");
PayPalRequest request = new PayPalRequest("1")
.currencyCode("USD")
.intent(PayPalRequest.INTENT_AUTHORIZE);
PayPal.requestOneTimePayment(mBraintreeFragment, request);
} catch (InvalidArgumentException e) {
e.printStackTrace();
}
}
#Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
}
}
However once the PayPal browser window comes up after clicking the buttons it just keeps popping up over and over, and never returns to my activity.
Anyone had a successful integration like this?
My app launches a SplashActivity followed by a MainActivity. I run branch.initSession in the SplashActivity but it's taking about 1.5 seconds to return to the listener which delays the launch of the MainActivity. I would like to reduce this time.
My ideas are:
run branch.initSession in the MainActivity instead.
run branch.initSession in SplashActivity, launch MainActivity, then pass the branch to the MainActivity using an eventbus for processing.
Does anyone have any recommendations on how to solve this issue?
Cheers, Duane.
Amruta from Branch here.
By default, Branch will delay the install call only for up to 1.5 seconds. We delay the install call in order to capture the install referrer string passed through Google Play, which increases attribution and deferred deep linking accuracy. We do not delay any other call, and the install call only occurs the first time a user opens your app.
If we receive the referrer string before 1.5 seconds, we will immediately fire the call, meaning this delay is up to 1.5 seconds, but not guaranteed to take that long.
If you’d like to optimize the first install call, simply paste the following code in your Application class, and we will not delay the first install call.
public final class CustomApplicationClass {
#Override
public void onCreate() {
super.onCreate();
// initialize the Branch object
Branch.setPlayStoreReferrerCheckTimeout(0);
Branch.getAutoInstance(this);
}
}
My solution was:
If first launch, wait for the parameters in the Splash Activity
If not first launch, pass the Branch parameters on to the Application which would pass the parameters onto any listener to process. If there is no listener, then it can try to process it in the Splash Activity or save it for later.
I'm not sure if this is good practice, but I thought it'll be simpler than adding a Event Bus library. Would be happy to hear some feedback.
The Application class:
public class MyApp extends Application {
private Listener branchListener = null;
public interface Listener {
void onBranchLinkReceived(JSONObject params, BranchError error);
}
public void registerBranchListener(Listener listener) {
branchListener = listener;
}
public void unregisterBranchListener() {
branchListener = null;
}
public boolean branchLinkReceived(JSONObject params, BranchError error) {
if (branchListener != null) {
branchListener.onBranchLinkReceived(params, error);
return true;
}
return false;
}
#Override
public void onCreate() {
Branch.getAutoInstance(this);
...
}
}
In the Splash Activity:
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener(){
#Override
public void onInitFinished(JSONObject params, BranchError error) {
if (error == null) {
if (firstLaunch) {
processParamsInSplashActivity(params);
} else {
boolean isProcessed = ((MyApp) getApplication()).branchLinkReceived(params, error);
}
}
}, this.getIntent().getData(), this);
}
}
}
And in the MainActivity:
public class MainActivity extends AppCompatActivity implements MyApp.Listener {
#Override
protected void onCreate(Bundle savedInstanceState) {
((MyApp) getApplication()).registerBranchListener(this);
...
}
#Override
protected void onDestroy() {
((MyApp) getApplication()).unregisterBranchListener();
super.onDestroy();
}
#Override
public void onBranchLinkReceived(JSONObject params, BranchError error) {
Log.d("MainActivity", "Branch link received: " + params);
}
}
I followed the Android official documentation on connecting MediaBrowserCompat but it's refused to connect, as a matter of fact neither onConnected(), onConnectionSuspended() or onConnectionFailed() is called.
I have also tried this answer but it didn't work.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio_player);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setupMediaComponents();
// initializeViews();
}
private void setupMediaComponents() {
Log.d(TAG, "setupMediaComponents");
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaBrowserCompat = new MediaBrowserCompat(this, new ComponentName(this, SongPlayerService.class),
mediaBrowserCompatConnectionCallback, null);
}
#Override
protected void onStart() {
super.onStart();
mediaBrowserCompat.connect();
}
#Override
public void onStop() {
super.onStop();
// (see "stay in sync with the MediaSession")
if (MediaControllerCompat.getMediaController(this) != null) {
MediaControllerCompat.getMediaController(this).unregisterCallback(controllerCallback);
}
mediaBrowserCompat.disconnect();
}
private MediaBrowserCompat.ConnectionCallback mediaBrowserCompatConnectionCallback = new MediaBrowserCompat.ConnectionCallback() {
#Override
public void onConnected() {
Log.d(TAG, "onConnected");
try {
// Create a MediaControllerCompat
MediaControllerCompat mediaController =
new MediaControllerCompat(AudioPlayerActivity.this, mediaBrowserCompat.getSessionToken());
// Save the controller
MediaControllerCompat.setMediaController(AudioPlayerActivity.this, mediaController);
setControlClickListeners();
} catch (RemoteException e) {
e.printStackTrace();
}
}
#Override
public void onConnectionSuspended() {
Log.d(TAG, "onConnectionSuspended");
// We were connected, but no longer :-(
}
#Override
public void onConnectionFailed() {
Log.d(TAG, "onConnectionFailed");
// The attempt to connect failed completely.
// Check the ComponentName!
}
};
I am using version 25.3.1 of the support library and all sdk tools are upto to date.
EDIT
Part of SongPlayerService
#Nullable
#Override
public BrowserRoot onGetRoot(#NonNull String clientPackageName, int clientUid, #Nullable Bundle rootHints) {
// Returning null means no one can connect so we’ll return something
return new BrowserRoot(getString(R.string.app_name), null); // Name visible in Android auto, Bundle is for optional params
// TODO: Support Android auto
}
Finally found the source of the problem. I was overriding onBind and returning null.
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
removing the above lines fixed it for me.
You must implement two methods of MediaBrowserServiceCompat.
At least:
#Nullable
#Override
public BrowserRoot onGetRoot(#NonNull String clientPackageName, int clientUid, #Nullable Bundle rootHints) {
return new BrowserRoot(MEDIA_ID_ROOT, null);
}
#Override
public void onLoadChildren(#NonNull String parentId, #NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
result.sendResult(null);
}
onConnectionFailed() can also be called if you fail to declare the service in the AndroidManifest file. Make sure the intent-filter is also correct. source
<service
android:name=".media.MusicService"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
I'm working with neura sdk in order to detect current data of a user(where he/she is, where were they 10 min ago etc).
I want to login to their api, and authenticate my user, however - when i call NeuraApiClient.authenticate(...) nothing happens.
I followed neura documentations, but still - nothing happens.
Here's my code :
public class MainActivity extends AppCompatActivity {
private ArrayList<Permission> mPermissions;
private AuthenticationRequest mAuthenticateRequest;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Builder builder = new Builder(this);
NeuraApiClient neuraApiClient = builder.build();
neuraApiClient.setAppUid(getResources().getString(R.string.app_uid));
neuraApiClient.setAppSecret(getResources().getString(R.string.app_secret));
neuraApiClient.connect();
fetchPermissions(neuraApiClient);
neuraApiClient.authenticate(100, mAuthenticateRequest);
}
private void fetchPermissions(final NeuraApiClient client) {
client.getAppPermissions(new GetPermissionsRequestCallbacks() {
#Override
public void onSuccess(final List<Permission> permissions) throws RemoteException {
runOnUiThread(new Runnable() {
#Override
public void run() {
mPermissions = new ArrayList<>(permissions);
mAuthenticateRequest = new AuthenticationRequest();
mAuthenticateRequest.setAppId(client.getAppUid());
mAuthenticateRequest.setAppSecret(client.getAppSecret());
mAuthenticateRequest.setPermissions(mPermissions);
}
});
}
#Override
public void onFailure(Bundle resultData, int errorCode) throws RemoteException {
}
#Override
public IBinder asBinder() {
return null;
}
});
}
}
getAppPermissions is an asynchronous call, and the data is fetched on GetPermissionsRequestCallbacks.
in GetPermissionsRequestCallbacks you're initiating mAuthenticateRequest which is in use of authenticate method.
Which means you have to wait untill onSuccess of GetPermissionsRequestCallbacks is called, and only then you can call
neuraApiClient.authenticate(100, mAuthenticateRequest);
Basically, if you don't wait for mAuthenticateRequest to be fetched, you authenticate with mAuthenticateRequest = null, and neuraApiClient.authenticate(..) fails.
You can do something like this : call authenticate when the results are received -
private void fetchPermissions(final NeuraApiClient client) {
client.getAppPermissions(new GetPermissionsRequestCallbacks() {
#Override
public void onSuccess(final List<Permission> permissions) throws RemoteException {
runOnUiThread(new Runnable() {
#Override
public void run() {
mPermissions = new ArrayList<>(permissions);
mAuthenticateRequest = new AuthenticationRequest();
mAuthenticateRequest.setAppId(client.getAppUid());
mAuthenticateRequest.setAppSecret(client.getAppSecret());
mAuthenticateRequest.setPermissions(mPermissions);
client.authenticate(100, mAuthenticateRequest);
}
});
}
...
});
}
I am trying to create chat in app using sampe-chat codes.
I authorized user, got opponend id, after that successfully created dialog:
ChatService.initIfNeed(this);
QBUsers.getUserByLogin(login, new QBEntityCallbackImpl<QBUser>() {
#Override
public void onSuccess(QBUser qbUser, Bundle args) {
QBPrivateChatManager privateChatManager = QBChatService.getInstance().getPrivateChatManager();
privateChatManager.createDialog(qbUser.getId(), new QBEntityCallbackImpl<QBDialog>() {
#Override
public void onSuccess(QBDialog dialog, Bundle args) {
ChatActivity.this.dialog = dialog;
setContentView(R.layout.activity_chat);
initViews();
if (isSessionActive()) {
initChat();
}
ChatService.getInstance().addConnectionListener(chatConnectionListener);
}
#Override
public void onError(List<String> errors) {
Log.e("chat", errors.toString());
}
});
}
#Override
public void onError(List errors) {
Log.e("chat", errors.toString());
}
});
But at initViews() I've got error at
else if (dialog.getType() == QBDialogType.PRIVATE) {
Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog);
companionLabel.setText(ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin());
}
The error is because ChatService.getInstance().getDialogsUsers() returns 0 elements: , so ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin() gives exception.
Any explanations of this I have not found in documentation:
Why I have got 0 elements at ChatService.getInstance().getDialogsUsers()? Dialog is successfully created.
The 'getDialogsUsers' is not an SDK method, it's from code sample
You can just look into it, what does it do
https://github.com/QuickBlox/quickblox-android-sdk/blob/master/sample-chat/src/com/quickblox/sample/chat/core/ChatService.java#L195
It returns a map of users, set in L172
https://github.com/QuickBlox/quickblox-android-sdk/blob/master/sample-chat/src/com/quickblox/sample/chat/core/ChatService.java#L172
Try to follow this file and move all needed logic to your app