安卓的BroadcastReceiver没有停止摄像机意向行动 [英] Android BroadcastReceiver not stopping Camera Intent action

查看:116
本文介绍了安卓的BroadcastReceiver没有停止摄像机意向行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想'块'的摄像头动作,而我的应用程序被激活。在的onReceive 的方法被在BroadcastReceiver的执行,而是由LogCat中这似乎是在做意向已经执行打完。

的manifest.xml

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=COM安卓版code =1机器人:VERSIONNAME =1.0>
    <使用-SDK安卓的minSdkVersion =8/>
    <应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME
        机器人:screenOrientation =景观的android:可调试=真
        机器人:clearTaskOnLaunch =真正的>
        <接收器的Andr​​oid版本:NAME =com.receiver.CameraReceiver>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.CAMERA_BUTTON/>
            &所述; /意图滤光器>
        < /接收器>

        <活动机器人:名称=机器人主:标签=@字符串/ APP_NAME>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.DEFAULT/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
            <意向滤光器>
                <作用机器人:名称=android.media.action.IMAGE_CAPTURE/>
                <类机器人:名称=android.intent.category.DEFAULT/>
            &所述; /意图滤光器>
        < /活性GT;

    < /用途>


< /舱单>
 

com.receiver.CameraReceiver

 包com.receiver;

进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.Intent;
进口android.util.Log;

公共类CameraReceiver扩展的BroadcastReceiver {

    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        Log.i(this.toString(),吸它的Andr​​oid!);
        abortBroadcast();
    }

    @覆盖
    公共字符串的toString(){
        返回com.receiver.CameraReceiver;
    }
}
 

LogCat中

  12-03 14:47:41.171:信息/ ActivityManager(981):启动活动:意向{行为= android.intent.action.MAIN猫= [android.intent.category .LAUNCHER] FLG = 0x14000000 CMP = com.google.android.camera / com.android.camera.Camera}
12-03 14:47:41.288:信息/窗口管理器(981):设置旋转1,animFlags = 1
12-03 14:47:41.304:信息/ ActivityManager(981):配置改变:{规模= 1.0 IMSI =四分之三百一十LOC = EN_US触摸= 3键= 2/1/2 NAV = 2/2广州澳凌= 2的布局= 34 uiMode = 17以次= 30}
12-03 14:47:41.811:DEBUG / dalvikvm(981):GC_EXTERNAL_ALLOC释放8025对象/在208ms 388808字节
12-03 14:47:41.999:DEBUG / AlarmManagerService(981):内核时区更新至300分钟GMT以西
12-03 14:47:42.288:信息/ [com.specialed.receiver.CameraReceiver](13152):吸它的Andr​​oid!
 

解决方案

其实我能够加入到这样做

 <类机器人:名称=android.intent.category.DEFAULT/>
 

我的意图FITER,所以它看起来像:

 <接收器的Andr​​oid版本:NAME =com.receiver.CameraReceiver>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.CAMERA_BUTTON/>
        <类机器人:名称=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>
< /接收器>
 

这似乎是工作,任何人都可以发表评论我要,如果这还是机器人:优先级的正确方法

另外,如果我能阻止'震动'是发生在鼠标preSS这将是有益的。

谢谢!

I am trying to 'block' the Camera action while my application is active. The onReceive method is being executed on the BroadcastReceiver, but by the LogCat it seems to be doing so after the Intent has already been executed.

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!

解决方案

Actually I was able to do it by adding

<category android:name="android.intent.category.DEFAULT" />

to my intent fiter, so it looks like:

<receiver android:name="com.receiver.CameraReceiver">
    <intent-filter>
        <action android:name="android.intent.action.CAMERA_BUTTON" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

and this seems to be working, can anybody comment to if this or the android:priority is the proper way.

Also, if I can stop the 'Vibrate' that happens on button press that would be helpful.

Thanks!

这篇关于安卓的BroadcastReceiver没有停止摄像机意向行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