[Question] How can I control my android app from a server

s.omar

BANNED
Joined
Dec 26, 2018
Messages
31
Reaction score
8
Hi BHW,

I'm trying to reskin an android app, but I want to add maybe 3 or 4 ads networks, my question is how can I control the enabling and disabling of each network, for example I want to show admob ads, but if I get a limit I want to switch admob off and then switch Facebook Audience Network on. and I want to do this remotly via a server or a service.

some people talk about doing it via JSON, but I didn't find any guide.
 
I'm not really familiar with app reskinning, but in theory it should work something like this:

1. create ad space/block on your app for all networks
2. make your app send POST or GET request to your server
3. get info from server which network is currently "live"
4. make ad block on your app enabled/insert code based on 3.
 
I'm not really familiar with app reskinning, but in theory it should work something like this:

1. create ad space/block on your app for all networks
2. make your app send POST or GET request to your server
3. get info from server which network is currently "live"
4. make ad block on your app enabled/insert code based on 3.

Thank you for your reply, that's exactly what I'm trying to do in theory ;)
 
Another way is to have a JS enabled webview that loads your website. You could have a Scroll Down to Refresh for refreshing the site. This is how I make mine.
Sample code would look like:

Code:
package com.example.whatever;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    private WebView webView;

    SwipeRefreshLayout mySwipeRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://your_site_url");
        mySwipeRefreshLayout = findViewById(R.id.sr2);

        mySwipeRefreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        webView = (WebView) findViewById(R.id.webView1);
                        webView.reload();
                        Log.i("OK","WORKS");
                        mySwipeRefreshLayout.setRefreshing(false);
                    }

                }
        );


        webView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return false;
            }

        });

        webView.setWebViewClient(new WebViewClient() {
        @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            String htmlData ="<html><body><br/><br/><br/><br/><br/><center>"+description+"</center></body></html>";
            webView.loadUrl("about:blank");
            webView.loadDataWithBaseURL(null,htmlData, "text/html", "UTF-8",null);
            webView.invalidate();
        } });


    }

}

This would load your app completely from the server, and you can position your ads anywhere you want. Although I am not sure if (and how) native ads would work here.
 
Another way is to have a JS enabled webview that loads your website. You could have a Scroll Down to Refresh for refreshing the site. This is how I make mine.
Sample code would look like:

Code:
package com.example.whatever;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    private WebView webView;

    SwipeRefreshLayout mySwipeRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://your_site_url");
        mySwipeRefreshLayout = findViewById(R.id.sr2);

        mySwipeRefreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        webView = (WebView) findViewById(R.id.webView1);
                        webView.reload();
                        Log.i("OK","WORKS");
                        mySwipeRefreshLayout.setRefreshing(false);
                    }

                }
        );


        webView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return false;
            }

        });

        webView.setWebViewClient(new WebViewClient() {
        @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            String htmlData ="<html><body><br/><br/><br/><br/><br/><center>"+description+"</center></body></html>";
            webView.loadUrl("about:blank");
            webView.loadDataWithBaseURL(null,htmlData, "text/html", "UTF-8",null);
            webView.invalidate();
        } });


    }

}

This would load your app completely from the server, and you can position your ads anywhere you want. Although I am not sure if (and how) native ads would work here.
Thank you so much, but what should I do on my web site ? is there any tutorial I can follow
 
Thank you so much, but what should I do on my web site ? is there any tutorial I can follow
Just make a mobile first website that supports android chrome browser (some things like keydown etc can be tricky to implement using normal jquery/vanilla js). Embed that i to the app and it will work. ;)

But because this is an app, you have to design it to look like one. Css+ html+js is perfectly capable of doing that nevertheless.
 
Just make a mobile first website that supports android chrome browser (some things like keydown etc can be tricky to implement using normal jquery/vanilla js). Embed that i to the app and it will work. ;)

But because this is an app, you have to design it to look like one. Css+ html+js is perfectly capable of doing that nevertheless.
Thank you so much for taking the time to help me, I really appreciate it :) I will test what you suggested, and I think I will need sometime to learn those stuff first ;)
 
Thank you so much for taking the time to help me, I really appreciate it :) I will test what you suggested, and I think I will need sometime to learn those stuff first ;)
It's super simple to understand though. Just try placing blackhatworld.com in the url. You will end up having your own bhw app, as an example. :p

If you need the layout etc settings, let me know. I will paste those as well.
 
Back
Top