简体   繁体   English

广播接收器在4.1.1中不起作用

[英]Broadcast Receiver Not working in 4.1.1

I have a broadcast receiver for incoming call.I want to launch a new activity when an incoming call comes.I am aware of the changes that are made from android 3.0,that the broadcast receiver will not work unless user manually starts an application For that purpose I launch a dummy activity with just a toast message in it.Still the broadcast receiver is not working. 我有一个用于接收呼叫的广播接收器。我想在传入呼叫时启动新的活动。我知道从android 3.0进行的更改,除非用户手动启动应用程序,否则广播接收器将无法工作目的是我启动一个虚拟活动,其中仅包含一个吐司消息。但广播接收器仍无法正常工作。 Here is my code 这是我的代码

My broadcastreceiver 我的广播接收器

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 file 清单文件

<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"/>

<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>

What is wrong with the code? 代码有什么问题? Please help 请帮忙

As you have already known that the broadcast receiver will not work unless user manually starts an application For that purpose , you should not be surprised that your broadcast receiver will not work until user Manually open your application once . 如您所知, 除非用户手动启动应用程序,否则广播接收器将无法工作。为此 ,除非用户手动打开应用程序一次否则广播接收器将不工作不会令您感到惊讶。 That is to say, you have to make a launcher activity which user is able to click and open it manually . 也就是说,您必须进行一个启动器活动,用户可以单击该活动并将其手动打开。

And what's more, it is better to Open and stay in your application for like 20s since I remember that the change of application configuration will take 10 or 20s to be saved. 而且,最好打开并在应用程序中停留20秒钟左右,因为我记得更改应用程序配置将需要10或20秒钟来保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM