Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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
Java 构建一个应用程序,该应用程序(使用语音)宣布通知栏中的所有通知_Java_Android - Fatal编程技术网

Java 构建一个应用程序,该应用程序(使用语音)宣布通知栏中的所有通知

Java 构建一个应用程序,该应用程序(使用语音)宣布通知栏中的所有通知,java,android,Java,Android,我试过很多东西,但没有一件奏效。我没有收到将在手机通知栏中发布/告知通知的代码。它应该在通知栏上宣布所有应用程序通知,如同呼叫广播器应用程序工作通知一样。我尝试过很多事情,但都失败了。任何帮助都会对我很有帮助。下面给出的解决方案是我尝试过的一件事。但是有很多错误 public class notif extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { sup

我试过很多东西,但没有一件奏效。我没有收到将在手机通知栏中发布/告知通知的代码。它应该在通知栏上宣布所有应用程序通知,如同呼叫广播器应用程序工作通知一样。我尝试过很多事情,但都失败了。任何帮助都会对我很有帮助。下面给出的解决方案是我尝试过的一件事。但是有很多错误

public class notif extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notif);


    TextToSpeech tts = new TextToSpeech(this/*context*/, new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {//Checking For Success

                int result = tts.setLanguage(Locale.US);//Setting Language

                if (result == TextToSpeech.LANG_MISSING_DATA
                        || result == TextToSpeech.LANG_NOT_SUPPORTED) {//Checking If Language Available
                    Log.e("TTS", "This Language is not supported");
                } else {
                    Log.d("TTS","Language Loaded...");
                }

            } else {
                Log.e("TTS", "Initilization Failed!");
            }
        }
    });
    NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher) // notification icon
            .setContentTitle(title) // title for notification
            .setContentText(message) // message for notification
            .setAutoCancel(true); // clear notification after click
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this,0,intent, Intent.FLAG_ACTIVITY_NEW_TASK);
    mBuilder.setContentIntent(pi);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
    speakOut(message);//Function call <- <- <-

   }
private void speakOut(String notification)
{
    tts.speak(notification, TextToSpeech.QUEUE_FLUSH, null);//Making The TextToSpeech Speak

}
公共类notif扩展AppCompative活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u notif);
TextToSpeech tts=new TextToSpeech(this/*context*/,new TextToSpeech.OnInitListener(){
@凌驾
公共无效onInit(int状态){
如果(status==TextToSpeech.SUCCESS){//正在检查是否成功
int result=tts.setLanguage(Locale.US);//设置语言
if(result==TextToSpeech.LANG_缺少_数据
||结果==TextToSpeech.LANG\u不受支持){//检查语言是否可用
Log.e(“TTS”,“不支持这种语言”);
}否则{
Log.d(“TTS”,“语言加载…”);
}
}否则{
Log.e(“TTS”,“初始化失败!”);
}
}
});
NotificationCompat.Builder mBuilder=新建NotificationCompat.Builder(此)
.setSmallIcon(R.drawable.ic_启动器)//通知图标
.setContentTitle(标题)//通知标题
.setContentText(消息)//用于通知的消息
.setAutoCancel(true);//单击后清除通知
意向意向=新意向(此,MainActivity.class);
PendingEvent pi=PendingEvent.getActivity(this,0,intent,intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
通知经理通知经理=
(NotificationManager)getSystemService(上下文通知服务);
mNotificationManager.notify(0,mBuilder.build());

speakOut(message);//函数调用您可以在显示通知时尝试使用
文本到语音的转换
例如:-

 TextToSpeech tts = new TextToSpeech(this/*context*/, new TextToSpeech.OnInitListener() {

    @Override
    public void onInit(int status) {
         if (status == TextToSpeech.SUCCESS) {//Checking For Success

        int result = tts.setLanguage(Locale.US);//Setting Language

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {//Checking If Language Available
            Log.e("TTS", "This Language is not supported");
        } else {
           Log.d("TTS","Language Loaded...")
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }
    }
});
NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher) // notification icon
            .setContentTitle(title) // title for notification
            .setContentText(message) // message for notification
            .setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
speakOut(message)//Function call <- <- <-
完整代码
:-

private void speakOut(String notification) 
    {
        tts.speak(notification, TextToSpeech.QUEUE_FLUSH, null);//Making The TextToSpeech Speak

    }
public class notif extends AppCompatActivity {
TextToSpeech tts;
String title,message; 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notif);

    title = "Your notification title";
    message = "Your notification body";
    tts = new TextToSpeech(this/*context*/, new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {//Checking For Success

                int result = tts.setLanguage(Locale.US);//Setting Language

                if (result == TextToSpeech.LANG_MISSING_DATA
                        || result == TextToSpeech.LANG_NOT_SUPPORTED) {//Checking If Language Available
                    Log.e("TTS", "This Language is not supported");
                } else {
                    Log.d("TTS","Language Loaded...");
                }

            } else {
                Log.e("TTS", "Initilization Failed!");
            }
        }
    });
    NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher) // notification icon
            .setContentTitle(title) // title for notification
            .setContentText(message) // message for notification
            .setAutoCancel(true); // clear notification after click
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this,0,intent, Intent.FLAG_ACTIVITY_NEW_TASK);
    mBuilder.setContentIntent(pi);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
    speakOut(message);//Function call <- <- <-

   }
