How to use the ContentValues in AIDL file - android

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.

Related

How to use a class in an imported jar?

What I am doing: Call the method inside the class in a very simple jar from main Activity. (The jar will be used as sdk to make connection with a server but right now is for testing)
Error message
This is all the code in my jar, just 1 class
I have tried this, and changed the class into singleton pattern and this, and make everything in the class public. I also found this one but same error different issue
Create class as public class to make it accessible. In java if you don't provide any access modifier it becomes default.
Refer Java Access Modifiers here
public class Jartest{
//Your Implementation
}
In addition to create the class with public modifier, all classes must be warped inside a package. Otherwise it becomes default package and there is no way to access it beside reflection. In another word, when you create the jar, create the class inside a package and Android studio should be able to import the package and use the class inside the jar.

how to import class of another package from different project in AIDL file?

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.

not understanding compile errors in AIDL files

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.

How to define parcelable of interface type in .aidl file?

I have an .aidl file that defines a single parcelable of an interface type, let's say
parcelable MyInterface;
Whereby MyInterface is a java interface declared in MyInterface.java that extends the Parcelable interface. The android parcelable mechanism requires me to define a static CREATOR in the parcelable class. But how can I do this for an interface since the interface class does not know the concrete implementation and therefor cannot implement the createFromParcel() method?
How will the android runtime decide which CREATOR (from which subclass) to call? Is it even impossible to use an interface type in an .aidl file?
about use interface in AIDL file:
I don't think there is anything there stopping you to do so. Because "parcelable MyInterface;" does not actually generate anything in gen folder, it is just needed for function signature of any AIDL interface using this MyInterface type.
CREATOR
You have to add creator definition for all your classes implements android.os.Parcelable.
I ran into similar scenario, and wanted to share what I did. I had following aidl main interface which contains another interface inside it.
//ICounterAidlInterface.aidl
import path.to.aidldirectory.CounterListener
interface ICounterAidlInterface {
int getCounter();
void setCounterListener(CounterListener listener);
}
Don't forget the import.
The question is how to represent this new type: CounterListener. Since CounterListener itself is an interface, you don't need to mark it parcelable.
You need to create another aidl file for the CounterListener too. So, I created another aidl file:
//CounterListener.aidl
interface CounterListener{
void newData(int data);
}
Hope this helps :)

How to return a list of MyObject in android aidl file?

I have this method in my .aidl file:
void getObjects(out List<MyObject> objList);
But I get this error
src/com/mycompany/mypackage/ITestService.aidl:26 parameter objList (1) unknown type List objList
How to create a List of MyObject in .aidl?
Thank you.
Steps:
MyObject implements Parcable
Create new MyObject.aidl file in src.com.mycompany.mypackage
package src.com.mycompany.mypackage;
parcelable MyObject;
Reason :you’re passing class objects between processes, the client process must understand
the definition of the object being passed.
AIDL complier won’t be able to locate our self-defined MyObject even if it implements the Parcelable interface. To inform our implementation to the AIDL compiler, we need to define an aidl file which declares the class as Parcelable
In ITestService.aidl add import statment,
import src.com.mycompany.mypackage.MyObject
Error unknown type List will get removed.
You need to make MyObject Parcelable and then import MyObject in your AIDL file.
For more information and an example see the developers guide: https://developer.android.com/guide/developing/tools/aidl.html#PassingObjects

Categories

Resources