【问题标题】:Unable to start service Intent. Fora Dictionary无法启动服务 Intent。论坛词典
【发布时间】:2012-06-14 05:30:43
【问题描述】:

我尝试通过 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 (有额外)}:未找到

这是我的服务:

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>

谢谢

【问题讨论】:

  • 嗨,你知道为什么它不起作用吗?我也遇到了同样的情况:(

标签: android android-intent


【解决方案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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 2022-01-17
    相关资源
    最近更新 更多