Unable to use object from library in AIDL interface - android

I am creating an AIDL interface that uses an object type from an android library that is part of a different project. I can import and use the type fine in my service, but I can not import it in my AIDL interface.
package com.mysite.service;
import com.othersite.library.MyObject;
interface IMyService {
int getPid();
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
double aDouble, String aString);
MyObject getObjects();
}
The error is:
couldn't find import for class com.othersite.library.MyObject

You must create a separate .aidl file for each class you wish to use
within your service that declares that class as parcelable.
There is a blog post about this issue here.

Related

Pass android.nfc.Tag via aidl?

I have got a simple aidl interface working:
package local.test;
interface ITest {
int[] getSupportedAidlLevels();
}
However I am struggling to pass the non primitive type android.nfc.Tag which already implements parcelable.
package local.test;
interface ITest {
int[] getSupportedAidlLevels();
void updateNfcTag(Tag tag);
}
I have tried to use an import statement like I would in java. Further I tried to create a second .aidl file like the following but non of this solved my problem.
package local.test;
import android.nfc.Tag;
parcelable Tag;
After a lot of trial and error I finally found the mistake. The in tag was missing.
package local.test;
interface ITest {
int[] getSupportedAidlLevels();
void updateNfcTag(in Tag tag);
}
Maybe this answer helps someone else ;)

Android aidl cant import

I have an aidl file:
package com.xyz;
interface ICallback
{
void CallbackMsg(String type, String value1);
}
I have another aidl file:
package com.xyz;
import com.xyz.ICallback;
interface ISendMsg
{
int getPid();
void SendMsg(String value1);
void registerCallBack(ICallback cb);
void unregisterCallBack(ICallback cb);
}
It gives error as: couldn't find import for class com.xyz.ICallback
What am i doing wrong?
I was copy pasting aidl files from other source and thats why it created a problem.
Once I created the aidl files in the project itself, it stopped giving errors?

Android reflection doesn't work - it don't find any class

I have an Android application.
I want to scan for all classes within a package for a specify annotation.
I have:
package com.sample.package;
import com.sample.core.Controller;
import com.sample.core.ProtocolId;
#Controller
public class OtherController implements ControllerInterface{
#ProtocolId(id=100)
public void doSomething(){
//do something
}
}
I'm finding for classes annotated with #Controller for a specify #ProtocolId number.
I'm using Google Reflections library.
Here is how I'm scanning:
package com.sample.package;
import org.reflections.ReflectionUtils;
import org.reflections.Reflections;
import com.sample.core.Controller;
import com.sample.core.ProtocolId;
public class FrontController {
public void executeProperControllerMethodBasedOnId(){
Reflections ref = new Reflections("com.sample.package");
Set<Class<?>> classes = ref.getTypesAnnotatedWith(Controller.class);
System.out.println(classes.size()); //THE SIZE IS 0!!!
//The reflection doesn't worked! It didn't found any class!
}
}
The above code doesn't find any class annotated with specify annotation. Is
there something which I miss when I'm using google reflection library on
android?

can't import android.os.SystemProperties in Camera app

In camera.java, I need to get property in system. However, I can't import android.os.SystemProperties, compile camera always complains:
packages/apps/Camera/src/com/android/camera/Camera.java:53: cannot find symbol
symbol : class SystemProperties
location: package android.os
import android.os.SystemProperties;
In the beginning of camera.java, I included:
import android.os.Message;
import android.os.MessageQueue;
import android.os.SystemClock;
import android.os.SystemProperties; /* (this is in line 53)*/
It seems SystemProperties is not in android.os package, but I have checked the frameworks source code, it's indeed in it.
This happen in camera app. I found many apps under packages/app dir using SystemProperties in this manner. It's really strange.
SystemProperties class is setted 'hide' annotation.
So you want to use this class in application layer,
you have to use refelection.
the definition of SystemProperties class is below.
package android.os;
/**
* Gives access to the system properties store. The system properties
* store contains a list of string key-value pairs.
*
* {#hide}
*/
public class SystemProperties
i have encounter the same problem as you have, and i use the code below, and solve the problem by using refelection. hope it would be help
//set SystemProperties as you want
public static void setProperty(String key, String value) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method set = c.getMethod("set", String.class, String.class);
set.invoke(c, key, value );
} catch (Exception e) {
Log.d(LOGTAG, "setProperty====exception=");
e.printStackTrace();
}
}

Android remote service using aidl

I'm trying to create a remote service in Eclipse using Android AIDL. I have created my AIDL file IRemoteService.aidl in /src as follows:
package com.vtrandal.bluesentry;
interface IRemoteService {
String getData();
}
After doing a build I get an enormous file IRemoteService.java in /gen containing these classes and methods as follows (it doesn't resemble anything I've seen in the documentation):
public interface IRemoteService extends android.os.IInterface
public static abstract class Stub extends android.os.Binder implements com.vtrandal.bluesentry.IRemoteService
private static final java.lang.String DESCRIPTOR = "com.vtrandal.bluesentry.IRemoteService";
public Stub()
public static com.vtrandal.bluesentry.IRemoteService asInterface(android.os.IBinder obj)
public android.os.IBinder asBinder()
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
private static class Proxy implements com.vtrandal.bluesentry.IRemoteService
Proxy(android.os.IBinder remote)
public android.os.IBinder asBinder()
public java.lang.String getInterfaceDescriptor()
public java.lang.String getData() throws android.os.RemoteException
public java.lang.String getData() throws android.os.RemoteException;
So why does IRemoteService.java contain so much junk not mentioned in the documentation? How could I possibly know what to do with it all? How could I possibly know what to do with any of it?
This is service stub code. It is needed to actually communicate with client. You didn't write any code for communicating between client and service yourself,did you? It's not as simple, after all and it is being generated for you. That's why so much code.
And documentation usually discusses API for user, not stub internal methods.

Categories

Resources