公共类notif扩展AppCompative活动{
texttospeechtts;
字符串标题、消息;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u notif);
title=“您的通知标题”;
message=“您的通知正文”;
tts=new TextToSpeech(this/*context*/,new TextToSpeech.OnInitListener(){
@凌驾
公共无效onInit(int状态){
如果(status==TextToSpeech.SUCCESS){//正在检查是否成功
int result=tts.setLanguage(Locale.US);//设置语言
if(result==TextToSpeech.LANG_缺少_数据
||结果==TextToSpeech.LANG\u不受支持){//检查语言是否可用
Log.e(“TTS”,“不支持这种语言”);
}否则{
Log.d(“TTS”,“语言加载…”);
}
}否则{
Log.e(“TTS”,“初始化失败!”);
}
}
});
NotificationCompat.Builder mBuilder=新建NotificationCompat.Builder(此)
.setSmallIcon(R.drawable.ic_启动器)//通知图标
.setContentTitle(标题)//通知标题
.setContentText(消息)//用于通知的消息
.setAutoCancel(true);//单击后清除通知
意向意向=新意向(此,MainActivity.class);
PendingEvent pi=PendingEvent.getActivity(this,0,intent,intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
通知经理通知经理=
(NotificationManager)getSystemService(上下文通知服务);
mNotificationManager.notify(0,mBuilder.build());

speakOut(message);//函数调用请转到以了解如何以及在此处询问什么。对不起,先生,您想指出我的que中的错误吗?它基本上只说明非常(太)广泛的需求。告诉我们你尝试了很多东西,但它们都不起作用也没有帮助-因为我们不知道你尝试了什么。或者,如果事情不起作用,是因为你的代码都错了,或者是因为你可能以一种更微妙的错误方式使用了API。基本上,你的问题需要我们坐下来和你谈一段时间。并且at并不是这个社区所关注的。你可以问一些明确的问题,这些问题最好可以用一个单一的、全面的答案来回答。我只是问一些代码,它将在通知栏中宣布通知。例如:-as call announcer app announced name of caller。在这里,我希望有一个应用程序可以宣布通知n通知栏。先生,我正在为盲人开发这个应用程序。我知道它听起来很有趣,他们在使用它时可能会遇到很多问题,但我正在对此做一个简短的介绍。谢谢你的回答。希望它能对我起作用。我不是先生,因为我只有17岁,如果它有效或出现任何错误,请发表评论…@YashBhomledude it it not工作。我有上面的邮政编码。请检查一下,告诉我哪里错了。老兄,你能在任何一张桌子上帮我吗?因为它仍然给出错误,我非常需要解决这个问题。