even putting the test id does not appear, I've made countless attempts, I found that it can be linked to mInterstitialAd.isLoaded (), but I can't solve it
I also tried to make modifications to the mInterstitialAd.setAdListener, nothing else happens, can someone help me?
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
public class SplashActivity extends Activity {
private InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener()
{
#Override
public void onAdClosed() {
super.onAdClosed();
doFunc();
}
}
);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
if(mInterstitialAd.isLoaded())
{
mInterstitialAd.show();
}else
{
doFunc();
}
}
},5000);
}
private void doFunc() {
startActivity(new Intent(SplashActivity.this,MainActivity.class));
//
}
}
Related
please can exo player a hls stream like this
http://m3ulink.com:7899/gtZcA8Ugs/po5dA7Vm07/111804
I can play hls links with this .m3u8 file extension but I cant play those without the .m3u8 file extension
If anyone could help i will be grateful. Please i am at the beginner level so if someone can help me look into this thanks
//code
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
public class VideoPlayerActivity extends AppCompatActivity {
private PlayerView videoPlayer;
private SimpleExoPlayer simpleExoPlayer;
private static final String FILE_URL = "";
ProgressBar progressBar;
ImageView btFullScreen;
boolean flag = false;
private Handler mainHandler;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_video_player);
videoPlayer = findViewById(R.id.exo_player);
progressBar = findViewById(R.id.progress_bar);
btFullScreen = videoPlayer.findViewById(R.id.bt_fullscreen);
setUpExoplayer(getIntent().getStringExtra("url"));
simpleExoPlayer.addListener(new Player.EventListener() {
#Override
public void onTimelineChanged(Timeline timeline, #Nullable Object manifest, int reason) {
}
#Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
#Override
public void onLoadingChanged(boolean isLoading) {
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_BUFFERING) {
progressBar.setVisibility(View.VISIBLE);
} else if (playbackState == Player.STATE_READY) {
progressBar.setVisibility(View.GONE);
}
}
#Override
public void onRepeatModeChanged(int repeatMode) {
}
#Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}
#Override
public void onPlayerError(ExoPlaybackException error) {
}
#Override
public void onPositionDiscontinuity(int reason) {
}
#Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
#Override
public void onSeekProcessed() {
}
});
btFullScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (flag) {
btFullScreen.setImageDrawable(getResources().getDrawable(R.drawable.ic_fullscreen));
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
flag = false;
} else {
btFullScreen.setImageDrawable(getResources().getDrawable(R.drawable.ic_fullscreen_exit));
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
flag = true;
}
}
});
}
private void setUpExoplayer(String url) {
new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new
AdaptiveTrackSelection.Factory();
TrackSelector trackSelector = new
DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
Handler mainHandler = new Handler();
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
videoPlayer.setPlayer(simpleExoPlayer);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,"");
MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url),mainHandler,null );
videoPlayer.setKeepScreenOn(true);
simpleExoPlayer.prepare(mediaSource);
simpleExoPlayer.setPlayWhenReady(true);
}
#Override
protected void onDestroy() {
super.onDestroy();
simpleExoPlayer.release();
}
#Override
protected void onPause() {
super.onPause();
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.getPlaybackState();
}
#Override
protected void onRestart() {
super.onRestart();
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.getPlaybackState();
}
}
I am trying to embed Exo player into my Android app to play m3u8 files but it isn't working.
I used the code below to initiate the player activity.
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
public class VideoPlayerActivity extends AppCompatActivity {
private PlayerView videoPlayer;
private SimpleExoPlayer simpleExoPlayer;
private static final String FILE_URL = "";
ProgressBar progressBar;
ImageView btFullScreen;
boolean flag = false;
Handler mainHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_video_player);
videoPlayer = findViewById(R.id.exo_player);
progressBar = findViewById(R.id.progress_bar);
btFullScreen = videoPlayer.findViewById(R.id.bt_fullscreen);
setUpExoplayer(getIntent().getStringExtra("url"));
simpleExoPlayer.addListener(new Player.EventListener() {
#Override
public void onTimelineChanged(Timeline timeline, #Nullable Object manifest, int reason) {
}
#Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
#Override
public void onLoadingChanged(boolean isLoading) {
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_BUFFERING) {
progressBar.setVisibility(View.VISIBLE);
} else if (playbackState == Player.STATE_READY) {
progressBar.setVisibility(View.GONE);
}
}
#Override
public void onRepeatModeChanged(int repeatMode) {
}
#Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}
#Override
public void onPlayerError(ExoPlaybackException error) {
}
#Override
public void onPositionDiscontinuity(int reason) {
}
#Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
#Override
public void onSeekProcessed() {
}
});
btFullScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (flag) {
btFullScreen.setImageDrawable(getResources().getDrawable(R.drawable.ic_fullscreen));
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
flag = false;
} else {
btFullScreen.setImageDrawable(getResources().getDrawable(R.drawable.ic_fullscreen_exit));
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
flag = true;
}
}
});
}
private void setUpExoplayer(String url) {
LoadControl loadControl = new DefaultLoadControl();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(
new AdaptiveTrackSelection.Factory(bandwidthMeter)
);
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
videoPlayer.setPlayer(simpleExoPlayer);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "Livefootballarena"));
MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url));
videoPlayer.setKeepScreenOn(true);
simpleExoPlayer.prepare(mediaSource);
simpleExoPlayer.setPlayWhenReady(true);
}
#Override
protected void onPause() {
super.onPause();
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.getPlaybackState();
}
#Override
protected void onRestart() {
super.onRestart();
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.getPlaybackState();
}
}
}
I have been struggling with this for a while, though I can play mp4 videos if I change the hls source to mediasource.
I m trying to create an webapp with file upload possibility.
I have gone through some queries listed in StackOverflow as well for solution no this like
File Upload in WebView
However when applied the same in my mainactivity, couldn't resolve some errors showing with red underlines.
Here's my MainActivity.java:
package com.pack.packname;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import android.os.Handler;
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webviewid);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://google.com/");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDomStorageEnabled(true);
}
private boolean doubleBackToExitPressedOnce = false;
#Override
protected void onResume() {
super.onResume();
// .... other stuff in my onResume ....
this.doubleBackToExitPressedOnce = false;
}
#Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
if(webView.canGoBack()){
webView.goBack();
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
doubleBackToExitPressedOnce=false;
}
}, 2000);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
protected class CustomWebChromeClient extends WebChromeClient {
// For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
context.mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
context.startActivityForResult(Intent.createChooser(i, "File Chooser"), MainActivity.FILECHOOSER_RESULTCODE);
}
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser(uploadMsg, "");
}
}
}
}
I have added an image as well to check the errors that are causing as well.
Any help is greatly appreciated..
package com.pack.packname;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import android.os.Handler;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_SELECT_FILE = 100;
private final static int FILE_CHOOSER_RESULT_CODE = 1;
private ValueCallback<Uri> mUploadMessage;
private ValueCallback<Uri[]> uploadMessage;
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webviewid);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://google.com/");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDomStorageEnabled(true);
webView..setWebChromeClient(new WebChromeClient() {
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
if (uploadMessage != null) {
uploadMessage.onReceiveValue(null);
uploadMessage = null;
}
uploadMessage = filePathCallback;
Intent intent = fileChooserParams.createIntent();
try {
startActivityForResult(intent, REQUEST_SELECT_FILE);
} catch (ActivityNotFoundException e) {
uploadMessage = null;
Toast.makeText(getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();
return false;
}
return true;
}
});
}
private boolean doubleBackToExitPressedOnce = false;
#Override
protected void onResume() {
super.onResume();
// .... other stuff in my onResume ....
this.doubleBackToExitPressedOnce = false;
}
#Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
if(webView.canGoBack()){
webView.goBack();
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
doubleBackToExitPressedOnce=false;
}
}, 2000);
}
}
try this code
I am able to use text using rxjava and rxandroid in my code using Textview. Now i m thinking of replacing the textview with imageview and displaying the drawable on the imageview. But I m getting errors. Since, I m new to rxjava, I m probably sure that I m missing something. An help would be really gr8!
Since to show a text, we used the parameter as String...So I thought for a drawable, I thought I might need the parameter as a Drawable...But its giving error..
package com.prajwal.rxjava_rxandroid;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;
public class MainActivity extends AppCompatActivity {
ImageView textView;
Observable<Integer> stringObservable;
DisposableObserver<Drawable> disposableObserver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textview);
stringObservable = Observable.just(R.drawable.ic_launcher_background);
disposableObserver = new DisposableObserver<Drawable>() {
#Override
public void onNext(Drawable drawable) {
Glide.with(getApplicationContext()).load(drawable).into(textView);
}
#Override
public void onError(Throwable e) {
}
#Override
public void onComplete() {
}
};
stringObservable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(disposableObserver);
}
#Override
protected void onDestroy() {
super.onDestroy();
disposableObserver.dispose();
}
}
Error: Cannot resolve method subscribe(Drawable)
Find out the solution:
package com.prajwal.rxjava_rxandroid;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;
public class MainActivity extends AppCompatActivity {
ImageView textView;
Observable<Integer> stringObservable;
DisposableObserver<Integer> disposableObserver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textview);
stringObservable = Observable.just(R.drawable.ic_launcher_background);
/*
stringObserver = new Observer<String>() {
#Override
public void onSubscribe(Disposable d) {
}
#Override
public void onNext(String s) {
textView.setText(s); //emitted data is set to textview.
}
#Override
public void onError(Throwable e) {
}
#Override
public void onComplete() {
}
};
*/
disposableObserver = new DisposableObserver<Integer>() {
#Override
public void onNext(Integer integer) {
Glide.with(getApplicationContext()).load(integer).asBitmap().into(textView);
}
#Override
public void onError(Throwable e) {
}
#Override
public void onComplete() {
}
};
stringObservable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(disposableObserver);
}
#Override
protected void onDestroy() {
super.onDestroy();
disposableObserver.dispose();
}
}
I was passing the parameter as Drawable whereas I needed to pass the
parameter as an Integer since .load() of Glide doesnt take Drawable as
a parameter.
So, I am creating an AI music player app. Everything seems fine but whenever I give it some voice command, it does not display the required message.
I have tried using different emulators and using different android versions. None of those worked.
package com.learning.intelligentmusicplayer;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
private RelativeLayout parentRelativeLayout;
private SpeechRecognizer speechRecognizer;
private Intent speechRecogniserIntent;
private String keeper="";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkVoiceCommandPermission();
parentRelativeLayout = findViewById(R.id.parentRelativeLayout);
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(MainActivity.this);
speechRecogniserIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechRecogniserIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM );
speechRecogniserIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
speechRecognizer.setRecognitionListener(new RecognitionListener() {
#Override
public void onReadyForSpeech(Bundle bundle) {
}
#Override
public void onBeginningOfSpeech() {
}
#Override
public void onRmsChanged(float v) {
}
#Override
public void onBufferReceived(byte[] bytes) {
}
#Override
public void onEndOfSpeech() {
}
#Override
public void onError(int i) {
}
#Override
public void onResults(Bundle bundle) {
ArrayList<String> matchesFound = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if(matchesFound!=null)
{
keeper = matchesFound.get(0);
Toast.makeText(MainActivity.this, "Result = "+keeper, Toast.LENGTH_LONG).show();
}
}
#Override
public void onPartialResults(Bundle bundle) {
}
#Override
public void onEvent(int i, Bundle bundle) {
}
});
parentRelativeLayout.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch(motionEvent.getAction())
{
case MotionEvent.ACTION_DOWN:
speechRecognizer.startListening(speechRecogniserIntent);
keeper="";
break;
case MotionEvent.ACTION_UP:
speechRecognizer.stopListening();
break;
}
return false;
}
});
}
private void checkVoiceCommandPermission()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
if(!(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO)==PackageManager.PERMISSION_GRANTED))
{
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package: "+getPackageName()));
startActivity(intent);
finish();
}
}
}
}
There is no error message. I hear the beep sound for recording message but it does not display the message on screen.
Downloading Google voice assistant fixed my problem!