Skip to content

Commit

Permalink
Merge pull request #31 from ilhan-athn7/dev
Browse files Browse the repository at this point in the history
Request notification permission for API 33
  • Loading branch information
Xtr126 authored Jul 7, 2023
2 parents 154b7d8 + 6e98260 commit 122f1c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<queries>
<intent>
Expand Down Expand Up @@ -50,4 +51,4 @@
android:enabled="true" />
</application>

</manifest>
</manifest>
17 changes: 14 additions & 3 deletions app/src/main/java/xtr/keymapper/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package xtr.keymapper.activity;

import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.widget.Button;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import xtr.keymapper.editor.EditorService;
import xtr.keymapper.R;
import xtr.keymapper.Server;
import xtr.keymapper.TouchPointer;
import xtr.keymapper.databinding.ActivityMainBinding;
import xtr.keymapper.editor.EditorService;
import xtr.keymapper.fragment.SettingsFragment;
import xtr.keymapper.server.InputService;

Expand Down Expand Up @@ -71,6 +74,7 @@ public void startPointer(){
setButtonActive(binding.controls.startPointer);
binding.controls.startPointer.setText(R.string.stop);
binding.controls.startPointer.setOnClickListener(v -> stopPointer());
requestNotificationPermission();
}
}

Expand Down Expand Up @@ -114,6 +118,13 @@ private void checkOverlayPermission(){
}
}

private void requestNotificationPermission(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (!(checkSelfPermission(POST_NOTIFICATIONS) ==
PERMISSION_GRANTED)) requestPermissions(new String[]{POST_NOTIFICATIONS}, 0);
}
}

@Override
protected void onDestroy() {
if (pointerOverlay != null)
Expand Down Expand Up @@ -191,4 +202,4 @@ public void onServiceConnected(ComponentName className,
public void onServiceDisconnected(ComponentName arg0) {
}
};
}
}

0 comments on commit 122f1c9

Please sign in to comment.