pusher-java-client eventQueue inside onCreate - android

Hi im using pusher for notifications, after some test i keep having troubles, now i have this message when i intent to load a task.
02-08 13:43:56.751 20712-21208/package E/AndroidRuntime: FATAL EXCEPTION: pusher-java-client eventQueue
java.lang.NoClassDefFoundError: com.pusher.client.connection.websocket.WebSocketClientWrapper
at com.pusher.client.util.Factory.newWebSocketClientWrapper(Factory.java:67)
at com.pusher.client.connection.websocket.WebSocketConnection$1.run(WebSocketConnection.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
this is how i call pusher connection in onCreate
runOnUiThread(new Runnable() {
#Override
public void run() {
// Create a new Pusher instance
Pusher pusher = new Pusher("KEY");
pusher.connect(new ConnectionEventListener() {
#Override
public void onConnectionStateChange(ConnectionStateChange change) {
System.out.println("State changed to " + change.getCurrentState() +
" from " + change.getPreviousState());
}
#Override
public void onError(String message, String code, Exception e) {
System.out.println("There was a problem connecting!");
}
}, ConnectionState.ALL);
Channel channel = pusher.subscribe("my-channel");
channel.bind("my-event", new SubscriptionEventListener() {
#Override
public void onEvent(String channel, String event, String data) {
System.out.println("Received event with data: " + data);
}
});
pusher.disconnect();
pusher.connect();
logger.info("Hubo un problema al conectarse");
}
});
Im stuck here, i don´t know if im implementing in a bad way the Thread, some tips will be helpful, thanks!

The reason behind this error is the 64K limit in android VM.
To fix it U should download this jar:
http://central.maven.org/maven2/com/pusher/pusher-java-client/1.2.1/pusher-java-client-1.2.1-jar-with-dependencies.jar
Add it and remove any existing java-client-* from your project dependency.
Also remove any com.google.gson from your gradle.build file.
Finally, enable multidex in your project:
https://developer.android.com/studio/build/multidex.html
that worked for me.

Related

How to register callback for stable HAL AIDL

We need implement a stable AIDL interface in /vendor on Android 11,to comunicate from java apk to service in /vendor, based on this document https://www.codeinsideout.com/blog/android/hal/aidl/, we already implement the interface and call it by ServiceManager.getService(), but when we try to add callback for the interface, it report errors while run in java application
01-10 05:01:53.791 2651 2651 E AndroidRuntime: java.lang.NoSuchMethodError: No virtual method markVintfStability()V in class Landroid/hardware/test/ITestCallback$Stub; or its super classes (declaration of 'android.hardware.test.ITestCallback$Stub' appears in /data/app/~~YnBU-5dLkTN-
fKvRl_DNGg==/com.example.myapplication-qOs99EEE-GIQ3pDHJEaSGg==/base.apk!classes4.dex)
anyone can help it?Many thanks!
ITestCallback.aidl
#VintfStability
interface ITestCallback{
void notify(int eventType,int param0,int param1);
}
ITestManager.aidl
#VintfStability
interface ITestManager {
void registerCallback(in ITestCallback callback);
void unRegisterCallback(in ITestCallback callback);
}
in java apk
IBinder binder = ServiceManager.getService(ITest_AIDL_INTERFACE);
if (binder == null) {
Log.e(TAG, "Getting " + " service daemon binder failed!");
} else {
invcaseAJ = ITestManager.Stub.asInterface(binder);--------worked
ITestCallback callback = new ITestCallback.Stub() { ---------repo error above
#Override
public void notify(int i, int i1, int i2) throws RemoteException {
Log.i(TAG,"");
}
};
Log.d(TAG, "AIDL daemon interface is binded!");

How to download file from kinvey in android

Trying to download publicly accessible file from kinvey to android app
tried following code,
FileOutputStream fos = new FileOutputStream(videoName);
FileMetaData meta = new FileMetaData(videoName);
meta.setId(videoName);
kinveyClient.file().downloadWithTTL(meta.getId(), 1200000, fos, new DownloaderProgressListener() {
#Override
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
Log.i("", "progress updated: " + downloader.getDownloadState());
final String state = new String(downloader.getDownloadState().toString());
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
//tProgress.setText((tProgress.getText() == null) ? state : tProgress.getText() + "\n" + state)
}
});
}
#Override
public void onSuccess(Void result) {
}
#Override
public void onFailure(Throwable error) {
}
});
getting event success but data is not being received. any idea how this will work??
getting error like this :
failure com.kinvey.java.core.KinveyJsonResponseException: InsufficientCredentials
The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials
According to the documentation, this is how you are supposed to use the value you get from getDownloadState() . In order to get the progress of your download, you need to first check the downloadState is equal to DOWNLOAD_IN_PROGRESS value, and then use the download.getProgress() method to get the progress, then you can use this to update the value on your progress slider, (you shouldn't be converting these values to string using the toString() method like you've done above.
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
switch (downloader.getDownloadState()) {
case DOWNLOAD_IN_PROGRESS:
//Download in progress
//Download percentage: + downloader.getProgress()
break;
case DOWNLOAD_COMPLETE:
//Download Completed!
break;
}
}
Code taken from documentation here
Nayana,
You might be getting this error because user does not have permission to access that file. You can try following to solve your issue:
If you make the file publicly readable, all authenticated users will be able to access that particular file.
You can make the file accessible by adding read/write permissions for
few users in ACL.
Also check the documentation for Access Control List:
http://devcenter.kinvey.com/rest/guides/security#entityanduserpermissions
Thanks,
Pranav
Kinvey Support

