广播转发接收器事件在没有任何UI的软件服务应用程序中失败

时间:2013-08-22 01:06:03

标签: android broadcastreceiver

我想要创建一个没有任何UI的应用程序,它应该作为服务应用程序工作。我在应用程序中使用了启动完成事件,当我在2.3(姜饼)版本中运行应用程序然后它的工作正常,但它不是正在使用Jellybean版本。但是如果我运行任何活动的应用程序,那么它在两个版本中都能正常工作。请给我一个解决方案。

AndroidManifest文件。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bootreceivecheck"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver android:name="com.home.BootReceiver.BootCompleteReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />             
            </intent-filter>
        </receiver>

    </application>

</manifest>

类文件。

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;


public class BootCompleteReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent arg1) {
        try
        {
            Toast.makeText(context, "Mobile Boot Completed", Toast.LENGTH_LONG).show();
        }catch(Exception ex)
        {
            Toast.makeText(context, ex.getMessage(), Toast.LENGTH_LONG).show();
        }

    }

}

0 个答案:

没有答案