I've been following some tutorials on how to make an app with API.ai integrated with it. But so far, unlike the tutorials, it gives me an error when I apply the Recognition Engine. This is the code on my Manifest.
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import ai.api.AIConfiguration;
import ai.api.AIListener;
import ai.api.android.AIService;
import ai.api.model.AIError;
import ai.api.model.AIResponse;
import ai.api.model.Result;
import ai.api.ui.AIButton;
public class MainActivity extends AppCompatActivity implements AIListener{
private AIService aiService;
TextView t;
#Override
protected void onCreate(Bundle savedInstanceState) {
AIService aiService;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t=findViewById(R.id.textView);
int permission = ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO);
if (permission != PackageManager.PERMISSION_GRANTED) {
makeRequest();
}
final AIConfiguration config = new AIConfiguration("CLIENT_ACCESS_TOKEN",
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.System);
aiService = AIService.getService(this, (ai.api.android.AIConfiguration) config);
aiService.setListener(this);
}
This line of code: AIConfiguration.RecognitionEngine.System);
I have all the dependencies that API.ai requests to add to the app gradle.
It says "Cannot resolve the symbol". Does anyone know why this error occurs or how to fix it?
You need to add "import ai.api.android.AIConfiguration;"
Related
I have been trying to figure out why the toast is not showing. from the code, the onReceive method does get executed and change the button color, but the Toast does not display. I dont know why.
client = new Client(
(publisher, topic, params) -> runOnUiThread(
() -> onReceive((Publisher) publisher, topic, params)
));
client.connectToServer("192.168.3.52",5050);
private void onReceive(Publisher publisher, String topic, Map<String, Object> params) {
sendBtn.setBackgroundColor(getColor(R.color.white));
Toast.makeText(MainActivity.this, "Hey", Toast.LENGTH_LONG).show();
}
Imports
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Class name
public class MainActivity extends AppCompatActivity {
hey can you share your file name and import section ........
or else try to run on clicklistener after sendbtn and try to link with your button
i want to show my post in webview but i fatch error of "Inconvertible type cannot cast android.view.view to javafx.scene.web.webview" in android studio.
how can i solve it please help me.
WPPostDetails.java
package com.ejobbox.ejobbox;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import javafx.scene.web.WebView;
public class WPPostDetails extends AppCompatActivity {
TextView title;
WebView webView;
#Override
public void onCreate(#Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_postdetails);
title=(TextView) findViewById(R.id.title);
webView= (WebView) findViewById(R.id.postwebview);
Intent i = getIntent();
int position = i.getExtras().getInt("itemPosition");
//title.setText(MainActivity.mListPost.get(position).getTitle().getRendered());
Log.e("WpPostDetails","title is"+MainActivity.mListPost.get(position).getTitle().getRendered());
webView.getSettings().setJavaScriptEnabled(true);
}
}
You import a wrong WebView class. Remove import javafx.scene.web.WebView; and add import android.webkit.WebView
Import
android.webkit.WebView instead of
javafx.scene.web.WebView;
I was watching a youtube tutorial (Firebase storage and around 14 minutes I got this error code:
Cannot resolve method 'getInstance()'
Can someone help me resolve it? I am pretty new to Java and have been watch tutorials to get the understanding right. I know this is a small detail, but it has been really frustrating.
package bfb.ess.myapplicationbfb;
import android.app.ProgressDialog;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.storage.UploadTask;
import java.io.File;
import java.io.IOException;
public class speakp extends AppCompatActivity {
private Button mRecordBtn;
private TextView mRecordlabel;
private MediaRecorder mRecorder;
private String mFileName = null;
private static final String LOG_TAG = "Record_log";
private StorageReference mStorage;
private ProgressDialog mProgress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recordpage);
mStorage = FirebaseStorage.getInstance().getReference(); /*RIGHT HERE*/
mRecordlabel = (TextView) findViewById(R.id.recordlabel);
mRecordBtn =(Button) findViewById(R.id.recordBtn);
I am attempting to currently create an Android app that will follow a user's route of travel. Although at this point I am simply attempting to get their current location. I have attempted several methods involving LocationListeners and the like, but either get no result or errors that the guide never mentions. Some use it in the HTML5 pages but I don't really know enough to do it that way. Below I have the code that, in theory, should get the user's location and place a marker there.
Admittedly there are a lot of imports, mostly from me stumbling my way through this project and trying different locations to other problems that have popped up. The end result will be that the user completes a perimeter of something and it will get the area. While getting the area from a series of LatLngs is doable, the problem is getting the actual perimeter drawn by the user walking it. I am hoping to, at the moment, get the user's location repeatedly into a list of LatLngs and use that, but I am open to other suggestions.
package ideo.farmerhelp;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Looper;
import android.support.v4.app.FragmentActivity;
import android.graphics.Color;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.Scope;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.common.api.zzc;
import com.google.android.gms.common.api.zzl;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.google.maps.android.SphericalUtil;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, OnMarkerDragListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener, android.location.LocationListener, GoogleMap.OnMapClickListener {
TextView tv;
private GoogleApiClient mGoogleApiClient;
public static final String TAG = MapsActivity.class.getSimpleName();
private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
private LocationRequest mLocationRequest;
private GoogleMap mMap;
SupportMapFragment mapFragment;
TextView txtlat;
String lat;
String provider;
protected String latitude, longitude;
protected boolean gps_Enabled, network_enabled;
#Override
protected void onCreate(Bundle savedInstanceState) { //On map create
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map); //Create a support map fragment
mapFragment.getMapAsync(this);
tv = (TextView) findViewById(R.id.area);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); //Requests that I cast the fourth parameter to android.location.LocationListener, doing so results in a castexception.
}
}
I am new for the android apps developing, I have created an sample app with a html design included with it.
when i was trying to install the app it displays
"The application has stopped unexpectedly. Please try again" in the device.
Please help me. Thanks in Advance.
MainActivity.java:
package com.example.ship;
import android.net.ConnectivityManager;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;
import com.phonegap.*;
public class MainActivity extends DroidGap {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
super.init();
super.loadUrl("ship/assets/www/ship/task.html");
}
}
Try this,
super.loadUrl("file:///android_asset/www/ship/task.html");