popup not open in webview really - android-webview

webview working well but pop-up does not open
public class MainActivity extends AppCompatActivity {
TextView txtMarquee;
private CardView btnDollar, btnFlexiload, btnNewAccount, btnContact, btnOffers, btnNotices, btnYT, btnFB;
private WebView dollarLoad;
public MainActivity() {
}
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtMarquee = findViewById(R.id.marqueeText);
txtMarquee.setSelected(true);
//Dollar
CardView buttonDollar = findViewById(R.id.btnDollar);
buttonDollar.setOnClickListener(view -> {
setContentView(R.layout.activity_doller);
dollarLoad = findViewById(R.id.dollarLoad);
dollarLoad.setWebViewClient(new WebViewClient());
dollarLoad.loadUrl("https://iteldollar.com");
WebSettings webSettings = dollarLoad.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setAllowContentAccess(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDatabaseEnabled(true);
webSettings.setMinimumFontSize(1);
webSettings.setMinimumLogicalFontSize(1);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
});

Related

In flutter, how can I register if the headset is suddenly unplugged

Android java offers to register a BroadcastReceiver checking for AudioManager.ACTION_AUDIO_BECOMING_NOISY, to listen to the system broadcasting an ACTION_AUDIO_BECOMING_NOISY message, when a sound is played but then the headset is unplugged or a Bluetooth device disconnected.
Is there a way to do this in flutter, to respond to the event that e.g. a headset is unplugged while playing sound?
With the hint in the answer below, I got this going, but only in DEBUG mode, not in a release ready APK. This is what I did:
Java:
public class MainActivity extends FlutterActivity {
public static final String STREAM = "XXX";
public static String TAG = "player/java file";
private IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
private BecomingNoisyReceiver myNoisyAudioStreamReceiver = null;
private class BecomingNoisyReceiver extends BroadcastReceiver {
final EventChannel.EventSink eventSink;
BecomingNoisyReceiver(EventChannel.EventSink eventSink){
super();
this.eventSink = eventSink;
}
#Override
public void onReceive(Context context, Intent intent) {
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) {
Log.w(TAG, "Noisy Receiver activated");
eventSink.success("success");
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new EventChannel(getFlutterView(), STREAM).setStreamHandler(
new EventChannel.StreamHandler() {
#Override
public void onListen(Object args, final EventChannel.EventSink events) {
Log.w(TAG, "adding listener");
myNoisyAudioStreamReceiver = new BecomingNoisyReceiver(events);
registerReceiver(myNoisyAudioStreamReceiver, intentFilter);
}
#Override
public void onCancel(Object args) {
Log.w(TAG, "cancelling listener");
unregisterReceiver(myNoisyAudioStreamReceiver);
}
}
);
}
}
And in Dart, in the class extending State:
static const platform = const EventChannel('XXX');
StreamSubscription _noisySubscription;
in initState():
_noisySubscription = null;
Whenever I need it:
if(_noisySubscription == null){
_noisySubscription = platform.receiveBroadcastStream().listen(_handleNoisy);
}
Whenever it needs to stop:
_noisySubscription.cancel().then((_){_noisySubscription = null;});
Any hint, how to fix this problem?
You can use EventChannel to communicate an event on native part (Android) to Dart part. Ref: https://medium.com/#svenasse/flutter-event-channels-89623ce6c017
(Pseudo) Sample Code (it's not in runable state, but hopefully it gives you idea):
Dart part
void _handleNoisy(noisyEvent) {
debugPrint("noisyEvent $noisyEvent");
}
static const stream =
const EventChannel('com.yourcompany.yourapp/ACTION_AUDIO_BECOMING_NOISY');
StreamSubscription _noisySubscription = stream.receiveBroadcastStream().listen(_handleNoisy);
Java part
public class MainActivity extends FlutterActivity {
public static final String STREAM = "com.yourcompany.yourapp/ACTION_AUDIO_BECOMING_NOISY";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new EventChannel(getFlutterView(), STREAM).setStreamHandler(
new EventChannel.StreamHandler() {
#Override
public void onListen(Object args, final EventChannel.EventSink dartEvents) {
Log.w(TAG, "adding listener");
noisyEvent = ... // Register
private class BecomingNoisyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) {
dartEvents.success("the payload you want to pass to dart")
}
}
}
}
#Override
public void onCancel(Object args) {
Log.w(TAG, "cancelling listener");
}
}
);
}
}

ToggleButton code in Android Studio unexpectedly crashes the App

My project is a music player that has a ToggleButton for play/pause.
I tried to run a code in Android Studio, but it unexpectedly crashes the App.
I am trying to follow up some tutorials on the internet and YouTube guides, but nothing works so far.
Here is the code that I'm running in the MainActivity:
package com.example.hamzeh.playpausestop;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
MediaPlayer Sound;
int pause;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void stop(View view)
{
Sound.release();
}
public void onToggleClicked(View view)
{
boolean checked = ((ToggleButton)view).isChecked();
if (checked)
{
Sound.start();
//Play
}
else
{
Sound.pause();
pause = Sound.getCurrentPosition();
//Pause
}
}
}
Post your logcat result i will give better answer your class have no any initialization of sound object and also check in xml onClick tag is onToggleClicked and stop is defined or not.
public class MainActivity extends AppCompatActivity {
MediaPlayer Sound;
int pause;
//
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize Mediaplayer here for single sound
Sound= MediaPlayer.create(MainActivity.this, R.raw.UrSoundFileInRawFolder);
}
public void stop(View view){
Sound.release();
}
public void onToggleClicked(View view){
boolean checked = ((ToggleButton)view).isChecked();
if (checked && !Sound.isPlaying() && Sound!=null){
Sound.start();
}
else if(Sound.isPlaying()){
Sound.pause();
pause = Sound.getCurrentPosition();
} esle{
Toast.makeText(MainActivity.this, "SomeThingWrong", Toast.LENGTH_SHORT).show();
}
}
}

Eclipse DisplayMessageActivity error

I have a question about an error I get in Eclipse.
Eclipse says "The nested type DisplayMessageActivity cannot hide an enclosing type"
This is my script:
package com.example.warzonegaming;
public class DisplayMessageActivity {
public class DisplayMessageActivity extends Activity {
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
}
Does someone knows an fix for this, because I can't go further now.
Regards
Try learn basics of javapackage com.example.warzonegaming;
public class DisplayMessageActivity extends Activity {
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}

Drawable layout on listview with ArrayAdapter

How can I set one drawable in my layout to use listview?
this is my code and funcion normally but i can't click on item:
public class ListMobileActivity extends Activity {
static final String[] Ristoranti = new String[] { "Osteria Mingot", "Cecchini", "Barrique", "Mediterraneo"};
ListView listView1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
ListView listView1 = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_mobile, R.id.label, Ristoranti);
listView1.setAdapter(adapter);
}
If I extends Activity I can set my drawable, if I extends ListActivity I can Click on the Item but the drawable appear in every item
protected void onItemClick(ListView l, View v, int position, long id) {
//get selected items
// String selectedValue = (String) getListAdapter().getItem(position);
//Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
}

play mp4 from sdcard of emulator 2.2

public class MainActivity extends Activity{
MediaController mediaController;
MediaPlayer mp;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Uri uri = Uri.parse("android.resource//org.me.vid_sample/raw/lahainaharbor");
File path = new File("/sdcard/Waileasuntest1.mp4");
VideoView videoView = (VideoView) findViewById(R.id.surface);
videoView.setVideoPath(path.getAbsolutePath());
mediaController = new MediaController(this);
mediaController.setMediaPlayer(videoView);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
Check in device. I am sure it works.