无法启动服务Intent。福拉字典

时间:2012-05-08 04:29:07

标签: android android-intent

我尝试通过Fora Dictionary Api翻译一个单词。 Here更多关于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额外的}}:未找到

这是我的服务:

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>

感谢的

1 个答案:

答案 0 :(得分:1)

尝试删除此代码:

foraIntent.putExtra("CALLBACK_PACKAGE", "com.myAPP");
foraIntent.putExtra("CALLBACK_CLASS", ".ServiceForFora");

并向服务描述添加更多参数:

android:enabled="true" android:exported="true" android:stateNotNeeded="true" android:excludeFromRecents="true" android:configChanges="keyboard|keyboardHidden|orientation"