Unable to register NSD Service

I am trying to work with NSD and I find myself stuck at the very begining..
I set up a very basic layout with a single big button. This button's purpose is to start and register a service on my device so other devices would be able to connect to it through LAN. One press of the said button calls the folowing method in my only Activity :
public void startService(View view){
initSocket();
initRegList();
regService();
}
Following the DevBytes: Network Service Discovery video, I implemented the methods called above, like so (pardon my YOLO-ing for debugging purposes) :
public void initSocket(){
try {
mSocket = new ServerSocket(0);
} catch (IOException e) {
e.printStackTrace();
}
mPort = mSocket.getLocalPort();
Log.e("YOLO-PORT", String.valueOf(mPort));
}
public void regService(){
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setServiceName("MyCoolService");
serviceInfo.setServiceType("_myapp.tcp.");
serviceInfo.setPort(mPort);
mNsdman = (NsdManager) this.getSystemService(this.NSD_SERVICE);
mNsdman.registerService(serviceInfo,NsdManager.PROTOCOL_DNS_SD,mReglist);
}
public void initRegList() {
mReglist = new NsdManager.RegistrationListener() {
#Override
public void onRegistrationFailed(NsdServiceInfo nsdServiceInfo, int i) {
Log.e("YOLO-FAIL", "REG_FAIL, errcode = " + String.valueOf(i));
}
#Override
public void onUnregistrationFailed(NsdServiceInfo nsdServiceInfo, int i) {
Log.e("YOLO-FAIL", "UNREG_FAIL, errcode = " + String.valueOf(i));
}
#Override
public void onServiceRegistered(NsdServiceInfo nsdServiceInfo) {
mServName = nsdServiceInfo.getServiceName();
Log.e("YOLO-NAME", mServName);
}
#Override
public void onServiceUnregistered(NsdServiceInfo nsdServiceInfo) {
Log.e("YOLO-OK", "UNREG");
}
};
}
My problem is I keep falling into onUnregistrationFailed method of the listener with a return code = 0.
Below you will find Logcat entries apearing when I press the said button :
09-14 21:54:03.904 18672-18672/fr.lpnsk.lollibox E/YOLO-PORT﹕ 48321
09-14 21:54:04.124 180-531/? E/MDnsDS﹕ service register request 22 got an error from DNSServiceRegister -65540
09-14 21:54:04.125 538-607/? E/NsdService﹕ Failed to execute registerService com.android.server.NativeDaemonConnector$NativeDaemonArgumentException: command '76 mdnssd register 22 MyCoolService _myapp.tcp. 48321' failed with '501 76 serviceRegister request got an error from DNSServiceRegister'
09-14 21:54:04.126 180-531/? E/MDnsDS﹕ register stop used unknown requestId 22
09-14 21:54:04.126 538-607/? E/NsdService﹕ Failed to execute unregisterService com.android.server.NativeDaemonConnector$NativeDaemonArgumentException: command '77 mdnssd stop-register 22' failed with '501 77 Unknown requestId'
09-14 21:54:04.127 18672-19953/fr.lpnsk.lollibox E/YOLO-FAIL﹕ REG_FAIL, errcode = 0
Am I missing something obvious here ?
Thank you for your help !
Am I missing something obvious here?
Yes. You missed the underscore _ sign before tcp when setting the service type. It should be:
serviceInfo.setServiceType("_myapp._tcp.");
From the official documentation:
...the service type specifies which protocol and transport layer the application uses. The syntax is "_protocol._transportlayer".

