Я пытаюсь «заблокировать» действие камеры, когда мое приложение активно. Метод onReceive выполняется на BroadcastReceiver, но LogCat, похоже, делает это после того, как намерение уже выполнено.
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:screenOrientation="landscape" android:debuggable="true"
android:clearTaskOnLaunch="true">
<receiver android:name="com.receiver.CameraReceiver">
<intent-filter>
<action android:name="android.intent.action.CAMERA_BUTTON" />
</intent-filter>
</receiver>
<activity android:name=".Main" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
com.receiver.CameraReceiver
package com.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class CameraReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(this.toString(), "Suck It Android!");
abortBroadcast();
}
@Override
public String toString() {
return "com.receiver.CameraReceiver";
}
}
LogCat
12-03 14:47:41.171: INFO/ActivityManager(981): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x14000000 cmp=com.google.android.camera/com.android.camera.Camera }
12-03 14:47:41.288: INFO/WindowManager(981): Setting rotation to 1, animFlags=1
12-03 14:47:41.304: INFO/ActivityManager(981): Config changed: { scale=1.0 imsi=310/4 loc=en_US touch=3 keys=2/1/2 nav=2/2 orien=2 layout=34 uiMode=17 seq=30}
12-03 14:47:41.811: DEBUG/dalvikvm(981): GC_EXTERNAL_ALLOC freed 8025 objects / 388808 bytes in 208ms
12-03 14:47:41.999: DEBUG/AlarmManagerService(981): Kernel timezone updated to 300 minutes west of GMT
12-03 14:47:42.288: INFO/[com.specialed.receiver.CameraReceiver](13152): Suck It Android!