Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.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 当照相机应用程序拍摄新照片时,如何生成通知?_Android_Android Notifications_Intentfilter_Android Camera Intent_Android Broadcastreceiver - Fatal编程技术网

Android 当照相机应用程序拍摄新照片时,如何生成通知?

Android 当照相机应用程序拍摄新照片时,如何生成通知?,android,android-notifications,intentfilter,android-camera-intent,android-broadcastreceiver,Android,Android Notifications,Intentfilter,Android Camera Intent,Android Broadcastreceiver,当从照相机应用程序拍摄新照片时,我想从我的应用程序创建通知。我想在我的应用程序未运行时实现这一点。我用广播接收器来做这个。 这是我的密码 在Android清单中 <receiver android:name=".receivers.CameraEventReceiver" android:label="CameraEventReceiver" android:enabled="true"> <intent-filter> &

当从照相机应用程序拍摄新照片时,我想从我的应用程序创建通知。我想在我的应用程序未运行时实现这一点。我用广播接收器来做这个。 这是我的密码

在Android清单中

<receiver
    android:name=".receivers.CameraEventReceiver"
    android:label="CameraEventReceiver"
    android:enabled="true">
    <intent-filter>
        <action android:name="android.hardware.action.NEW_PICTURE" />

        <data android:mimeType="image/*" />
    </intent-filter>
</receiver>

在我的听筒课上

public class CameraEventReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

            NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){

                NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "my channel name", NotificationManager.IMPORTANCE_HIGH);
                manager.createNotificationChannel(channel);
            }
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID")
                    .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Picture Taken")
                    .setContentText("here is the uri : "+intent.getData())
                    .setDefaults(NotificationCompat.DEFAULT_VIBRATE)
                    .setAutoCancel(true);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
                builder.setPriority(NotificationCompat.PRIORITY_HIGH);
            }

            manager.notify(222, builder.build());
        }
    }
公共类CameraEventReceiver扩展了BroadcastReceiver{
@凌驾
公共void onReceive(上下文、意图){
NotificationManager=(NotificationManager)context.getSystemService(context.NOTIFICATION\u服务);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.O){
NotificationChannel=新建NotificationChannel(“频道ID”、“我的频道名称”、NotificationManager.IMPORTANCE\u HIGH”);
manager.createNotificationChannel(频道);
}
NotificationCompat.Builder=新建NotificationCompat.Builder(上下文,“频道ID”)
.setColor(ContextCompat.getColor(context,R.color.colorPrimary))
.setSmallIcon(R.mipmap.ic_启动器)
.setContentTitle(“拍摄的照片”)
.setContentText(“这是uri:+intent.getData())
.setDefaults(NotificationCompat.DEFAULT\u振动)
.setAutoCancel(真);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.JELLY\u BEAN&&Build.VERSION.SDK\u INT
当应用程序运行时,Android 6.0运行良好。。。 但它不适用于新版本我能做些什么来实现这一点? 我希望它支持所有android版本大于4.1的设备(JELLY_BEAN)

提前谢谢

但它不适用于新版本

对。这些广播不再受支持。看

我能做些什么来实现这一点

无论是使用
ACTION\u IMAGE\u CAPTURE
、摄像头API还是库(例如Fotoapparat、CameraKit Android),都可以自己拍照

该广播没有直接的替代品,也不要求摄像头应用程序触发该广播


您可以使用来监视
MediaStore
的更改。但是,我不知道您如何将其限制为仅由照相机应用程序拍摄的照片。

我在新短信出现时就已经实现了,我也面临着同样的问题。我在清单文件中放了以下几行

<intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.INPUT_METHOD_CHANGED" />
</intent-filter> 


但在本文档中。他们说“在安卓系统中,这个广播已经恢复,但只针对注册的接收者”。。所以它应该在Android O上工作,对吗?@user9333500:所谓“注册接收者”,我相信他们的意思是通过
registerReceiver()
在运行时注册。当您的进程未运行时,这将不起作用。我尝试在“活动”中的运行时使用registerReceiver(),但它仍然不起作用。@user9333500:那么文档可能是错误的。或者,该特定设备上的摄像头应用程序可能不会触发此广播。请记住,有数百个摄像头应用程序。没有要求他们中的任何人触发这个广播。是的。这是正确的。。。我尝试使用默认的照相机应用程序。无论如何,感谢您的回复。请尝试使用最新版本android的通知频道,请参阅以下内容: