Commit ea38dbde authored by RAUSHAN RAJ's avatar RAUSHAN RAJ

[Raushan] - voice working

parent d8480377
<!--
Copyright 2015 Blanyal D'Souza.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.blanyal.remindme" >
package="com.blanyal.remindme">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
tools:replace="android:icon,android:theme"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
tools:replace="android:icon,android:theme">
<activity android:name=".ReadTheMessage"></activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ReminderAddActivity"
android:label="@string/title_activity_add_reminder" />
<activity
android:name=".ReminderEditActivity"
android:label="@string/title_activity_edit_reminder" />
<activity
android:name=".LicencesActivity"
android:label="@string/title_activity_licenses" />
<activity android:name=".ReminderAddActivity"
android:label="@string/title_activity_add_reminder"/>
<activity android:name=".ReminderEditActivity"
android:label="@string/title_activity_edit_reminder"/>
<activity android:name=".LicencesActivity"
android:label="@string/title_activity_licenses"/>
<receiver android:name=".AlarmReceiver"/>
<receiver android:name=".AlarmReceiver" />
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".AlarmService"
android:enabled="true" />
</application>
</manifest>
\ No newline at end of file
......@@ -42,12 +42,22 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));
//
//Get notification title from Reminder Database
ReminderDatabase rb = new ReminderDatabase(context);
Reminder reminder = rb.getReminder(mReceivedID);
String mTitle = reminder.getTitle();
// Create intent to open ReminderEditActivity on notification click
Intent editIntent = new Intent(context, ReminderEditActivity.class);
editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
......@@ -68,8 +78,43 @@ public class AlarmReceiver extends BroadcastReceiver {
// NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// nManager.notify(mReceivedID, mBuilder.build());
NotificationHelper notificationHelper = new NotificationHelper(context,intent);
NotificationCompat.Builder nb = notificationHelper.getChannelNotification();
notificationHelper.getManager().notify(mReceivedID, nb.build());
// tts
// context.startService(new Intent(context, ReadTheMessage.class));
// String number = mTitle;
// Intent i = new Intent(this, ReadTheMessage.class);
// i.putExtra("MyNumber", number);
// startService(i);
//
Intent speechIntent = new Intent();
speechIntent.setClass(context, ReadTheMessage.class);
speechIntent.putExtra("MESSAGE",mTitle );
speechIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(speechIntent);
////
// Intent speechIntent = new Intent();
// speechIntent.putExtra("MESSAGE", "Bluetooth is on.");
// ReadTheMessage.enqueueWork(context, speechIntent);
//
}
public void setAlarm(Context context, Calendar calendar, int ID) {
......
......@@ -7,14 +7,19 @@ import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.speech.tts.TextToSpeech;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
public class NotificationHelper extends ContextWrapper {
......@@ -23,7 +28,12 @@ public class NotificationHelper extends ContextWrapper {
String mTitle;
PendingIntent mClick;
private NotificationManager mManager;
private TextToSpeech t1;
// public Uri getFileUri(){
//
//
// return
// }
public NotificationHelper(Context base,Intent intent) {
super(base);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......@@ -41,6 +51,8 @@ public class NotificationHelper extends ContextWrapper {
editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
mClick = PendingIntent.getActivity(base, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@TargetApi(Build.VERSION_CODES.O)
......@@ -59,17 +71,31 @@ public class NotificationHelper extends ContextWrapper {
}
public NotificationCompat.Builder getChannelNotification() {
return new NotificationCompat.Builder(getApplicationContext(), channelID)
//t1.speak(mTitle, TextToSpeech.QUEUE_FLUSH, null);
// t1.synthesizeToFile(mTitle, null, "/SDCARD/speak1.wav");
//Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/sample");
return new NotificationCompat.Builder(getApplicationContext(), channelID)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.ic_alarm_on_white_24dp)
.setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
.setTicker(mTitle)
.setContentText(mTitle)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
//.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
// .setSound(Uri.fromFile(new File("SDCARD/s1.mp3")))
.setSound(null)
.setContentIntent(mClick)
.setAutoCancel(true)
.setOnlyAlertOnce(true);
.setOnlyAlertOnce(false);
}
public TextToSpeech getTextToSpeech(){
return t1;
}
}
//function
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment