Settings里设置Camera参数
Camera端:
定义ICameraSettingService.aidl内容如下:
package com.android.camera.service;
interface ICameraSettingService
{
String getValue(String preferenceName,String key,String value);
void setValue(String preferenceName,String key,String value);
boolean getBooleanValue(String preferenceName,String key,boolean value);
void setBooleanValue(String preferenceName,String key,boolean value);
int getIntValue(String preferenceName,String key,int value);
void setIntvalue(String preferenceName,String key,int value);
}
定义CameraSettingService.java内容如下:
package com.android.camera.service;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
public class CameraSettingService extends Service {
ICameraSettingService.Stub stub = new ICameraSettingService.Stub() {
@Override
public void setValue(String preferenceName, String key, String value)
throws RemoteException {
// TODO Auto-generated method stub
SharedPreferences sp = getSharedPreferences(preferenceName, MODE_PRIVATE);
sp.edit().putString(key, value).commit();
}
@Override
public String getValue(String preferenceName, String key, String value)
throws RemoteException {
// TODO Auto-generated method stub
SharedPreferences sp = getSharedPreferences(preferenceName, MODE_PRIVATE);
return sp.getString(key, value);
}
@Override
public boolean getBooleanValue(String preferenceName, String key,
boolean value) throws RemoteException {
// TODO Auto-generated method stub
SharedPreferences sp = getSharedPreferences(preferenceName, MODE_PRIVATE);
return sp.getBoolean(key, value);
}
@Override
public void setBooleanValue(String preferenceName, String key,
boolean value) throws RemoteException {
// TODO Auto-generated method stub
SharedPreferences sp = getSharedPreferences(preferenceName, MODE_PRIVATE);
sp.edit().putBoolean(key, value).commit();
}
@Override
public int getIntValue(String preferenceName, String key, int value)
throws RemoteException {
// TODO Auto-generated method stub
SharedPreferences sp = getSharedPreferences(preferenceName, MODE_PRIVATE);
return sp.getInt(key, value);
}
@Override
public void setIntvalue(String preferenceName, String key, int value)
throws RemoteException {
// TODO Auto-generated method stub
SharedPreferences sp = getSharedPreferences(preferenceName, MODE_PRIVATE);
sp.edit().putInt(key, value).commit();
}
};
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return stub;
}
}
Settnigs端:
ICameraSettingService.aidl复制过来
CameraSettings中实现如下:
import com.android.camera.service.ICameraSettingService;//导入包
private ICameraSettingService mCameraSettingService;//定义全局变量
//oncreate 中绑定service
Intent intent = new Intent(
"com.android.camera.service.CameraSettingService");
getActivity().bindService(intent, conn, Context.BIND_AUTO_CREATE);
//绑定service时参数定义
private ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
mCameraSettingService = ICameraSettingService.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
Log.i("ServiceConnection", "onServiceDisconnected() called");
}
};
完成后就可以调用mCameraSettingService 的方法了!
备注:用Eclipse开发的,ICameraSettingService.java文件会在gen目录下对应的目录自动生成