如何在服务器资源管理器中添加access的连接?
发布网友
发布时间:2022-04-11 19:11
我来回答
共2个回答
懂视网
时间:2022-04-11 23:33
//首先定义Service的接口,IMyService.aidl package com.xxxx; import android.os.IBinder; import android.os.ParcelFileDescriptor; interface IMyService { void doService(int id); } //实现service类,MyService.java public class MyService extends IM
//首先定义Service的接口,IMyService.aidl
package com.xxxx;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
interface IMyService {
void doService(int id);
}
//实现service类,MyService.java
public class MyService extends IMyService.Stub {
public static final String MY_SERVICE = "myservice";
private static MyService sService = null;
static String PERMISSION = "com.xxxx.permission.ACCESS_MYSERVICE";
/*
* The entry called by system server to create service.
*/
public static MyService main(Context context) {
if (sService != null) {
return sService;
}
sService = new MyService(context);
try {
Slog.d(TAG, "created service");
ServiceManager.addService(MY_SERVICE, sService);
Slog.d(TAG, "added service " + MY_SERVICE);
} catch (Throwable e) {
Slog.e(TAG, "Failure starting MyService", e);
}
return sService;
}
private MyService(Context context) {
mContext = context;
}
/*
* Called from Client App to retrieve interface
*/
public static IMyService getService() {
IBinder b = ServiceManager.getService(MY_SERVICE);
if ( b == null) {
return null;
}
return IMyService.Stub.asInterface(b);
}
@Override
public long openSession(IBinder clientToken, int sensorType) throws RemoteException {
//添加访问权限
if (mContext.checkCallingPermission(PERMISSION) != PackageManager.PERMISSION_GRANTED) {
throw new RemoteException("Permission not granted for MyService");
}
//做实际的工作
}
}
热心网友
时间:2022-04-11 20:41
楼主您好
有礼了
我是专业的IDC服务器工作人员,我来帮帮您
access,的连接很很简单的
只要您的程序里,指明您的数据库的地址,就可以连接和写入了
很高兴为您解答,有什么不明白的,欢迎与我咨询,海腾数据---中尉
参考资料:http://hi.baidu.com/wangzhongwei2006