Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android IntentService中会出现什么问题_Android_Android Intent_Broadcastreceiver_Intentservice - Fatal编程技术网

Android IntentService中会出现什么问题

Android IntentService中会出现什么问题,android,android-intent,broadcastreceiver,intentservice,Android,Android Intent,Broadcastreceiver,Intentservice,我已经成功使用了IntentService几次,但在当前的应用程序中,我无法启动BroadcastReceive的onReceive()。我在IntentService的Intent操作和IntentFilter中拥有确切的字符串,该字符串与BroadcastReceiver一起注册在onResume中 filter = new IntentFilter("com.currencyconverter2.intent.action.MESSAGE"); Log.d("CC2", "

我已经成功使用了IntentService几次,但在当前的应用程序中,我无法启动BroadcastReceive的onReceive()。我在IntentService的Intent操作和IntentFilter中拥有确切的字符串,该字符串与BroadcastReceiver一起注册在onResume中

    filter = new IntentFilter("com.currencyconverter2.intent.action.MESSAGE");
    Log.d("CC2", "intent filter created");
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    Log.d("CC2", "filter category added");
    receiver = new MessageReceiver();
    Log.d("CC2", "receiver instantiated");
}

public void onResume(){
    super.onResume();
    registerReceiver(receiver, filter);
    Log.d("CC2", "receiver registered");
}

public void onPause(){
    super.onPause();
    unregisterReceiver(receiver);
    Log.d("CC2", "receiver unregistered");
}

public class MessageReceiver extends BroadcastReceiver{
    public void onReceive(Context context, Intent intent){
        Log.d(Tag, "entered onReceive...");
        String html = intent.getStringExtra("OUTPUT");
        webView.setBackgroundColor(Color.parseColor("#f4f36f"));
        webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
    }
}
我还在Manifest.xml中指定了服务

<service android:name=".IntentServiceTest"></service>
编辑2:

找到了bug

                          Intent broadcastIntent = new Intent();
        Log.d(Tag, "setting intent action");
        broadcastIntent.setAction("com.currencyconverter2.intent.action.MESSAGE");
        Log.d(Tag, "adding intent category");
        broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
        Log.d(Tag, "putting intent extra");
        broadcastIntent.putExtra("OUTPUT", data.text());
        Log.d(Tag, "sending broadcast");
        sendBroadcast(intent);

我应该发送广播(广播意图);相反,

用于执行任务并关闭它,但与您的代码一样,您使用的是长运行时间,而不是使用

检查您的ANDROIDMANDS.XML:

<receiver android:name=".MessageReceiver">
<intent-filter>
<action android:name="com.currencyconverter2.intent.action.MESSAGE" />
<category android:name="android.intent.category.Default" />
</intent-filter>
</receiver>


^-^

仍然不会触发过滤器。我提出了我的意向服务。你看到什么不对劲了吗?我已经通过编程注册了过滤器和接收器。但是谢谢你!
<receiver android:name=".MessageReceiver">
<intent-filter>
<action android:name="com.currencyconverter2.intent.action.MESSAGE" />
<category android:name="android.intent.category.Default" />
</intent-filter>
</receiver>