安卓htc m8手机,链接蓝牙热敏打印机,(佳博gp5890xIII)提示
Service Intent must be explicit。。。
根据打印机官方提供的demo,修改为
private void connection() {
conn = new PrinterServiceConnection();
Intent intent0 = new Intent("com.gprinter.aidl.GpPrintService");
Intent intent = new Intent(getExplicitIntent(this,intent0));
bindService(intent, conn, Context.BIND_AUTO_CREATE); // bindService
}
此方法中的getExplicitIntent方法,也要复制进来。connect方法可以在oncreate中或onresume中
public static Intent getExplicitIntent(Context context, Intent implicitIntent) {
// Retrieve all services that can match the given intent
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;
}
// Get component info and create ComponentName
ResolveInfo serviceInfo = resolveInfo.get(0);
String packageName = serviceInfo.serviceInfo.packageName;
String className = serviceInfo.serviceInfo.name;
ComponentName component = new ComponentName(packageName, className);
// Create a new intent. Use the old one for extras and such reuse
Intent explicitIntent = new Intent(implicitIntent);
// Set the component to be explicit
explicitIntent.setComponent(component);
return explicitIntent;
}