WebView from Unity3d Android is not shown - android

I am trying to show a webview in unity3d from an Android Application.
The components of this test are:
Android library(has a method that i call for test purposes):
public void nonStaticMethod() {
Log.d("TAG", "Non-static method was called from my android class");
String url = "http://roadtoautomation.blogspot.ro/2014/02/road-to-setup-and-create-first-appium.html";
Toast.makeText(mContext, "URL: " + url, Toast.LENGTH_SHORT).show();
webView = new WebView(mContext);
Log.d("Interstitialactivity", "webView: " + webView);
Toast.makeText(mContext, "webView: " + webView, Toast.LENGTH_SHORT).show();
webView.loadUrl(url); // webview is not null
}
Mono code from class:
using (AndroidJavaClass javaInterClass = new AndroidJavaClass("mypackage.MyActivity")) {
if (javaInterClass != null) {
Debug.Log ("MyActivity class is NOT null");
try {
Debug.Log ("before my activity");
javaInterClass.Call ("nonStaticMethod");
Debug.Log ("after my activity");
} catch (Exception e) {
Debug.Log ("exception");
Console.WriteLine (e);
}
} else {
Debug.Log ("MyActivity class is null");
}
}
From the above code i can see the android class is not null, but the webview( from this "javaInterClass.Call ("nonStaticMethod");") is not shown.
Do i have to add a plugin in unity3d for supporting webview? Thanks.

