aidl

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目录下对应的目录自动生成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值