Android 广播接收机在4.1.1中不工作
我有一个用于接听来电的广播接收器。我想在接到来电时启动一个新活动。我知道android 3.0所做的更改,即除非用户手动启动应用程序,否则广播接收器将无法工作 为此,我启动了一个虚拟活动,其中只有一条toast消息,但广播接收器仍然不工作。 这是我的密码 我的广播接收机Android 广播接收机在4.1.1中不工作,android,Android,我有一个用于接听来电的广播接收器。我想在接到来电时启动一个新活动。我知道android 3.0所做的更改,即除非用户手动启动应用程序,否则广播接收器将无法工作 为此,我启动了一个虚拟活动,其中只有一条toast消息,但广播接收器仍然不工作。 这是我的密码 我的广播接收机 public class IncomingCallResult extends BroadcastReceiver { String TAG="IncomingCallResult"; @Override public
public class IncomingCallResult extends BroadcastReceiver
{
String TAG="IncomingCallResult";
@Override
public void onReceive(Context arg0, Intent I1)
{
Log.i(TAG,"inside on receive........");
Bundle bundle=I1.getExtras();
String state=bundle.getString(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
Intent flash_intent=new Intent(arg0,LedFlasher.class);
flash_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(flash_intent);
}
}
}
清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.blinker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
代码有什么问题?
请帮助因为您已经知道,除非用户手动启动应用程序,否则广播接收器将无法工作,在用户手动打开应用程序一次之前,广播接收器将无法工作,您不应感到惊讶。也就是说,您必须创建一个启动器活动,用户可以单击并手动打开它
更重要的是,最好打开应用程序并在应用程序中停留20秒,因为我记得应用程序配置的更改需要10秒或20秒才能保存。@Robin…是的,我知道…因此,我正在启动一个虚拟活动,其中只包含一个吐司。正如您在清单中看到的,它是启动器活动。但是广播接收机不工作接收机中指定的android:priority=“214783648”的用途是什么?
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name=".IncomingCallResult"
android:enabled="true">
<intent-filter
android:priority="214783648"
android:name="android.intent.action.PHONE_STATE">
</intent-filter>
</receiver>
<activity
android:name=".LedFlasher"
android:label="@string/title_activity_incoming_call_result" >
</activity>
<activity
android:name=".Dummy">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>