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:
NLService:
Main:
Vielen Dank
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: