액티비티에서
버튼누르면
리시버로 연결 후
부팅시 로그뜨게 해 놨습니다...
전체 코드 입니다... 왜 부팅 코드에서 에러가 나는 거일까요...
public class MainActivity extends Activity {
private PendingIntent pendingIntent;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent( MainActivity.this, Reciver.class );
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, i, 0);
try {
pendingIntent.send();
} catch (CanceledException e) {
e.printStackTrace();
}
}
});
-----------------------------------------------------------
public class Reciver extends BroadcastReceiver {
//private PendingIntent pendingIntent;
@Override
// On every interval, the Intent is received here
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Log.e("mylog","onReceive");
Toast.makeText(context, "ddddddddddddddddddddd", Toast.LENGTH_LONG).show();
}
Log.e("mylog","onReceiveeeeeeeeeeeeee");
}
}
---------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cuber.sendreciver"
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" >
<activity
android:name="cuber.sendreciver.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Reciver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
