Add Apptentive Survey for Android - android

From the Android Apptentive documentation, only get a callback when a Survey is finished:
Apptentive.setOnSurveyFinishedListener(new OnSurveyFinishedListener() {
#Override
public void onSurveyFinished(boolean completed) {
// Your code
}
});
But,I want to get some class like ios:
ApptentiveSurveyShownNotification/ApptentiveSurveySentNotification
This way I can get more content than just completed(true/false).
Is there such some class for Android Apptentive?

Related

Making API Call continuously even when the Android application is closed - RxJava

I have developed an android application where I need to fetch a list using rest API call and show on my application. The list gets updated frequently. I have written the following code using RxAndroid and retrofit to make the api call :
private void fetchAllData() {
disposable.add(Observable.interval(0,60,TimeUnit.SECONDS).
subscribeOn(Schedulers.io()).
flatMap(i -> apiService.getData(fetchActiveData)).
observeOn(AndroidSchedulers.mainThread()).
subscribeWith(new DisposableObserver<DataResponse>() {
#Override
public void onNext(DataResponse dataResponse) {
Log.i(TAG, "The rest api was called again");
List<Data> dataList = dataResponse.getData();
displayData(dataList,false);
}
#Override
public void onError(Throwable e) {
Log.e(TAG, "The exception is thrown :: " + e.getMessage());
displayData(null,true);
fetchAllData();
}
#Override
public void onComplete() {
}
})
);
}
Using above code , I am able to make api call every 60 seconds and update my list. If there is any new item which I am not displaying on the application , then for that i have the logic to show the notification.
To enhance my application , I need to make the api call when the application is closed and not running on background. Can someone please suggest me how do I achieve this with RxJava.

Flutter force to release foreground

How to release foreground to the previous application in Flutter (Dart) ? I mean, how to force to call the onPause or viewWillDisappear to let my app disappear and let the previous app come back to the foreground.
Is there a method thant I can call ?
Edit : I don't wan't to close my app, juste "minimize" it.
You are struggling with a mismatch between Flutter's architecture and Android's. In your previous question you needed a way to bring your flutter app to the foreground, to which the answer is a full-screen intent notification. The problem is that in native Android, you would probably have used the NEW_TASK flag to start a new task. As Flutter only has one activity, it's necessary to use USE_CURRENT instead.
With NEW_TASK, you would use Activity.finish() to close it, closing just the new activity. If you did that with Flutter, that would probably close the whole app (because of the use of USE_CURRENT).
It might be possible to have a native Android app (allowing you to have more direct control of the launch of activities) and to use Add2App to add the Flutter screen(s). If you get that to work, I'd like to know.
I finally got a solution ! I haven't found yet a solution for the IOS side : I'm working on it.
I used MethodChannel to ask to the native side to minimize itself. For Android use this.moveTaskToBack(true); ! If you got an Objectif-C alternative, it will be perfect !
Dart:
class _MyHomePageState extends State<MyHomePage> {
static const MethodChannel actionChannel = MethodChannel('method.channel');
Future<void> _minimize() async{
try{
await actionChannel.invokeMethod('minimize');
} on PlatformException catch(e) {
print('${e.message}');
}
}
}
Android:
public class MainActivity extends FlutterActivity {
private static final String ACTION_CHANNEL = "method.channel";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Action-post-alert method
new MethodChannel(getFlutterView(), ACTION_CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
#Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("minimize")) {
this.moveTaskToBack(true);
result.success(true);
} else {
result.notImplemented();
}
}
}
);
}
}

LibGDX http request not working

