0
所以目前我正在製作這個應用程序,當用戶鎖定他們的手機時,然後打開它回來了一個有邊界的圖像出現,而不是標準的鎖屏。這工作正常。 然後當彈出通知時,我可以選擇在應用程序界面上更改圖像。這也適用。通知訪問和鎖屏衝突?
我的問題是,他們不一起工作,一個會工作,但另一個不會,如果這一切都有道理。任何人都有任何想法,爲什麼這是?
編輯: 這是這裏
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//If the notification service is enabled don't do anything, if it's not go to the option
if(!isNotificationServiceEnabled()) {
buildNotificationServiceAlertDialog = buildNotificationServiceAlertDialog();
buildNotificationServiceAlertDialog.show();
}
requestWriteSettingPermission();
//Permissions ----------------
Button button = (Button) findViewById(R.id.privacy_policy_button);
button.setPaintFlags(button.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
button.setText("Privacy Policy & Terms of Use");
timeSpinner = (MaterialSpinner) findViewById(R.id.activity_main_time_spinner);
timeSpinner.setItems(time_arrays);
timeSpinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
@Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
onTimeDurationChanged(position);
}
});
ButterKnife.bind(this);
//Lockscreen service button check
if (MainActivity.isServiceRunning(this, LockScreenService.class)){
onOffToggleButton.setChecked(true);
}else{
onOffToggleButton.setChecked(false);
}
opacitySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//Offset set opacity so the user can never make the shape impractically dim
onOpacityChanged(progress + OPACITY_OFFSET);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//Notifys the activity when a notification is sent in
imageChangeBroadcastReceiver = new ImageChangeBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.screenoflight.android2.NotificationService");
registerReceiver(imageChangeBroadcastReceiver, intentFilter);
}
主要活動課這是新的代碼,我增加了對通知的東西
private boolean isNotificationServiceEnabled(){
String pkgName = getPackageName();
final String flat = Settings.Secure.getString(getContentResolver(),
ENABLED_NOTIFICATION_LISTENERS);
if (!TextUtils.isEmpty(flat)) {
final String[] names = flat.split(":");
for (int i = 0; i < names.length; i++) {
final ComponentName cn = ComponentName.unflattenFromString(names[i]);
if (cn != null) {
if (TextUtils.equals(pkgName, cn.getPackageName())) {
return true;
}
}
}
}
return false;
}
private void updateNotification(int notificationCode)
{
switch(notificationCode)
{
case NotificationService.InterceptedNotificationCode.FACEBOOK_CODE:
shapeRectangleButton.setImageResource(R.drawable.toggle_on);
break;
case NotificationService.InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE:
shapeRectangleButton.setImageResource(R.drawable.toggle_on);
break;
}
}`
public class ImageChangeBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int receivedNotificationCode = intent.getIntExtra("Notification Code",-1);
updateNotification(receivedNotificationCode);
}
}
/**
* Build Notification Listener Alert Dialog.
* Builds the alert dialog that pops up if the user has not turned
* the Notification Listener Service on yet.
* @return An alert dialog which leads to the notification enabling screen
*/
private AlertDialog buildNotificationServiceAlertDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("one");
alertDialogBuilder.setMessage("two");
alertDialogBuilder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS));
}
});
alertDialogBuilder.setNegativeButton("no",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// If you choose to not enable the notification listener
// the app. will not work as expected
}
});
return(alertDialogBuilder.create());
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(imageChangeBroadcastReceiver);
}
不可能說沒有一些代碼,看看你是如何實現它 – aliaksei
我已經添加了一個編輯它,所以你可以有一個更好的主意發生了什麼 –
我得到了它的工作謝謝 –