Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.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
Android 我不知道';t接收在仿真器中完成的接收启动_Android_Service_Bootcompleted - Fatal编程技术网

Android 我不知道';t接收在仿真器中完成的接收启动

Android 我不知道';t接收在仿真器中完成的接收启动,android,service,bootcompleted,Android,Service,Bootcompleted,我是法国人,对不起我的英语。我正在尝试开发一个自动启动服务,在后台运行并捕获短信。经过大量的研究,我没能解决我的问题 我无法在启动后运行服务,并且我没有收到日志 Log.v("LTM","MyReceiver.onReceive: "+intent.getAction()); 应该由引导接收器打印。(参见下面的代码) 我验证了AndroidManifest,测试了不同的代码,但没有什么是正确的。我使用Eclipse并用Android虚拟设备测试代码,所以问题可能来自模拟器,我用真实设备进行了

我是法国人,对不起我的英语。我正在尝试开发一个自动启动服务,在后台运行并捕获短信。经过大量的研究,我没能解决我的问题

我无法在启动后运行服务,并且我没有收到日志

 Log.v("LTM","MyReceiver.onReceive: "+intent.getAction());
应该由引导接收器打印。(参见下面的代码)

我验证了AndroidManifest,测试了不同的代码,但没有什么是正确的。我使用Eclipse并用Android虚拟设备测试代码,所以问题可能来自模拟器,我用真实设备进行了测试,但它没有启动

您可以在下面找到代码。谢谢你的帮助

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.smsmanager"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.READ_SMS"/>

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

        <service android:enabled="true" android:label="ServiceGUI"     android:name="com.smsmanager.MainService"/>

        <receiver android:enabled="true"         android:permission="android.permission.RECEIVE_BOOT_COMPLETED" android:name=".MyReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <receiver class="com.smsmanager.SMSReceiver" android:name="com.smsmanager.SMSReceiver">
            <intent-filter android:priority="100">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>
package com.smsmanager;

import com.smsmanager.SMSReceiver;
import android.os.IBinder;
import android.util.Log;
import android.app.Service;
import android.content.Intent;

public class MainService extends Service {
    SMSReceiver rec;
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        Log.v("LTM", "Demarrage du service");
        rec=new SMSReceiver();
        Log.v("LTM", "Retour dans le service");
        return super.onStartCommand(intent, flags, startId);
    }
}
package com.smsmanager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context ctx, Intent intent) {
    // TODO Auto-generated method stub
    Log.v("LTM","MyReceiver.onReceive: "+intent.getAction());
    Intent intent1=new Intent(ctx,MainService.class);
    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startService(intent1);

}

}
接收器:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.smsmanager"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.READ_SMS"/>

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

        <service android:enabled="true" android:label="ServiceGUI"     android:name="com.smsmanager.MainService"/>

        <receiver android:enabled="true"         android:permission="android.permission.RECEIVE_BOOT_COMPLETED" android:name=".MyReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <receiver class="com.smsmanager.SMSReceiver" android:name="com.smsmanager.SMSReceiver">
            <intent-filter android:priority="100">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>
package com.smsmanager;

import com.smsmanager.SMSReceiver;
import android.os.IBinder;
import android.util.Log;
import android.app.Service;
import android.content.Intent;

public class MainService extends Service {
    SMSReceiver rec;
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        Log.v("LTM", "Demarrage du service");
        rec=new SMSReceiver();
        Log.v("LTM", "Retour dans le service");
        return super.onStartCommand(intent, flags, startId);
    }
}
package com.smsmanager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context ctx, Intent intent) {
    // TODO Auto-generated method stub
    Log.v("LTM","MyReceiver.onReceive: "+intent.getAction());
    Intent intent1=new Intent(ctx,MainService.class);
    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startService(intent1);

}

}

您使用的是哪个android版本的emulator?这是AVD的详细信息:CPU/ABI:ARM(armeabi-v7a)目标:Android 4.1.2(API级别16)设备名称:Nexus 4