我尝试通过 Fora Dictionary Api 翻译一个单词。这里有更多关于 ForaApi 的信息。这是我的代码:
String query = "com.ngc.fora.action.QUERY";
Intent foraIntent = new Intent(query);
foraIntent.putExtra("QUERY_ID", new Long("1"));
foraIntent.putExtra("QUERY", lword);
foraIntent.putExtra("MAX_RESULTS", 2);
foraIntent.putExtra("AS_PAGE", true);
foraIntent.putExtra("CALLBACK_ACTION", "com.myAPP.ServiceForFora.TRANSLATE");
foraIntent.putExtra("CALLBACK_PACKAGE", "com.myAPP");
foraIntent.putExtra("CALLBACK_CLASS", ".ServiceForFora");
startService(foraIntent);
但是当 Fora Dictionary 尝试向我的服务(ServiceForFora)发送意图时,我得到了这个:
05-07 06:20:40.440: W/ActivityManager(52): 无法启动服务 Intent { act=com.myAPP.ServiceForFora.TRANSLATE cmp=com.myAPP/.ServiceForFora (has extras) }: 未找到
这是我的服务:
epublic class ServiceForFora extends Service{
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(this, "onBind", Toast.LENGTH_LONG).show();
return null;
}
@Override
public void onCreate() {
//code to execute when the service is first created
Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show();
super.onCreate();
}
@Override
public void onDestroy() {
//code to execute when the service is shutting down
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//code to execute when the service is starting up
super.onStart(intent, startId);
return Service.START_STICKY;
}
}
和清单符号:
<application><service android:name="com.myAPP.ServiceForFora"
android:exported="true">
<intent-filter>
<action android:name="com.myAPP.ServiceForFora.TRANSLATE"/>
</intent-filter>
</service>
.............................
</application>
谢谢