I'm taking my first foray into Android services and having trouble with compile errors in AIDL files. I am using Eclipse (with Android Development Tools) and Android 4.1. I have the following AIDL files:
Weather.aidl
package ws.hamacher.weatherservice.service;
parcelable ws.hamacher.weatherservice.dto.Weather;
In this file, I get "interface ws.hamacher.weatherservice.dto.Weather should be declared in a file called ws\hamacher\weatherservice\service\ws.aidl." on the parcelable line, but this refers to my Java class!
IWeatherService.aidl
package ws.hamacher.weatherservice.service;
import ws.hamacher.weatherservice.service.Weather;
interface IWeatherService {
void addToWeatherService(in Weather weather);
void deleteFromWeatherService(in Weather weather);
List<Weather> getLocations();
}
Here again, the import statement gives a similar error "interface ws.hamacher.weatherservice.dto.Weather should be declared in a file called ws\hamacher\weatherservice\service\ws.aidl." This should be referring to the first file above right?
Along with that, the method declarations all have errors, to the tune of "unknown type Weather".
Any help would be appreciated.
If you want to send custom object such as Weather class, you should creat a package:
ws.hamacher.weatherservice.dto
write :
Weather.java
in package: ws.hamacher.weatherservice.dto like this:
public class Weather implements Parcelable {
....
}
Then, write Weather.aidl:
package ws.hamacher.weatherservice.dto;
parcelable Weather;
Please see AndroidMusicPlayer and AndroidMusicPlayerClient for real code.
Solved it. My Weather.aidl had to be in the same directory as my parcelable Weather class.
Related
I have a class name String and a String which containing the class code. For example, "Example" is the name of the class, and
public class Example {
public void example () {System.out.println ("Hello world!"); }
}
The class code.
I looked at the Dexmaker library, but I did not understand if it's possible to compile the generated code into it. And the question is just how to compile the code string under Android?
Not sure if possible at all the compilation within the embedded system but definitelly you can parse and run the code using beanshell:
http://www.beanshell.org/
it is lightweight and easily to embed in your app. Then you can instance the generated class and run whatever you put inside.
There is only one true way: using DexMaker. All examples you can find on DexMaker wiki and especially for current problem (runtime generation code on android).
I am trying to write a Processing-based Android app that needs to communication with a SQLite database. To do this, I am trying to use the Ketai Library, but I am having an issue with it: I cannot use the library because Processing complains about an indirect reference to android.content.Context;. Here is my code for the project.
import ketaisqlite.*;
KetaiSQLite database;
void setup()
{
// Preliminary Stuff
orientation(LANDSCAPE);
lights();
fullScreen(P3D);
// Database Connection
KetaiSQLite.load(this, "/sdcard/Android/database.sqlite", "database");
}
Here are the two messages in the Error Console.
The type android.content.Context cannot be resolved. It is indirectly referenced from required .class files The type android.content.Context cannot be resolved. It is indirectly referenced from required .class files
The method load(Context, String, String) from the type KetaiSQLite refers to the missing type Context The method load(Context, String, String) from the type KetaiSQLite refers to the missing type Context
Trying to add import android.context.Context; creates an additional problem:
Only a type can be imported. android.context.Context resolves to a package Only a type can be imported. android.context.Context resolves to a package
What do I do? I have looked at the code for the library itself and cannot figure out what is wrong with it, if anything.
Add a new tab to processing called "required.java". The name isn't important, but it seems that processing Android needs a .java file to work with imports.
I have a AIDL file that implemented in the package under ProjectA, and I am trying to import a Parcelable class (Foo) from another package under ProjectB. Below is the way how I implemented the MyService.AIDL file:
package com.packageA.projectA
import com.packageB.projectB.Foo
interface MyService{
void getSomething(Foo foo);
}
However, I get this compilation error "couldn't find import for class com.example.projectB.Foo". If I copied the packageB to packageA, then I will get no compilation error.
Is there a way to import parcelable class from package under different project? I know there're multiple questions on stackoverflow and elsewhere (like google group) about importing parcelable under the same project, but none from different projects. Thank you for your time.
You mean to say that you defined the class for the parcelable class and you are not able to use that class in the aidl ?
Try the below solution.
you have your MyService.AIDL in your src/xxx path.
Now create Foo.aidl (name should be same)in the same path and define that Foo.aidl as below.
package com.packageB.projectB
parcelable Foo
now remove the import statement from MyService.AIDL and re-type it (its for refreshing , else it will show same error)
now that import error must be gone.
I know this is old but I had the same problem and found the solution very ugly.
I had two classes defined in the package:
com.lni.codephg.inter
I had another class defined in the package
com.pcha.androidbtmanager
The actual AIDL interfaces were defined in the package
com.pcha.proprietary.handler
The client would be looking for remote services implementing methods in the package com.pcha.proprietary.handler.
So what did my AIDL file hierarchy have to look like to make this work?
src\main\aidl\com\lni\codephg\inter
MetricIntermediary.aidl
MdsIntermediary.aidl
src\main\aidl\com\pcha\androidbtmanager
PhdInformation.aidl
src\main\aidl\com\pcha\proprietary\handler
IConnectionCallback.aidl
IIntermediaryCallback.aidl
IProprietaryDeviceHandler.aidl
IStatusEventCallback.aidl
The 'one-liner' files defining the custom classes like MdsIntermediary.aidl look like this
// MdsIntermediary.aidl
package com.lni.codephg.inter;
parcelable MetricIntermediary;
I have to admit I do understand why these one-liner files must exist in such a weird form.
Then the interface AIDL files that reference them (for example IIntermediaryCallback.aidl) look like this
// IIntermediaryCallback.aidl
package com.pcha.proprietary.handler;
// Declare any non-default types here with import statements
import com.lni.codephg.inter.MdsIntermediary;
import com.lni.codephg.inter.MetricIntermediary;
interface IIntermediaryCallback
{
void onMdsIntermediary(in MdsIntermediary mds);
void onReceiveMetricIntermediaries (in List<MetricIntermediary> metricList, in
MdsIntermediary mds);
}
Of course I had to implement the Parcelable methods on the said custom classes. However, as ugly as that was, Android Studio seemed to do it for me. Since I know nothing about Parcelable I don't know if it is good enough or if I have to do some massaging.
This was painfully difficult. Hope this will save someone hours of frustration.
I have setup my own android library and now want to use the methods within..
For some reason I am having issues understanding how this works, looking at other questions/ internet has not helped.
In my library class i have the following.
public void testMethod(){
Toast s = Toast.makeText(this, "test!", Toast.LENGTH_SHORT).show();
}
I want to be able to reference this in my main for example, how do i do this?
I have found several links which do look at this however it has not helped as it is different to what I want to do. Am I being very stupid and missing something?
I am guessing an interface needs to be setup on my Main Class? I am not sure.
By the way I have already setup the library and have referenced in manifest etc..
You should import to your project the package name you used to create your library, then, create an object of the class you want to use from your library, and finally, call the method.
Supose your library package name it's: "com.mylibrary"
Your library class it's called: "MyClass"
Your method it's called: "MyMethod"
In Your Project you should do:
//Import Your Library Package
import com.mylibrary;
//Instantiate The Library Class
MyClass mytest = new MyClass();
//Call The Library Class Method You Want To Use.
mytest.MyMethod();
I am trying to use class android.content.ContentValues in an aidl
interface. Since this class implements parcelable, why It is not possible to declare in the
aidl file.so this is something particular to getting aidl to recognize a parcelable class.
Regards,
Jainish CS
All the classes which are implementing Parcelable interface eligible to get defined inside an AIDL file.So we can edit the platforms\version\framework.aidl file add the contentValues.So the problem is solved
I find another better way to handle it:
create a package android.content in your sourcecode.
add&define an aidl file with name ContentValues.aidl:
Add the ContentValues.aidl with following code:
package android.content;
parcelable ContentValues;
Then the compile will show no error.