If you want to open webview over Unity's UI you need an activity or you need to override unity's activity otherwise you can try this
Uri uri = Uri.parse("http://www.example.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
but it work same as Unity's Application.LoadUrl(url)

Related

xamrin android visual studio 2019 community version for WhatsApp chat with button click on specific number

I want to add button in my app. when I click on the button this will redirect me to WhatsApp chat having that specific number and chat with that number. I have the following code but its not working :(
public void Button1_Click(object sender, System.EventArgs e)
{
string phoneNumberWithCountryCode = "+9233623xxx";
string message = "Hallo";
StartActivity(new Intent(
Intent.ActionView, Android.Net.Uri.Parse("https://api.whatsapp.com/send?phone=" + phoneNumberWithCountryCode + "&text=" + message)));
}
Button button1 = FindViewById<Button>(Resource.Id.watsapp_op);
button1.Click += (sender, e) => {
Button1_Click(sender, e);
};
I saw the working sample , it sets Package in Intent , so try the following code .
private void OpenWhatsApp(Activity activity, string number, string message)
{
try
{
PackageManager packageManager = activity.PackageManager;
Intent i = new Intent(Intent.ActionView);
String url = "https://api.whatsapp.com/send?phone=" + number + "&text=" + URLEncoder.Encode(message, "UTF-8");
i.SetPackage("com.whatsapp");
i.SetData(Uri.Parse(url));
if (i.ResolveActivity(packageManager) != null)
{
activity.StartActivity(i);
}
else
{
//Error message
}
}
catch (Exception e)
{
// exception
}
}
Update
Does the button on the current content view or not ?
You can see SetContentView(Resource.Layout.activity_main) in OnCreate method .
You have to ensure the button is placed in activity_main.xml , if the button is in another layout , you have to find the view first .
var view = LayoutInflater.Inflate(Resource.Layout.anotherlayout,null);
var button = view.FindViewById<Button>(Resource.Id.button);

How to play IMA ads on Chromecast from sender app ( Android )

Hi everyone just wondering if anyone knew what we need to do to play IMA ads on chrome cast from a sender app,
From what I understand reading the docs the only way to play it is to send a message to the chromecast receiver with the pubads URL:
private void loadMedia(MediaInfo mediaInfo, Boolean autoplay) {
try {
Log.d(TAG, "loading media");
mRemoteMediaPlayer.load(sApiClient, mediaInfo, autoplay)
.setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
#Override
public void onResult(RemoteMediaPlayer.MediaChannelResult result) {
if (result.getStatus().isSuccess()) {
boolean adStarted = mVideoPlayerController.hasAdStarted();
if (mVideoFragment.isVmap() || !adStarted) {
sendMessage("requestAd," + mAdTagUrl + ","
+ mVideoPlayerController.getCurrentContentTime());
} else {
sendMessage("seek,"
+ mVideoPlayerController.getCurrentContentTime());
}
} else {
Log.e(TAG, "Error loading Media : "
+ result.getStatus().getStatusCode());
}
FYI : the mAdTagUrl is the 'pubads' link
Ex pubs link :
https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dskippablelinear&correlator=
Incase anyone was looking for the answer :
it's actually in the AdBreak Clip Info Builder -> setVastAdsRequest() Method.
Pass in the 'pubads' link to this method , and you're good to go.

Can I delay the instabug IntroDialog?

In my Application class I have this method, that I call on the onCreate of my Application:
public void initInstabug() {
try {
instabug = new Instabug.Builder(this, "45c752889689ac2ae0840d11e2a5f628")
.setDebugEnabled(true)
.setEmailFieldRequired(true)
.setFloatingButtonOffsetFromTop(400)
.setShouldShowIntroDialog(true)
.setColorTheme(IBGColorTheme.IBGColorThemeLight)
.setCommentFieldRequired(true)
.setInvocationEvent(IBGInvocationEvent.IBGInvocationEventShake)
.build();
instabug.setPrimaryColor(getResources().getColor(R.color.background));
instabug.setPreSendingRunnable(new Runnable() {
#Override
public void run() {
Log.i("","instabug entered pre sending runnable");
String[] files = new String[2];
files[0] = Environment.getExternalStorageDirectory() + "/Passenger/passenger_log.txt";
files[1] = Environment.getExternalStorageDirectory() + "/Passenger/passenger_log2.txt";
Compress compress = new Compress(files, Environment.getExternalStorageDirectory() + "/Passenger/log.zip");
compress.zip(new CrudStateCallback() {
#Override
public void onResponse(String string) {
Log.i("", "instabug ended making the archive");
}
});
}
});
File file = new File(Environment.getExternalStorageDirectory() + "/Passenger/log.zip");
Uri uri = Uri.fromFile(file);
instabug.setFileAttachment(uri, null);
}catch (Exception e){
Log.e("","error instabug:" + e.getMessage());
Utils.appendLog("In case instabug crashes asyncTask process, will not crash app",true);
}
}
My Issue is that I have the login page, first, and the popup always comes up while I ussually write my login info (email, password).
Is it possible to delay the introDialog, so it will appear only when another activity is open?
I tried initialising my instabug instance with this code in Application, where .setShouldShowIntroDialog(FALSE) is set to false, as you can see. And then in the timeline I reinit it with .setShouldShowIntroDialog(true). But it doesn't show at all like this.
You can try to use Instabug.showIntroMessage() in your activity and set the .setShouldShowIntroDialog() to false.

SVM model fails to load in Android Application

I have a problem with load() method in SVM module. For example if I run code:
try {
Uri uri = Uri.fromFile(new File("file:///android_asset/SVM_Bills.xml"));
mySvm.load(uri.getPath());
int in = mySvm.get_support_vector_count();
if (in != 0) {
Toast.makeText(context,"done loading : " + uri.getPath(), Toast.LENGTH_SHORT).show();
value = (int)mySvm.predict(matOfDescriptor);
}
else {
Toast.makeText(context,"error while loading : " + uri.getPath(), Toast.LENGTH_SHORT).show();
}
It give me the error toast message (i.e it goes to else part and show the toast message).
Of course SVM was previously trained.
Any help please?

E/DroidGap(21383): DroidGap: TIMEOUT ERROR! - calling webViewClient

I use phonegap 1.3.0 to develop mobile application.
when i click one button that will invoke my plugin to invoke a js function, after about 20s, countered the error: "E/DroidGap(21383): DroidGap: TIMEOUT ERROR! - calling webViewClient" in eclipse log console.
and the emulator alert a dialog, show error message : The connection to the server was unsuccessful.(javascript:showProcessBar(1))
How can I fix the error? thanks!
There are some details below to complement my question.
when I invoke js function in phonegap plugin. there must will show error message in logcat:"E/DroidGap(21383): DroidGap: TIMEOUT ERROR! - calling webViewClient" .
I find the code that generate the error. just below:
private void loadUrlIntoView(final String url) {
if (!url.startsWith("javascript:")) {
LOG.d(TAG, "DroidGap.loadUrl(%s)", url);
}
this.url = url;
if (this.baseUrl == null) {
int i = url.lastIndexOf('/');
if (i > 0) {
this.baseUrl = url.substring(0, i+1);
}
else {
this.baseUrl = this.url + "/";
}
}
if (!url.startsWith("javascript:")) {
LOG.d(TAG, "DroidGap: url=%s baseUrl=%s", url, baseUrl);
}
// Load URL on UI thread
final DroidGap me = this;
this.runOnUiThread(new Runnable() {
public void run() {
// Init web view if not already done
if (me.appView == null) {
me.init();
}
// Handle activity parameters
me.handleActivityParameters();
// Track URLs loaded instead of using appView history
me.urls.push(url);
me.appView.clearHistory();
// Create callback server and plugin manager
if (me.callbackServer == null) {
me.callbackServer = new CallbackServer();
me.callbackServer.init(url);
}
else {
me.callbackServer.reinit(url);
}
if (me.pluginManager == null) {
me.pluginManager = new PluginManager(me.appView, me);
}
else {
me.pluginManager.reinit();
}
// If loadingDialog property, then show the App loading dialog for first page of app
String loading = null;
if (me.urls.size() == 1) {
loading = me.getStringProperty("loadingDialog", null);
}
else {
loading = me.getStringProperty("loadingPageDialog", null);
}
if (loading != null) {
String title = "";
String message = "Loading Application...";
if (loading.length() > 0) {
int comma = loading.indexOf(',');
if (comma > 0) {
title = loading.substring(0, comma);
message = loading.substring(comma+1);
}
else {
title = "";
message = loading;
}
}
me.spinnerStart(title, message);
}
// Create a timeout timer for loadUrl
final int currentLoadUrlTimeout = me.loadUrlTimeout;
Runnable runnable = new Runnable() {
public void run() {
try {
synchronized(this) {
wait(me.loadUrlTimeoutValue);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
// If timeout, then stop loading and handle error
if (me.loadUrlTimeout == currentLoadUrlTimeout) {
me.appView.stopLoading();
LOG.e(TAG, "DroidGap: TIMEOUT ERROR! - calling webViewClient");
//me.webViewClient.onReceivedError(me.appView, -6, "The connection to the server was unsuccessful.", url);
}
}
};
Thread thread = new Thread(runnable);
thread.start();
me.appView.loadUrl(url);
}
});
}
I comment the line : me.webViewClient.onReceivedError(me.appView, -6, "The connection to the server was unsuccessful.", url); because it will alert a dialog to terminate my program.
Android enforces a timeout when loading URLs in a webview.
check out this link, (it doesn't really pertain to JQM) , but phonegap android
http://jquerymobile.com/test/docs/pages/phonegap.html
The problem explains itself.. when there's a time out response in any PhoneGap call to an external URL it throws that error.
You can you this HTML5 feature to check the internet connection:
navigator.onLine;
You can see it working here: http://html5demos.com/nav-online
super.setIntegerProperty("loadUrlTimeoutValue",60000);
Place this line in java code in Activity

Categories

Resources