Android Working WebView 2016 - android

I created a website which is not published yet, so I am not gonna share it now. But it's a website build with PHP Framework Nette and Twitter Bootstrap as a Frontend framework.
And I wanted to create simple Android and iOS app. Both apps with webview. It works fine on iOS, however, I cannot make work on Android. I browsed tons of similar issues, but none of them helped me.
So, what do I actually need?
Geolocation Access
Showing my website in webview
My code:
package com.URL.URL;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.webkit.GeolocationPermissions;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends Activity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
WebView view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setDomStorageEnabled(true);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setGeolocationEnabled(true);
view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
view.getSettings().setAppCacheEnabled(true);
view.getSettings().setDatabaseEnabled(true);
//view.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U;`Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
view.setWebViewClient(new MyBrowser());
view.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
view.loadUrl("https://www.URL.com");
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
#Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.URL.URL/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
#Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.URL.URL/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
This did not work when I tried it in android emulators (4.4, 5.1, 6, 7) but it worked when I downloaded it on my old Samsung where is android version 4.4.4.
I don't know if there is not something wrong with my website, because when I tried to load google.com it works fine..But even when I entered just the string "aaa" to my menu and tried to open it in webview, it did not work.
Screenshots of my website in Webview and in browser:
WebView
Web Browser
I also wanted to add geolocation access popup window.
All of that works on iOS, but I really do not know how to do that on Android. I am primarily Web Developer, so please, forgive me any messy Android code, it's actually for the first time I am working with Android Studio. Thank you for any help!
PS: I wanna open it in the app not as a new browser tab.
Errors:
09-16 15:01:01.578 2390-2512/com.URL.URL E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
09-16 15:01:01.972 2390-2512/com.URL.URL E/chromium: [ERROR:gles2_cmd_decoder.cc(2167)] [GroupMarkerNotSet(crbug.com/242999)!:A08E32ECFE7F0000]GL ERROR :GL_INVALID_OPERATION : BackFramebuffer::Create: <- error from previous GL command
09-16 15:01:06.059 2390-2390/com.URL.URL E/cr_LocationProvider: Caught security exception while registering for location updates from the system. The application does not have sufficient geolocation permissions.
Warnings:
09-16 15:01:00.562 2390-2390/com.URL.URL W/System: ClassLoader referenced unknown path: /system/app/webview/lib/x86_64
09-16 15:01:00.951 2390-2468/com.URL.URL W/cr_media: Requires BLUETOOTH permission
09-16 15:01:01.116 2390-2390/com.URL.URL W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
09-16 15:01:01.353 2390-2390/com.URL.URL W/gralloc_ranchu: Gralloc pipe failed
09-16 15:01:01.526 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:01.540 2390-2397/com.URL.URL W/art: Suspending all threads took: 9.484ms
09-16 15:01:02.184 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:02.770 2390-2390/com.URL.URL W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2390
09-16 15:01:02.933 2390-2390/com.URL.URL W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2390
09-16 15:01:03.059 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:03.597 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:03.980 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:04.058 2390-2397/com.URL.URL W/art: Suspending all threads took: 26.284ms
09-16 15:01:05.010 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:05.346 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:05.704 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:06.044 2390-2397/com.URL.URL W/art: Suspending all threads took: 10.006ms
09-16 15:01:06.182 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:06.216 2390-2401/com.URL.URL W/art: Suspending all threads took: 8.273ms
09-16 15:01:06.485 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:06.729 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:07.035 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:07.277 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
09-16 15:01:10.719 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread
Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

seems related to hardware draw of chromium
emulator is creating with gpu off by default
Try setting "gpu=on" option in emulator
and add "android:hardwareAccelerated="true" in your manifest

Related

Why Android Volley library is unable to connect asp.net web api?

