마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

재 부팅시 자동실행되는 코드를 작성했는데요

+1 추천
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="kr.pe.theeye.gobackground"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
     <service android:name = "BootSvc"></service>
	<receiver android:name=".BRcvr"
	    android:enabled="true"
	    android:exported="false"
	    android:label="Broadcast Receiver">
	    <intent-filter>
	        <action android:name="android.intent.action.BOOT_COMPLETED"/>
	    </intent-filter>
	</receiver>
    </application>
   
   <!--   <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> -->
</manifest>
package kr.pe.theeye.gobackground;

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

public class BootSvc extends Service {

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void onCreate(){
		super.onCreate();
		
		Log.i("0000aaa","서비스 시작은 재부팅 후에");
	}
	
}
package kr.pe.theeye.gobackground;

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

public class BRcvr extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
		{
			Log.i("BOOTSVC", "인텐트 받기");
			
			ComponentName cn = new ComponentName(context.getPackageName(),BootSvc.class.getName());
			ComponentName svcName = context.startService(new Intent().setComponent(cn));
			if(svcName == null)
				Log.e("BOOTSVC", "에러!" + cn.toString());
			
		}
	}

}

아무것도 안뜸니다;;

아오쿠르 (900 포인트) 님이 2015년 8월 19일 질문

2개의 답변

+1 추천
 
채택된 답변
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

이거 해제해 보세요 

쎄미 (162,410 포인트) 님이 2015년 8월 19일 답변
아오쿠르님이 2015년 8월 19일 채택됨
그래도 똑같은데요; ㄷㄷㄷㄷㄷ
exported도 true로 해보세요
service의 exported와 enabled도 true로 하고, 브로드캐스트 리시버는 지워보세요
+1 추천
브로드캐스트를 수신하기 위해서는 어플이 한번은 실행이 되어야 합니다.

아오쿠르님이 작성하신 코드에는 런처 액티비티가 존재하지 않으니 어플의 실행이 되지 않으므로 브로드캐스트리시버는 동작하지 않습니다.

 

http://developer.android.com/about/versions/android-3.1.html

위의 링크를 참고해주세요.
레미_21 (2,920 포인트) 님이 2015년 8월 19일 답변
...