Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.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
Can';Android中启动后侦听器无法完成_Android_Bootcompleted - Fatal编程技术网

Can';Android中启动后侦听器无法完成

Can';Android中启动后侦听器无法完成,android,bootcompleted,Android,Bootcompleted,我无法在设备启动后立即启动服务。 我的服务和接收器类别如下 package android_programmers_guide.BroadcastReceiver1; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; import android.app.ActivityManager; impor

我无法在设备启动后立即启动服务。 我的服务和接收器类别如下

    package android_programmers_guide.BroadcastReceiver1;
   import java.util.ArrayList;
   import java.util.List;
   import java.util.Timer;
   import java.util.TimerTask;
   import android.app.ActivityManager;
   import android.app.Service;
   import android.content.Intent;
   import android.content.pm.PackageManager;
   import android.os.IBinder;
   import android.util.Log;
   import android.widget.Toast;
   public class MyService extends Service {
 /**
  * Delay until first exeution of the Log task.
  */
 private final long mDelay = 0;
 /**
  * Period of the Log task.
  */
 private final long mPeriod = 500;
 /**
  * Log tag for this service.
  */ 
 private final String LOGTAG = "**BootDemoService**";
 /**
  * Timer to schedule the service.
  */
 private Timer mTimer;

 /**
  * Implementation of the timer task.
  */
 private class LogTask extends TimerTask {
  public void run() {
   Log.i(LOGTAG, "scheduled");
  }
 }
 private LogTask mLogTask; 

 @Override
 public IBinder onBind(final Intent intent) {
  return null;
 }

 @Override
 public void onCreate() {
  super.onCreate();
  Log.i(LOGTAG, "created");
  mTimer = new Timer();
  mLogTask = new LogTask();
 }

 @Override
 public void onStart(final Intent intent, final int startId) {
  super.onStart(intent, startId);
  Log.i(LOGTAG, "started");
  mTimer.schedule(mLogTask, mDelay, mPeriod);
 }
}
这是接收级

package android_programmers_guide.BroadcastReceiver1;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyStartupIntentReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(final Context context, final Intent bootintent) {
  Intent mServiceIntent = new Intent();
mServiceIntent.setAction("android_programmers_guide.BroadcastReceiver1.MyService");
  context.startService(mServiceIntent);
 }
}
这是清单文件

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android_programmers_guide.BroadcastReceiver1"
android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <service android:name=".MyService">
        <intent-filter>
            <action android:name="android_programmers_guide.BroadcastReceiver1.MyService">
            </action>
        </intent-filter>
    </service>
    <receiver android:name=".MyStartIntentReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED">
            </action>
        </intent-filter>
    </receiver>
</application>
<uses-sdk android:minSdkVersion="4" />

请在舱单中添加该行

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

请在舱单中添加该行

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

您的问题似乎在AndroidManifest.xml中

首先,您在这里拼错了您的
**MyStartupIntentReceiver**

<receiver android:name=".MyStartIntentReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED">
            </action>
        </intent-filter>
</receiver>

1.)首先,更改上述内容并进行检查

2.)否则请删除服务类的

应该是

 <service android:enabled="true" android:name=".MyService" />


希望您在完成此操作后一定能完成此操作。

您的问题似乎在AndroidManifest.xml中

首先,您在这里拼错了您的
**MyStartupIntentReceiver**

<receiver android:name=".MyStartIntentReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED">
            </action>
        </intent-filter>
</receiver>

1.)首先,更改上述内容并进行检查

2.)否则请删除服务类的

应该是

 <service android:enabled="true" android:name=".MyService" />


希望您完成此操作后一定能完成。

谢谢。但我恐怕无法完成活动。谢谢。但我恐怕无法启动已完成事件。您已经检查了答案,这意味着您的查询已解决?我在回答中已经提到,您在AndroidManifest中将MyStartupIntentReceiver拼写错误为MyStartIntentReceiver。我的错。我已经检查过了,因为之前的问题已经解决了,谢谢大家。但我还有一个问题要问,所以我只在该问题中编辑。您已经检查了答案,这意味着您的查询已解决?我在回答中已经提到,您在AndroidManifest中将MyStartupIntentReceiver拼写为MyStartIntentReceiver。我的错。我已经检查过了,因为之前的问题已经解决了,谢谢大家。但我还有一个问题要问,所以我只在这个问题内编辑。