I am trying to call asp.net web api from Android Client using Volley library. The .net API is working fine and listening ports are:
http://localhost:5000 and https://localhost:5001 in my local machine.
But,When, I try to run android client keeping the base url as http://10.0.2.2:5000/api/login
I found below error in console->
04/23 23:13:41: Launching 'app' on Nexus 6 API 24.
Install successfully finished in 9 s 435 ms.
$ adb shell am start -n "com.example.tourexpwip/com.example.tourexpwip.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 3662 on device 'Nexus_6_API_24 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/art: Late-enabling -Xcheck:jni
W/art: Unexpected CPU variant for X86 using defaults: x86
W/System: ClassLoader referenced unknown path: /data/app/com.example.tourexpwip-1/lib/x86
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/System.out: URL: http://10.0.2.2:5000/api/login/
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/: HostConnection::get() New Host Connection established 0xa67ec7c0, tid 3662
E/Volley: [210] NetworkUtility.shouldRetryException: Unexpected response code 307 for http://10.0.2.2:5000/api/login/
D/: HostConnection::get() New Host Connection established 0xa67ecac0, tid 3683
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xb5c05660: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xb5c05660: ver 2 0 (tinfo 0xb5c032b0)
W/System.err: com.android.volley.ServerError
at com.android.volley.toolbox.NetworkUtility.shouldRetryException(NetworkUtility.java:201)
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:145)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
I/Choreographer: Skipped 68 frames! The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xb5c05660: ver 2 0 (tinfo 0xb5c032b0)
I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
The controller class for login in ASP.NET web api->
namespace TourExpWIP1.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LoginController : ControllerBase
{
NetCoreAuthenticationContext dbContext = new NetCoreAuthenticationContext();
public string Post([FromBody] TblUser value)
{
if (dbContext.TblUser.Any(user => user.UserName.Equals(value.UserName)))
{
TblUser user = dbContext.TblUser.Where(u => u.UserName.Equals(value.UserName)).First();
var client_post_hash_password = Convert.ToBase64String(
Common.SaltHashPassword(
Encoding.ASCII.GetBytes(value.Password),
Convert.FromBase64String(user.Salt)));
if (client_post_hash_password.Equals(user.Password))
return JsonConvert.SerializeObject(user);
else return JsonConvert.SerializeObject("Wrong Password");
}
else
{
return JsonConvert.SerializeObject("user does not exists in db");
}
}
}
}
Try this
1.In Android Manifiest, in tag application add:
inside tag application add this tag:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<application
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
...
/>
2.With a corresponding network_security_config.xml in app/src/main/res/xml/:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
More details please find from here- Link

Facebook Audience Network not displaying test Ads. Already added TestDevice

