3

我正在开发一个应用程序,当应用程序打开时,可能会显示任何未接来电通知,我如何隐藏或删除通知栏以及有什么方法可以实现它。我已经在我的应用程序中放入了如下所有代码,

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

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

但我使用广播接收器打开一个活动文件,然后在未接来电或消息到达时看到通知

4

3 回答 3

3

您可以使用以下代码:

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);
    }
}
于 2012-12-20T12:59:06.883 回答
1

我遇到了和你一样的问题,但是我在来电和去电时都遇到了这个问题。我找到了来电/未接来电的解决方案,但还没有找到去电的解决方案。

您要做的是以下内容:

1.创建一个 BroadCastReceiver 类以收听具有最高优先级的来电:

a.在 Manifest.xml 中添加:

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

b.那么类

@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.在 Manifest.xml 文件中,为您将用作客户呼叫接收器的类添加此意图过滤器。

    <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.CustomeCallsReceiver 类:

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.最后当然不要忘记在 Manifest.XML 文件中添加非标题或通知栏的主题

    <application
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
于 2012-12-30T12:03:39.137 回答
0

您需要在 Android manifest .xml 中设置主题...。

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

希望对你有帮助..

如果您将此设置为应用程序主题,它将使您的应用程序的所有页面生效..

   <application
         android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
         >
于 2012-12-20T12:58:56.973 回答