Thursday, April 2, 2015

Inspect Html elements and console for your Android Hybrid Apps

Now Inspect Html elements and track console as well for your Android Hybrid App as you do for your HTML pages in browser.
You just need chrome browser and some changes in Application’s native code
 Include
import android.annotation.SuppressLint;
On application start class
Also use @SuppressLint("NewApi") before class access definition
Use below code inside on create method
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
    android.webkit.WebView.setWebContentsDebuggingEnabled(true);
}
Full Code

package com.achievers.app;

import android.annotation.SuppressLint;
import android.app.Application;

import com.salesforce.androidsdk.smartstore.app.SalesforceSDKManagerWithSmartStore;
import com.salesforce.androidsdk.ui.LoginActivity;

/**
 * Included @SuppressLint("NewApi") for enabling webview showing on inspect element with chrome
 * @author Kunal Bindal
 * Date: 24-03-2015
 */
@SuppressLint("NewApi") public class MyApp extends Application {

       @Override
        public void onCreate() {
         super.onCreate();
         /**
          * For webview showing on inspect element with chrome
          * @author Kunal Bindal
          * Date: 24-03-2015
          * */
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
          android.webkit.WebView.setWebContentsDebuggingEnabled(true);
       }

         SalesforceSDKManagerWithSmartStore.initHybrid(getApplicationContext(), new KeyImpl(), SplashScreenDemoActivity.class, LoginActivity.class);

        }
}


After that go to Chrome 
then


















No comments:

Post a Comment