广播接收器的onReceive()从来没有所谓的接收器、从来没有、onReceive

2023-09-04 09:42:36 作者:春风正得意

我得到这个问题,ICS,而不是在previous版本:

I get this issue in ICS, but not in previous versions:

从App1的,我发送广播,并试图获得在app 2活动。但是的onReceive不会被调用的应用程序2的活动。

From App1, I am sending broadcast and trying to receive it in App 2 activity. But the onReceive is never called in App 2's activity.

我不明白什么是获取调用该块的的onReceive,虽然我已经正确指定的一切。

I cannot understand what is that block's onReceive from getting called, though I have specified everything correctly.

我,然后再BroadcastSend运行BroadcastReceive

I run the BroadcastReceive first and then BroadcastSend

任何帮助,这将帮我解决,这是多少AP preciated。

Any help which would help me resolve this is much appreciated.

App1的发送活动

public class BroadcastSend extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent i = new Intent();
    i.setAction("edu.ius.rwisman.custom.intent.action.TEST");
    i.putExtra("url","ww.ius.edu");
    sendBroadcast(i);
}

应用程序2接收活动

App 2 receive activity

public class BroadcastReceive extends BroadcastReceiver{
// Display an alert that we've received a message.    
@Override 
public void onReceive(Context context, Intent intent){
    System.out.println("Inside onReceive");
    String url = intent.getExtras().getString("url");
    Toast.makeText(context, "BroadcastReceive:"+url, Toast.LENGTH_SHORT).show();
  }

应用程序2的清单

Manifest of App 2

<?xml version="1.0" encoding="utf-8"?>

    

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <receiver android:name="edu.ius.rwisman.BroadcastReceive.BroadcastReceive" android:enabled="true" android:exported="true"> 
        <intent-filter>
            <action android:name="edu.ius.rwisman.custom.intent.action.TEST"/>
        </intent-filter>
    </receiver>
</application>

推荐答案

在ICS您将不会收到广播,直到您的应用程序手动启动至少once.in的Andr​​oid 3.1+,应用程序都处于停止状态,如果他们从来没有已运行,或已经停止力。该系统不包括从广播意图这些应用程序。它们可以包括使用Intent.FLAG_INCLUDE_STOPPED_PACKAGES标志,这样的..

In ICS you won't receive broadcasts until your app is started manually at least once.in Android 3.1+, apps are in a stopped state if they have never been run, or have been force stopped. The system excludes these apps from broadcast intents. They can be included by using the Intent.FLAG_INCLUDE_STOPPED_PACKAGES flag like this..

i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
 
精彩推荐
图片推荐