I created a new sample project for displaying the Facebook audience network Banner ad at bottom of my activity.
My app is running in device but not displaying anything at bottom. I already added the hash for test device.
MainActivity.java
package liveradio.radioz.com.facebookads;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.facebook.ads.*;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
private AdView adView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adView = new AdView(this, "PLACEMENT-ID", AdSize.BANNER_HEIGHT_50);
// Find the Ad Container
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
// Add the ad view to your activity layout
adContainer.addView(adView);
AdSettings.addTestDevice("DEVICE-ID");
// Request an ad
adView.loadAd();
}
#Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="liveradio.radioz.com.facebookads.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
/>
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="liveradio.radioz.com.facebookads">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Log :
01/12 12:13:01: Launching app
$ adb shell am start -n "liveradio.radioz.com.facebookads/liveradio.radioz.com.facebookads.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: liveradio.radioz.com.facebookads.test | liveradio.radioz.com.facebookads
Waiting for application to come online: liveradio.radioz.com.facebookads.test | liveradio.radioz.com.facebookads
Waiting for application to come online: liveradio.radioz.com.facebookads.test | liveradio.radioz.com.facebookads
Connecting to liveradio.radioz.com.facebookads
Waiting for application to start debug server
Waiting for application to come online: liveradio.radioz.com.facebookads.test | liveradio.radioz.com.facebookads
Connecting to liveradio.radioz.com.facebookads
Connected to the target VM, address: 'localhost:8645', transport: 'socket'
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/zygote: Not late-enabling -Xcheck:jni (already on)
W/zygote: Suspending all threads took: 83.944ms
W/zygote: Unexpected CPU variant for X86 using defaults: x86
I/zygote: Background concurrent copying GC freed 9752(4MB) AllocSpace objects, 0(0B) LOS objects, 61% free, 973KB/2MB, paused 48.188ms total 236.235ms
W/ActivityThread: Application liveradio.radioz.com.facebookads is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/zygote: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1486)
I/InstantRun: starting instant run server: is main process
I/WebViewFactory: Loading com.android.chrome version 61.0.3163.98 (code 316409812)
I/zygote: The ClassLoaderContext is a special shared library.
I/cr_LibraryLoader: Time to load native libraries: 3 ms (timestamps 6510-6513)
I/chromium: [INFO:library_loader_hooks.cc(136)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "61.0.3163.98", actual native library version number "61.0.3163.98"
E/FBAudienceNetwork: You don't call AudienceNetworkAds.initialize(). Some functionality may not work properly.
D/IS_UNITY: false
D/AdInternalSettings: Test mode device hash: 877dd37b-fff7-4fa1-b83d-776592220359
D/AdInternalSettings: When testing your app with Facebook's ad units you must specify the device hashed ID to ensure the delivery of test ads, add the following code before loading an ad: AdSettings.addTestDevice("877dd37b-fff7-4fa1-b83d-776592220359");
D/IS_UNITY: false
E/ActivityThread: Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
D/OpenGLRenderer: HWUI GL Pipeline
V/StudioProfiler: StudioProfilers agent attached.
V/StudioProfiler: Acquiring Application for Events
V/StudioProfiler: Transformed class: java/net/URL
W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
V/StudioProfiler: Memory control stream started.
[ 01-12 12:13:06.606 20774:20877 D/ ]
HostConnection::get() New Host Connection established 0xd1835a80, tid 20877
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xe4b85540: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xe4b85540: ver 3 0 (tinfo 0xe4b83360)
D/EGL_emulation: eglMakeCurrent: 0xe4b85540: ver 3 0 (tinfo 0xe4b83360)
W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true
I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
[ 01-12 12:13:07.026 20774:20774 D/ ]
HostConnection::get() New Host Connection established 0xd1583c00, tid 20774
D/EGL_emulation: eglCreateContext: 0xcecec360: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xcecec360: ver 3 0 (tinfo 0xe21fff60)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/cr_CrashFileManager: /data/user/0/liveradio.radioz.com.facebookads/cache/WebView/Crash Reports does not exist or is not a directory
W/com.facebookads: type=1400 audit(0.0:22): avc: denied { read } for name="vmstat" dev="proc" ino=4026532039 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0
D/IS_UNITY: false
I/zygote: Background concurrent copying GC freed 7886(1025KB) AllocSpace objects, 5(100KB) LOS objects, 50% free, 1746KB/3MB, paused 680us total 122.639ms
I/zygote: Do partial code cache collection, code=30KB, data=25KB
I/zygote: After code cache collection, code=30KB, data=25KB
I/zygote: Increasing code cache capacity to 128KB
V/StudioProfiler: Live memory tracking disabled.
V/StudioProfiler: Live memory tracking enabled.
V/StudioProfiler: JNIEnv not attached
V/StudioProfiler: Loaded classes: 6311
V/StudioProfiler: Tracking initialization took: 648527000ns
I/zygote: Do partial code cache collection, code=60KB, data=44KB
I/zygote: After code cache collection, code=56KB, data=43KB
I/zygote: Increasing code cache capacity to 256KB
Disconnected from the target VM, address: 'localhost:8645', transport: 'socket'
I'm getting the build successful and installed in my device. When I open the app I can't see any ads or test ads at bottom of my main activity.
If you've added Audience network libraries, you can add the code below to show test ads without worrying about adding a test device.
if (BuildConfig.DEBUG) {
AdSettings.setTestMode(true);
}
Add this code, preferably in your Application class.
First Implement this library:
implementation 'com.facebook.android:audience-network-sdk:4.99.1'
than use below code:
com.facebook.ads.AdView adView;
adView = new com.facebook.ads.AdView(this, "PLACEMENT-ID",
com.facebook.ads.AdSize.BANNER_HEIGHT_50);
((LinearLayout) adContainer).addView(adView);
adView.loadAd();
first, add this library to your grade file
implementation 'com.facebook.android:audience-network-sdk:6.12.0'
then paste this code in your xml file
<LinearLayout
android:id="#+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
/>
In your Java code paste this code and also replace IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID with your banner ad ID
adView = new AdView(this, "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
adContainer.addView(adView);
adView.loadAd();
for more information you can follow official link of meta
https://developers.facebook.com/docs/audience-network/setting-up/ad-setup/android/banner

Appium Android click on element in WebView crashes code, but is executed in the emulator

I am developing Appium tests for an Android app. The problem happens during the login to facebook which works through a WebView. The login to facebook is necessary for the app login and the app registration. The login to facebook is in both cases (app login and app registration) the same, so I execute in both cases the same method:
private void logInAtFacebook(String email, String password) {
findElementWithTimeout(By.className("android.webkit.WebView"), 10);
Set<String> contextHandles = driver.getContextHandles();
for (String s : contextHandles) {
if (s.contains("WEBVIEW")) {
driver.context(s);
}
}
findElement(By.xpath("//input[#name='email']")).sendKeys(email);
findElement(By.xpath("//input[#name='pass']")).sendKeys(password);
findElement(By.xpath("//button[#name='login']")).click();
findElement(By.xpath("//button[#name='__CONFIRM__']")).click();
driver.context("NATIVE_APP");
}
It is weird, that the app login with facebook works, but the app registration with facebook crashes. The second last line in the above method...
findElement(By.xpath("//button[#name='__CONFIRM__']")).click();
...doesn't return, but the button is clicked in the UI. In other words, the execution stops at this line, so that the next line...
driver.context("NATIVE_APP");
... is never executed. I am really confused. Why is the same code working for the app login, but not for the registration?!
Iv'e copied the logs from Android Studio:
First, the last lines before it crashes during app registration:
01-30 14:18:25.016 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.103 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.184 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.260 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.322 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.401 24439-24450/de.blabla I/art: Background partial concurrent mark sweep GC freed 133(8KB) AllocSpace objects, 3(18MB) LOS objects, 13% free, 24MB/28MB, paused 9.861ms total 80.852ms
01-30 14:18:44.416 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.516 24439-24475/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df02443c260: ver 2 0 (tinfo 0x7df02440ce80)
01-30 14:18:44.633 24439-24439/de.blabla W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 24439
01-30 14:18:44.807 24439-24475/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df02443c260: ver 2 0 (tinfo 0x7df02440ce80)
01-30 14:18:45.111 24439-24475/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df02443c260: ver 2 0 (tinfo 0x7df02440ce80)
And the same lines of the working app login:
01-30 14:21:17.179 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.464 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.573 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.640 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.644 25078-25089/de.blabla I/art: Background partial concurrent mark sweep GC freed 156(6KB) AllocSpace objects, 2(12MB) LOS objects, 11% free, 30MB/34MB, paused 3.293ms total 143.091ms
01-30 14:21:30.717 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.843 25078-25112/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df024436640: ver 2 0 (tinfo 0x7df02440c900)
01-30 14:21:31.002 25078-25078/de.blabla W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 25078
01-30 14:21:31.153 25078-25112/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df024436640: ver 2 0 (tinfo 0x7df02440c900)
01-30 14:21:31.564 25078-25112/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df024436640: ver 2 0 (tinfo 0x7df02440c900)
01-30 14:21:31.721 25078-25248/de.blabla ... *no it continues the test as it should*
Have you tried sending app to background for 0 seconds just after "__ CONFIRM__" button is clicked?
Example:
findElement(By.xpath("//button[#name='login']")).click();
findElement(By.xpath("//button[#name='__CONFIRM__']")).click();
driver.runAppInBackground(0);
driver.context("NATIVE_APP");
Sometimes when tasks are done in background, you lose focus and you are not able to find, click or even make a screenshot with Appium...
Let me know if it worked
I found an inconvenient workaround, but it works for now:
private void logInAtFacebook(String email, String password) {
findElementWithTimeout(By.className("android.webkit.WebView"), 10);
Set<String> contextHandles = driver.getContextHandles();
for (String s : contextHandles) {
if (s.contains("WEBVIEW")) {
driver.context(s);
}
}
findElement(By.xpath("//input[#name='email']")).sendKeys(email);
findElement(By.xpath("//input[#name='pass']")).sendKeys(password);
findElement(By.xpath("//button[#name='login']")).
driver.context("NATIVE_APP");
driver.findElementByAccessibilityId("Continue").click();
}
The problem had something to do with the click within the WebView, so I decided to go back to context "NATIVE_APP" before the last click on the "Continue-Button" happens.
I'm still hoping for a better way to fix this!

AdMob in app not showing

I am trying to show a simple test ad in an android app. I was using this github project to test
https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob/BannerExample
I have also gone through this example https://developers.google.com/admob/android/quick-start#configure_gradle
Im using IntelliJ and not Android Studio so havent been able to follow it exactly.
My problem is that the ads dont seem to be appearing. The logs are below and Ive added a couple of ** next to the lines that I think may be problematic. I have also added my code. I have not added anything to the manifest file (I havent seen any example where I have to)
I am using the emulator. Are there certain constraints on what emulator I can use? At the moment I never see any ad or any placeholder where the ad should be.
Any help greatly appreciated.
Thanks
CODE
Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".EntryPoint">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Code
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mAdView = (AdView) findViewById(R.id.ad_view);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);
}
/** Called when leaving the activity */
#Override
public void onPause() {
if (mAdView != null) {
mAdView.pause();
}
super.onPause();
}
/** Called when returning to the activity */
#Override
public void onResume() {
super.onResume();
if (mAdView != null) {
mAdView.resume();
}
}
/** Called before the activity is destroyed */
#Override
public void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}
LOGS
5222-5222/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
5222-5222/? I/art﹕ Late-enabling JIT
5222-5222/? I/art﹕ JIT created with code_cache_capacity=2MB compile_threshold=1000
** 5222-5222/my.app W/System﹕ ClassLoader referenced unknown path: /data/app/my.app-2/lib/arm
** 5222-5222/my.app W/GooglePlayServicesUtil﹕ Google Play services is missing.
5222-5222/my.app I/WebViewFactory﹕ Loading com.android.webview version 44.0.2403.119 (code 246011900)
5222-5222/my.app W/System﹕ ClassLoader referenced unknown path: /system/app/webview/lib/arm
5222-5222/my.app I/LibraryLoader﹕ Time to load native libraries: 44 ms (timestamps 1048-1092)
5222-5222/my.app I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
5222-5250/my.app W/art﹕ Long monitor contention event with owner method=void java.lang.Thread.nativeCreate(java.lang.Thread, long, boolean) from Thread.java:4294967294 waiters=0 for 206ms
5222-5231/my.app W/art﹕ Suspending all threads took: 91.755ms
5222-5222/my.app V/WebViewChromiumFactoryProvider﹕ Binding Chromium to main looper Looper (main, tid 1) {84fa4d0}
5222-5222/my.app I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
5222-5222/my.app I/chromium﹕ [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0, default verbosity = 0
5222-5222/my.app I/BrowserStartupController﹕ Initializing chromium process, singleProcess=true
5222-5222/my.app W/art﹕ Attempt to remove non-JNI local reference, dumping thread
5222-5222/my.app E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
5222-5222/my.app W/chromium﹕ [WARNING:resource_bundle.cc(285)] locale_file_path.empty()
** 5222-5222/my.app E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
** 5222-5222/my.app E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
** 5222-5222/my.app E/chromium﹕ [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
** 5222-5222/my.app E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
5222-5222/my.app E/chromium﹕ [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
5222-5250/my.app W/art﹕ Long monitor contention event with owner method=void android.app.SharedPreferencesImpl$1.run() from SharedPreferencesImpl.java:90 waiters=1 for 280ms
5222-5247/my.app W/art﹕ Long monitor contention event with owner method=void java.lang.Thread.nativeCreate(java.lang.Thread, long, boolean) from Thread.java:4294967294 waiters=3 for 441ms
5222-5231/my.app W/art﹕ Suspending all threads took: 16.275ms
5222-5222/my.app E/DataReductionProxySettingListener﹕ No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
5222-5269/my.app W/AudioManagerAndroid﹕ Requires BLUETOOTH permission
** 5222-5222/my.app I/Ads﹕ Starting ad request.
5222-5231/my.app W/art﹕ Suspending all threads took: 9.629ms
5222-5222/my.app I/Choreographer﹕ Skipped 41 frames! The application may be doing too much work on its main thread.
5222-5222/my.app D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
5222-5231/my.app W/art﹕ Suspending all threads took: 140.144ms
** 5222-5246/my.app W/GooglePlayServicesUtil﹕ Google Play services is missing.
** 5222-5246/my.app W/GooglePlayServicesUtil﹕ Google Play services is missing.
5222-5267/my.app W/chromium﹕ [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
5222-5222/my.app W/art﹕ Attempt to remove non-JNI local reference, dumping thread
5222-5222/my.app W/AwContents﹕ onDetachedFromWindow called when already detached. Ignoring
5222-5222/my.app W/art﹕ Attempt to remove non-JNI local reference, dumping thread
5222-5222/my.app W/art﹕ Attempt to remove non-JNI local reference, dumping thread
5222-5303/my.app A/chromium﹕ [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
5222-5303/my.app W/google-breakpad﹕ ### ### ### ### ### ### ### ### ### ### ### ### ###
5222-5303/my.app W/google-breakpad﹕ Chrome build fingerprint:
5222-5303/my.app W/google-breakpad﹕ 1.04
5222-5303/my.app W/google-breakpad﹕ 5
5222-5303/my.app W/google-breakpad﹕ 023f32a1-4862-425f-a49b-e5b1792614ed
5222-5303/my.app W/google-breakpad﹕ ### ### ### ### ### ### ### ### ### ### ### ### ###
5222-5303/my.app E/chromium﹕ ### WebView Version 44.0.2403.119 (code 246011900)
5222-5303/my.app A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 5303 (GpuThread)
Thanks
Create emulator that is targeted to Google APIs, not to android.

Android Custom URL Scheme Refuses To Work / How to Navigate Back to Android App After OAuth

edit, please see my 2nd answer below this question for a much more concise, and simple display of the problem
I finally have hit my wits end. I'm working on a cross platform app (IOS and Android) using titanium and connects to salesforce api via rest calls. I've spent 3 days and 20 some hours on this issue and am still stuck. Any support would be extremely appreciated! So lets dive right in.
What I Want It To Do:
The app starts, checks if the user has been given a token using oauth2 authorization, if not gives the user the salesforce login screen. User enters credentials and hits "allow" button and then we are redirected back to the app.
The Issue:
From the description of what I want it to do above everything works except for the last line in bold. Once the user clicks "allow" button we receive this unknown url scheme error:
The code:
The code pretty much consists of 3 different important areas
my index.js file which is where the salesforce login call is made
my AuthService.js file which is where the salesforce url info is called in the index.js
my tiapp.xml where configuration stuff is held for android custom url scheme
index.js
var Auth = require('AuthService');
Auth.openLogin();
AuthService.js Only "openLogin" function is really important here.
var loginWindow;
module.exports = {
get: function () {
console.log("made it into the auth.get function");
return Ti.App.Properties.getObject('auth');
},
set: function (data) {
Ti.App.Properties.setObject('auth', data);
console.log("auth set function was executed!!!");
},
erase: function () {
Ti.App.Properties.removeProperty('auth');
},
openLogin: function () {
console.log("made it into openLogin!!");
var webview = Titanium.UI.createWebView({url:'https://login.salesforce.com/services/oauth2/authorize' +
'?response_type=token&display=touch' +
'&redirect_uri=testapp://app.open' +
'&client_id=' + Ti.App.Properties.getString('salesforce_client_id')});
//console.log("Webview URL: " + webview.getUrl());
loginWindow = Titanium.UI.createWindow();
loginWindow.add(webview);
loginWindow.open({modal:true});
// attempt to log url to console here
//console.log("this is the webview URL during callback: " + webview.getUrl());
},
closeLogin: function () {
loginWindow.close();
}
};
tiapp.xml I am only including my android section of this for the sake of brevity
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:versionCode="1" android:versionName="1.00">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
</manifest>
<activity
android:name=".TesterActivity"
android:exported="true"
android:label="#string/app_name" >
<intent-filter>
<data android:host="app.open" android:scheme="testapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</android>
Callback Url registered with Salesforce:
What I have tried:
I have googled myself blue on this issue. Most of my tinkering has been making adjustments to my "tiapp.xml" in changing the properties and values of those properties within the android tag as well as many adjustments to the "redirect_rui" value in my "AuthService.js" file and in salesforce "callback url" field (since these values have to match or you get a uri mismatch error).
Here are some solutions I have looked at and attempted in order to fix my problem:
https://gist.github.com/jasonkneen/5736738
android custom url scheme..?
How to implement my very own URI scheme on Android
Just to name a few.
console log on app execution:
[INFO] : Emulator is booted
[INFO] : SD card not required, skipping mount check
[INFO] : Emulator ready!
[INFO] : Creating unsigned apk
[INFO] : Processing /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/src
[INFO] : Writing unsigned apk: /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/app-unsigned.apk
[INFO] : Using MD5withRSA signature algorithm
[INFO] : Signing apk: /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/bin/jarsigner "-sigalg" "MD5withRSA" "-digestalg" "SHA1" "-keystore" "/Users/michael.kellogg/Library/Application Support/Titanium/mobilesdk/osx/5.1.2.GA/android/dev_keystore" "-storepass" "*******" "-signedjar" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apk" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/app-unsigned.apk" "tidev"
[INFO] : Aligning zip file: /Users/michael.kellogg/android-sdk/build-tools/23.0.2/zipalign "-v" "4" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apk" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apkz"
[INFO] : Writing build manifest: /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/build-manifest.json
[INFO] : Making sure the adb server is running
[INFO] : Installing apk: /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apk
[INFO] : App successfully installed
[INFO] : Starting app: com.test.test/.TesterActivity
[INFO] : Application pid: 1160
[INFO] : Project built successfully in 3m 8s 295ms
[INFO] : art: Late-enabling JIT
[INFO] : art: JIT created with code_cache_capacity=2MB compile_threshold=1000
[INFO] : TiApplication: (main) [2,2] checkpoint, app created.
[INFO] : TiApplication: (main) [1067,1069] Titanium 5.1.2 (2015/12/16 19:00 ca822b2)
[INFO] : art: Background sticky concurrent mark sweep GC freed 15623(973KB) AllocSpace objects, 11(384KB) LOS objects, 41% free, 2MB/3MB, paused 2.142ms total 105.631ms
[INFO] : TiApplication: (main) [383,1452] Titanium Javascript runtime: v8
[INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
[WARN] : TiTempFileHelper: (main) [189,189] The external temp directory doesn't exist, skipping cleanup
[INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.test.test.TesterActivity#a298e02
[WARN] : V8Object: (KrollRuntimeThread) [1039,1228] Runtime disposed, cannot set property 'userAgent'
[INFO] : made it into openLogin!!
[INFO] : OpenGLRenderer: Initialized EGL, version 1.4
[WARN] : EGL_emulation: eglSurfaceAttrib not implemented
[WARN] : OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4d32b20, error=EGL_SUCCESS
[INFO] : WebViewFactory: Loading com.android.webview version 44.0.2403.119 (code 246011900)
[WARN] : System: ClassLoader referenced unknown path: /system/app/webview/lib/arm
[INFO] : LibraryLoader: Time to load native libraries: 36 ms (timestamps 588-624)
[INFO] : LibraryLoader: Expected native library version number "",actual native library version number ""
[INFO] : LibraryLoader: Expected native library version number "",actual native library version number ""
[INFO] : chromium: [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0, default verbosity = 0
[INFO] : BrowserStartupController: Initializing chromium process, singleProcess=true
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[ERROR] : SysUtils: ApplicationContext is null in ApplicationStatus
[WARN] : chromium: [WARNING:resource_bundle.cc(285)] locale_file_path.empty()
[ERROR] : libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
[ERROR] : libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
[ERROR] : eglCodecCommon: glUtilsParamSize: unknow param 0x00008d57
[WARN] : AudioManagerAndroid: Requires BLUETOOTH permission
[ERROR] : DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : AwContents: onDetachedFromWindow called when already detached. Ignoring
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
[WARN] : EGL_emulation: eglSurfaceAttrib not implemented
[WARN] : OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4d32b40, error=EGL_SUCCESS
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background sticky concurrent mark sweep GC freed 7564(860KB) AllocSpace objects, 25(988KB) LOS objects, 0% free, 11MB/11MB, paused 1.603ms total 308.766ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 1948(144KB) AllocSpace objects, 3(8MB) LOS objects, 22% free, 13MB/17MB, paused 1.658ms total 271.298ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 148(6KB) AllocSpace objects, 13(36MB) LOS objects, 17% free, 19MB/23MB, paused 1.205ms total 327.978ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 91(3KB) AllocSpace objects, 5(14MB) LOS objects, 22% free, 13MB/17MB, paused 1.228ms total 201.595ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Suspending all threads took: 15.737ms
[INFO] : art: Background sticky concurrent mark sweep GC freed 261(13KB) AllocSpace objects, 2(5MB) LOS objects, 0% free, 25MB/25MB, paused 18.832ms total 174.330ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 98(20KB) AllocSpace objects, 7(19MB) LOS objects, 26% free, 11MB/15MB, paused 3.244ms total 302.681ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background sticky concurrent mark sweep GC freed 11512(602KB) AllocSpace objects, 0(0B) LOS objects, 4% free, 14MB/15MB, paused 1.739ms total 174.806ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 301(32KB) AllocSpace objects, 2(5MB) LOS objects, 25% free, 11MB/15MB, paused 2.370ms total 274.103ms
[WARN] : EGL_emulation: eglSurfaceAttrib not implemented
[WARN] : OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9d719f80, error=EGL_SUCCESS
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background sticky concurrent mark sweep GC freed 358(19KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 17MB/17MB, paused 6.593ms total 277.832ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 148(5KB) AllocSpace objects, 3(8MB) LOS objects, 18% free, 17MB/21MB, paused 7.547ms total 414.524ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background sticky concurrent mark sweep GC freed 30(608B) AllocSpace objects, 1(2MB) LOS objects, 0% free, 23MB/23MB, paused 2.321ms total 159.615ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 36(1168B) AllocSpace objects, 5(14MB) LOS objects, 21% free, 14MB/18MB, paused 1.626ms total 197.175ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background sticky concurrent mark sweep GC freed 21(448B) AllocSpace objects, 0(0B) LOS objects, 0% free, 20MB/20MB, paused 37.280ms total 96.680ms
[INFO] : art: Background partial concurrent mark sweep GC freed 34(960B) AllocSpace objects, 4(11MB) LOS objects, 30% free, 8MB/12MB, paused 1.475ms total 106.381ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 56(3KB) AllocSpace objects, 3(8MB) LOS objects, 21% free, 14MB/18MB, paused 3.001ms total 243.577ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160
[INFO] : I/TiWebChromeClient.console: (main) [21796,21796] Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png (0:data:text/html,chromewebdata)
[INFO] : art: Background sticky concurrent mark sweep GC freed 337(53KB) AllocSpace objects, 1(2MB) LOS objects, 6% free, 17MB/18MB, paused 43.249ms total 82.260ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 82(11KB) AllocSpace objects, 3(8MB) LOS objects, 21% free, 14MB/18MB, paused 1.613ms total 159.713ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background sticky concurrent mark sweep GC freed 27(544B) AllocSpace objects, 1(2MB) LOS objects, 6% free, 17MB/18MB, paused 21.912ms total 68.965ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[INFO] : art: Background partial concurrent mark sweep GC freed 39(1056B) AllocSpace objects, 3(8MB) LOS objects, 21% free, 14MB/18MB, paused 1.523ms total 136.698ms
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[WARN] : art: Attempt to remove non-JNI local reference, dumping thread
[ERROR] : Surface: getSlotFromBufferLocked: unknown buffer: 0xaad48dc0
[INFO] : art: Background partial concurrent mark sweep GC freed 40(1104B) AllocSpace objects, 5(14MB) LOS objects, 25% free, 11MB/15MB, paused 3.871ms total 157.623ms
[INFO] : APSAnalyticsService: Analytics Service Started
[INFO] : APSAnalyticsService: Stopping Analytics Service
-- End application log -------------------------------------------------------
In terms of setting up the manifest for a schema recognition you should end up with something resembling the following
<manifest ...>
...
<application ...>
...
<activity ...
android:exported="true"> <!-- Make it exported -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="...">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="testapp" />
<data android:host="app" /> <!-- cover all your bases -->
<data android:host="app.open" />
</intent-filter>
</activity>
</application>
</manifest>
I would then have a method in that activity which could check if your schema is in the intent. Something like the following:
protected void onCreate(final Bundle savedInstanceState) {
...
checkIntent( getIntent() );
}
protected void onNewIntent(final Intent intent) {
...
checkIntent( intent );
}
private void checkIntent(Intent intent) {
if ( intent.getDataString() != null && Intent.ACTION_VIEW.equals(intent.getAction()) ) {
//If we reached here we have some kind of deep link or custom schema
//so lets identify which schema
if ( "testapp".equals(data.getScheme().toLowerCase()) ) {
//my tests were able to reach here
}
}
}
One quirk of androids is that with later versions the user has to show intent. What that means realistically is that typing in a url in the browser and pressing go won't work. It's only triggered when a user clicks on a link or when you fire an intent. When you only want to detect the redirect from your own WebView (and not external browsers) then you are able to get around that:
myWebView.setWebViewClient( new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("testapp://")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData( Uri.parse(url) );
view.getContext().startActivity( intent );
return true; //with return true, the webview wont try rendering the url
}
return false;
}
} );
After something like 64 hours of scouring the internet and countless attempts I have finally found a solution to this issue. Yay me! I must admit I feel a bit of shame as to how long this issue took to resolve.
The Issue: Could not find a way to navigate back to android app after salesforce authorization (custom url scheme was extremely painful with android).
Solution: After searching around I found a code example from salesforce that did what I was attempting to do here:
https://developer.salesforce.com/page/Developing_Mobile_Applications_with_Force.com_and_Appcelerator_Titanium
Here is the github link provided in the above article that has the much needed code:
https://github.com/appcelerator-developer-relations/Force
TLDR: The real key here was to NOT use a custom url scheme with android and titanium. Instead the github code listed above opens the auth page in a web view and then, using listeners, closes that webview after auth is done and opens whatever view you need.
Explanation: to navigate back to my app on IOS all I had to do was add a couple of lines to my tiapp.xml file in order to use a custom url scheme. It worked very quickly and simply without any headache. Naturally I assumed a custom url scheme was the way to go with android, simple right? false. I spent many hours as listed above trying to make a custom url scheme on android to no avail. There seems to be lots of info online about android custom url schemes but none of them worked for me and believe me I tried so many things (after all it was approx. 64 hours). Eventually I just tried to find an example online of code that did what I wanted. This was the one that I found.
Could not put it in comment, so creating an answer. Would request you to please try it and see if it helps.
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application android:icon="#drawable/appicon" android:label="MyApp" android:name="MyApplication">
<activity android:label="MyApp" android:name=".MyApplicationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mytestapplication" />
</intent-filter>
</activity>
</application>
</manifest>
Can you give this a try and see if this works. You can also check out the TiApp.xml entry mentioned in this Git Post.
Request you to try and let us know, if this does not work out, then may be we can try something else.
There's some workaround which looks legit to me.
So, along with shouldOverrideUrlLoading() the WebViewClient allows to override onErrorRecieved() and actually it passes failingUrl as an argument.
private val webViewClient = object : WebViewClient() {
#Suppress("OverridingDeprecatedMember")
override fun onReceivedError(view: WebView?, errorCode: Int, description: String?, failingUrl: String?) {
if (failingUrl != null) {
handleCallbackUrl(Uri.parse(failingUrl))
}
}
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?) = when {
handleCallbackUrl(request?.url) -> true
else -> super.shouldOverrideUrlLoading(view, request)
}
}

Categories

Resources