Skip to content

Instantly share code, notes, and snippets.

View fevziomurtekin's full-sized avatar
:octocat:

Fevzi Ömür Tekin fevziomurtekin

:octocat:
View GitHub Profile
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
private int id=32489;
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@fevziomurtekin
fevziomurtekin / androidmanifest.xml
Created March 23, 2018 19:54
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kuarkdijital.samam">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
@fevziomurtekin
fevziomurtekin / build.gradle
Created January 25, 2019 11:19
build.gradle in app
// DialogFlow SDK depencies
implementation 'ai.api:sdk:2.0.7@aar'
implementation 'ai.api:libai:1.6.12'
// Java v2
implementation 'com.google.cloud:google-cloud-dialogflow:0.67.0-alpha'
implementation 'io.grpc:grpc-okhttp:1.15.1'
private fun initAsisstant() {
try {
val stream = resources.openRawResource(R.raw.asistan)
val credentials = GoogleCredentials.fromStream(stream)
val projectId = (credentials as ServiceAccountCredentials).projectId
val settingsBuilder = SessionsSettings.newBuilder()
val sessionsSettings =
settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build()
client = SessionsClient.create(sessionsSettings)
class RequestTask : AsyncTask<Void, Void, DetectIntentResponse> {
var activity: Activity? = null
private var session: SessionName? = null
private var sessionsClient: SessionsClient? = null
private var queryInput: QueryInput? = null
constructor(activity: Activity,session:SessionName,sessionsClient: SessionsClient,queryInput: QueryInput){
this.activity=activity
private fun sendMicrophoneMessage(view:View){
val intent: Intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
intent.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
intent.putExtra(
RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt)
private fun initAsisstantVoice() {
asistan_voice= TextToSpeech(applicationContext,object : TextToSpeech.OnInitListener {
override fun onInit(status: Int) {
if (status!=TextToSpeech.ERROR){
asistan_voice?.language=Locale("tr")
}
}
})
fun onResult(response: DetectIntentResponse?) {
try {
if (response != null) {
var botReply:String=""
if(response.queryResult.fulfillmentText==" ")
botReply= response.queryResult.fulfillmentMessagesList[0].text.textList[0].toString()
else
botReply= response.queryResult.fulfillmentText
appendText(botReply, BOT)
private fun appendText(message: String, type: Int) {
val layout: FrameLayout
when (type) {
USER -> layout = appendUserText()
BOT -> layout = appendBotText()
else -> layout = appendBotText()
}
layout.isFocusableInTouchMode = true
linear_chat.addView(layout)
val tv = layout.findViewById<TextView>(R.id.chatMsg)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when(requestCode){
SPEECH_INPUT->{
if(resultCode== Activity.RESULT_OK
&& data !=null){
val result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
edittext.text=Editable.Factory.getInstance().newEditable(result[0])
sendMessage(send)
}