Error when displaying the map using Skobbler in Android

I want to integrate a map in my android application. But I'm just starting form the basics and I'm already encountering a crash/error.
I just copied some codes from the demo project but still no luck.
Logcat :
08-14 16:19:55.703: E/AndroidRuntime(30065): FATAL EXCEPTION: GLThread 787
08-14 16:19:55.703: E/AndroidRuntime(30065): java.lang.NullPointerException
08-14 16:19:55.703: E/AndroidRuntime(30065): at com.skobbler.ngx.map.MapRenderer.onSurfaceCreated(SourceFile:487)
08-14 16:19:55.703: E/AndroidRuntime(30065): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)
08-14 16:19:55.703: E/AndroidRuntime(30065): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
I researched already but I haven;t found any solution yet.
Please help.
Here's my code:
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SKLogging.enableLogs(true);
File externalDir = getExternalFilesDir(null);
if (externalDir != null) {`enter code here`
mapresDirPath = externalDir + "/SKMaps/";
} else {
mapresDirPath = getFilesDir() + "/SKMaps/";
}
if (!new File(mapresDirPath).exists()) {
new SKPrepareMapTextureThread(this, mapresDirPath, "SKMaps.zip", this).start();
copyOtherResources();
prepareMapCreatorFile();
} else {
Toast.makeText(MainActivity.this, "Map resources copied in a previous run", Toast.LENGTH_SHORT).show();
prepareMapCreatorFile();
initializeLibrary();
finish();
startActivity(new Intent(MainActivity.this, MapActivity.class));
}
}
private void initializeLibrary() {
SKMapsInitSettings initSettings = new SKMapsInitSettings();
initSettings.setMapResourcesPaths(mapresDirPath, new SKMapViewStyle(mapresDirPath + "daystyle/", "daystyle.json"));
final SKAdvisorSettings advisorSettings = initSettings.getAdvisorSettings();
advisorSettings.setLanguage("en");
advisorSettings.setAdvisorVoice("en");
advisorSettings.setPlayInitialAdvice(true);
advisorSettings.setPlayAfterTurnInformalAdvice(true);
advisorSettings.setPlayInitialVoiceNoRouteAdvice(true);
initSettings.setAdvisorSettings(advisorSettings);
SKVersioningManager.getInstance().setMapUpdateListener(this);
SKMaps.getInstance().initializeSKMaps(this, initSettings, API_KEY);
}
#Override
public void onMapTexturesPrepared(boolean prepared) {
initializeLibrary();
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, "Map resources were copied", Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(MainActivity.this, MapActivity.class));
}
});
}
MapActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
SKMapViewHolder mapViewHolder = (SKMapViewHolder) findViewById(R.id.map_surface_holder);
mapView = mapViewHolder.getMapSurfaceView();
mapView.getMapSettings().setMapPanningEnabled(true);
mapView.getMapSettings().setMapZoomingEnabled(true);
mapView.getMapSettings().setInertiaPanningEnabled(true);
SKVersioningManager.getInstance().setMapUpdateListener(this);
}
I had the same problem, and I posted an answer on their support forum :
Hi,
Implementing Skobbler in my android app, I stucked half an hour with a crash I couldn't understand.
Following the DemoApp for the initialization part, I kept crashing just before map was displayed with error:
java.lang.NullPointerException
at com.skobbler.ngx.map.MapRenderer.onSurfaceCreated( SourceFile:487)
at android.opengl.GLSurfaceView$GLThread.guardedRun(G LSurfaceView.java:1509)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfac eView.java:1248)
As the error wasn't self explanatory at all, I investigated file MapRenderer from package com.skobbler.ngx.map, and found
that I was crashing because I didn't implement a map listener (this.s, in line below), which classname was trying to be displayed on log.
public final void onSurfaceCreated(GL10 arg1, EGLConfig paramEGLConfig)
{
SKLogging.writeLog("MapRenderer", "onSurfaceCreated before LOCK ", 2);
synchronized (V) {
SKLogging.writeLog("MapRenderer", "onSurfaceCreated" + this.s.getClass().getName(), 2); // <== Line 487
You might have forgot to check non-nullity of this.s before logging it, and as it wasn't described as mandatory in your doc to
implement this listener,I think you should correct that, or otherwise precise it in documentation.
http://forum.skobbler.com/showthread.php/6554-Android-Resolution-for-NullPointerException-onSurfaceCreated(SourceFile-487)?p=17601#post17601
Hope that helps !
tl:dr :
SKMapSurfaceView mapView = mapViewContainer.getMapSurfaceView();
mapView.setMapSurfaceListener(new SKMapSurfaceListener() {...});

batch adding events to google calender

Hi I'm trying to add events to a calender with the google-api-java-client and calender API service for a android app. I used the calendersample project created by Yaniv Inbar as a template which works great. When inserting 1 event to the selected calender works perfectly but when i try to batch add events to the calendar get an Illegal state exception.
in the example you could batch add calenders like this.
whole class can be found here AsyncBatchInsertCalendars.java
#Override
protected void doInBackground() throws IOException {
BatchRequest batch = client.batch();
for (Calendar calendar : calendars) {
client.calendars().insert(calendar).setFields(CalendarInfo.FIELDS)
.queue(batch, new JsonBatchCallback<Calendar>() {
public void onSuccess(Calendar calendar, GoogleHeaders headers) {
model.add(calendar);
}
#Override
public void onFailure(GoogleJsonError err, GoogleHeaders headers)
throws IOException {
Utils.logAndShowError(activity, CalendarSampleActivity.TAG, err.getMessage());
}
});
}
batch.execute();
}
I rewrote the class so that it would be events instead of calenders. if you look at the whole class AsyncBatchInsertEvent.java you'll see that in the doInBackground methode I also loop through a arraylist creating a list of events. which should than be added to the batch to be inserted on the given calendar.
#Override
protected void doInBackground() throws IOException {
BatchRequest batch = client.batch();
for (Event event : events) {
client.events().insert(calender.id, event).queue(batch,
new JsonBatchCallback<Event>() {
public void onSuccess(Event event, GoogleHeaders headers) {
//TODO show succes message.
}
#Override
public void onFailure(GoogleJsonError err, GoogleHeaders headers)
throws IOException {
Utils.logAndShowError(activity, EventActivity.TAG, err.getMessage());
}
});
}
batch.execute();
}
If I use this then get a an exception and the app crashes
W/dalvikvm(21030): threadid=20: thread exiting with
uncaught exception (group=0x40c19930)
E/AndroidRuntime(21030): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(21030): java.lang.RuntimeException: An error occured
while executing doInBackground()
The full stacktrace of the error can be found here at pastebin log.txt. Does anyone know how to fix this or did I implement the code incorrectly? the whole code can be found here at pastbin AsyncBatchInsertEvent.java
Stupid me, the arraylist events was empty cause i checked a string == string instead of string.equels(string).

Categories

Resources