简体   繁体   中英

Remove or hide notification bar in android

i am developing an application, when the app is open there may be any missed call the notification is displayed,how i hide or remove the notification bar & is there any way to implement it. i have put all codes like below in my application,

requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

and

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 

but i open an activity file using broadcast receiver, then the notification is seen when missed call or message arrives

You can use this code:

public class FullScreen
    extends android.app.Activity
{
    @Override
    public void onCreate(android.os.Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
    }
}

I was having the exact same problem as yours, but I hade it for both incoming and outgoing calls. I found the solution for the incoming calls/ missed calls but not yet for the outgoing calls.

What you are going to do is the following:

1.Create a BroadCastReceiver Class to listen to incoming calls with the highest priority:

a.In the Manifest.xml add:

    <receiver android:name=".MyPhoneBroadcastReceiver">
        <intent-filter android:priority="99999">
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver>

b.Then the Class

@Override
public void onReceive(final Context context, Intent intent) {

    Bundle extras = intent.getExtras();

    if (extras != null) {

        String state = extras.getString(TelephonyManager.EXTRA_STATE);          
        final String incomingNumber = extras.getString("incoming_number");

        Handler callActionHandler = new Handler();

        Runnable runRingingActivity = new Runnable(){
            @Override
            public void run() {
                 //Notice the intent, cos u will add intent filter for your class(CustomCallsReceiver)
                Intent intentPhoneCall = new Intent("android.intent.action.ANSWER");
                intentPhoneCall.putExtra("INCOMING_NUM", incomingNumber);
                intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intentPhoneCall);
            }
        };
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            //increase the delay amount if problem occur something like -the screen didn't show up- that's the key about this method(the delay).
            callActionHandler.postDelayed(runRingingActivity, 100);    
        }
        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
            callActionHandler.removeCallbacks(runRingingActivity);
        }

    }
}

2.a.In the Manifest.xml file add this intent filter for the class you will use as a custome call receiver.

    <activity android:name="CustomCallsReceiver" android:noHistory="true" android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.ANSWER" />
             <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>    
    </activity>

2.b.The CustomeCallsReceiver Class:

public class CustomCallsReceiver extends Activity {

private String TAG = "CustomCallsReceiver";
String incomingNumber, caller;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custome_calls_receiver);

    TextView number = (TextView) findViewById(R.id.number);
    number.setGravity(Gravity.CENTER);

    incomingNumber = getIntent().getExtras().getString("INCOMING_NUM");
    caller = getCallerName(incomingNumber);

    if (caller != null) {
        number.setText(caller + "\n" + incomingNumber);  }  }

3.And finally of course don't forget to add the Theme for not title or notification bar at the Manifest.XML file

    <application
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

You need to set the theme in Android manifest .xml.. .

 android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 

Hope this will help you..

if you set this as application theme it will give effect all the pages of your app..

   <application
         android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
         >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM