start/stop Notification listener

E

er4z0r

Neues Mitglied
0
Hallo zusammen,

Momentan stehe ich vor einem Rätsel, denn wie bekomme ich den Notification listener gestoppt bzw. wie kann ich den nach belieben sarten und wieder schließen am besten zeitlich steuerbar(von 9-18 Uhr an, sonst aus).

EDIT: Oder gibt es eine andere Möglichkeit diesen Notification listener einzubinden, so dass ich den nach belieben staten und stoppen kann?

Mnifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test.myapplication" >
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="test.myapplication.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <service android:name=".NLService"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService" />
            </intent-filter>
        </service>

</application>

</manifest>

NLService:
Code:
public class NLService extends NotificationListenerService {


    private String TAG = this.getClass().getSimpleName();
    @Override
    public void onCreate() {
        super.onCreate();
        Log.v("NL","START");

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.v("NL","STOP");
    }

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {

        Log.i(TAG,"**********  onNotificationPosted");
    }

    @Override
    public void onNotificationRemoved(StatusBarNotification sbn) {
    }

}

Main:
Code:
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }



    public void buttonClicked(View v){

        if(v.getId() == R.id.btnCreateNotify){
            NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
            ncomp.setContentTitle("My Notification");
            ncomp.setContentText("Notification Listener Service Example");
            ncomp.setTicker("Notification Listener Service Example");
            ncomp.setSmallIcon(R.drawable.ic_launcher);
            ncomp.setAutoCancel(true);
            nManager.notify((int)System.currentTimeMillis(),ncomp.build());
        }
        else if(v.getId() == R.id.btnClearNotify){
            
            Log.v("NL", "CLEAR");


        }


    }




}

Vielen Dank
 
Zuletzt bearbeitet:
#push
 
eine if abfrage einbauen
 
meinst du in den NLService ne if abfrage? anders kann ich das nicht beenden oder nicht ausführen?
 

Ähnliche Themen

Laser5001
  • Laser5001
Antworten
2
Aufrufe
900
Laser5001
Laser5001
Jansenwilson
Antworten
1
Aufrufe
690
Mazuch
Mazuch
L
Antworten
3
Aufrufe
1.314
deek
D
Zurück
Oben Unten