I want to send a String message to database when user presses a specific button in the LibGDX game I am designing for android. How do I go about doing that? Following is the code I tried. But it does not work.
Net.HttpRequest httpRequest = new Net.HttpRequest();
httpRequest.setMethod("POST");
httpRequest.setUrl("URL is here");
httpRequest.setContent("INSERT INTO `game_table` (`Button`) VALUES ('Button 1 Pressed')");
Net.HttpResponseListener httpResponseListener = new Net.HttpResponseListener() {
#Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
Gdx.app.log("Log httpResponse", httpResponse.getResultAsString());
}
#Override
public void failed(Throwable t) {
}
#Override
public void cancelled() {
}
};
Gdx.net.sendHttpRequest(httpRequest,httpResponseListener);
Log does not provide anything in android monitor. I also tried using AsyncTask and without AsyncTask to implement this code. But neither works.
Am I missing something? If so could you give me small code snippet that will work?
You don't need to use an AsyncTask, libGDX' HTTPRequest is async out of the box.
You did not log anything if the request fails or is cancelled so probably that's the case.

React Native - Module Lifecycle - Dispose resources on "Reload"

I am using a react native module (https://github.com/rusel1989/react-native-bluetooth-serial) for Bluetooth communication with an Arduino.
Eveything works just fine. But when I press "Reload" or the application reloads due to Live Reload being enabled, the onDestroy method of the module is not called. Because of that, the sockets (and streams) are no correctly disposed.
When the reload is finished, I can no longer open a bluetooth socket. It requires me to disable and enable bluetooth, or to restart the application.
Is there ant callback or method I could implement that would correctly dispose these sockets when I reload my application?
Ok after spending time in react-native code I found the answer to this:
On iOS:
You'll have to implement a method called invalidate in your RCTBridgeModule implementation:
That will run whenever the context is destroyed (the app is reloaded) and it will look like this:
- (void)invalidate
{
// disconnect bluetooth here
}
Here's an example of how I did it on iOS.
On Android:
you'll have to implement the onCatalystInstanceDestroy method inside your ReactContextBaseJavaModule and it will look like this:
#Override
public void onCatalystInstanceDestroy() {
// disconnect bluetooth here
}
Here's an example of how I did it on Android.
It seems we can use #Override public void onCatalystInstanceDestroy() {} without the need of implementing anything.
That method will be called before the current JS bundle is destroyed.
on iOS
- (instancetype)init
{
self = [super init];
NSLog(#"whatever you want");
return self;
}
- (void)dealloc
{
// by the way, you do not need the following line because of ARC
// [super dealloc];
NSLog(#"whatever you want");
}
I prefer use dealloc rather than invalidate
because react-native api may change in the future...
on android
import com.facebook.react.bridge.LifecycleEventListener;
import android.util.Log;
public class YourModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
...
YourModule(ReactApplicationContext reactContext) {
super(reactContext);
reactContext.addLifecycleEventListener(this);
this.reactContext = reactContext;
Log.d("YourModuleLog", "whatever you want");
}
#Override
public void onHostResume() {}
#Override
public void onHostPause() {}
#Override
public void onHostDestroy() {
Log.d("YourModuleLog", "not trigger after fast reload");
}
#Override
public void onCatalystInstanceDestroy() {
Log.d("YourModuleLog", "whatever you want");
}
}
only override onCatalystInstanceDestroy does not work for me
unless I also add LifecycleEventListener.

android usage of "controller.query(activity);" in scoreloop

i am attempting to implement a built in controller that is part of the scoreloop library. the documentation states:
Basic Usage:
To invoke the TOS dialog if it was not accepted previously, the following code may be used:
final TermsOfServiceController controller = new TermsOfServiceController(new TermsOfServiceControllerObserver() {
#Override
public void termsOfServiceControllerDidFinish(final TermsOfServiceController controller, final Boolean accepted) {
if(accepted != null) {
// we have conclusive result.
if(accepted) {
// user did accept
}
else {
// user did reject
}
}
}
});
controller.query(activity);
but when i paste this into my code i get the following syntax errors:
am i using this incorrectly? how and where would this be used any ideas?
EDIT: after moving the statement to the method where i want to show the dialog i now get the following error:
You seem to be calling controller.query(activity) in a class body where a declaration is expected. Move the statement controller.query(activity) to a method where you would like to show the dialog.

Categories

Resources