Android Question Send Broadcast with intent and and extras

EvgenyB4A

Active Member
Licensed User
Longtime User
What is the broadcast I should send that the following listener will get:
package com.android.settings;


import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import com.android.internal.statusbar.IStatusBarService;
import android.os.ServiceManager;
import android.util.Log;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.RemoteException;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class ShowStatusBarReceiver extends BroadcastReceiver
{
private static final String TAG = "ShowStatusBarReceiver";
final Object mServiceAquireLock = new Object();
IStatusBarService mStatusBarService;
@override
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
boolean isShow = intent.getBooleanExtra("show",false);
if(!isShow){
enShowStatusBar(true);
}else{
enShowStatusBar(false);
}
if(bundle != null) {
String hideNav = bundle.getString("show");
String defStr = "true";
if (defStr.equals(hideNav)) {
enShowStatusBar(false);
}
}
}

IStatusBarService getStatusBarService() {
synchronized (mServiceAquireLock) {
if (mStatusBarService == null) {
mStatusBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService("statusbar"));
}
return mStatusBarService;
}
}
 

DonManfred

Expert
Licensed User
Longtime User
Start with using code tags when posting code! You are Member since a few years. You should know it
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
It is from Tablet supplier to hide/show navigation and status bars:

B4X:
package com.android.settings;


import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import com.android.internal.statusbar.IStatusBarService;
import android.os.ServiceManager;
import android.util.Log;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.RemoteException;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class ShowStatusBarReceiver extends BroadcastReceiver
{   
    private static final String TAG = "ShowStatusBarReceiver";
    final Object mServiceAquireLock = new Object();
    IStatusBarService mStatusBarService;
    @Override 
    public void onReceive(Context context, Intent intent)
    {
        Bundle bundle = intent.getExtras();
        boolean isShow = intent.getBooleanExtra("show",false);
        if(!isShow){   
            enShowStatusBar(true);
        }else{
            enShowStatusBar(false);
        }
        if(bundle != null) {
            String hideNav = bundle.getString("show");
            String defStr = "true";
            if (defStr.equals(hideNav)) {
                enShowStatusBar(false);
            }
        }
    }
   
    IStatusBarService getStatusBarService() {
        synchronized (mServiceAquireLock) {
            if (mStatusBarService == null) {
                mStatusBarService = IStatusBarService.Stub.asInterface(
                        ServiceManager.getService("statusbar"));
            }
            return mStatusBarService;
        }
    }
   
    public void enShowStatusBar(boolean showStatusBar)
    {
        IStatusBarService statusbar = getStatusBarService();
        if(showStatusBar)
        {
            try
            {
                Log.i(TAG, "statusbar enShowStatusBar show.");
                statusbar.addBar();       
            }catch(RemoteException e)
            {
                Log.w(TAG,"services fail");
            }   
        }
        else
        {
            try
            {       
                Log.i(TAG, "statusbar enShowStatusBar hide.");
                statusbar.hidBar();       
            }catch(RemoteException e)
            {
                Log.w(TAG,"services fail");
            }
        }
    }
}
 
Upvote 0
Top