mirror of
https://github.com/Xcreen/RestSMS.git
synced 2026-02-20 07:38:21 -05:00
Fix ServerService/Foreground-Service for Android 13+
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
<application
|
||||
android:name=".AppContext"
|
||||
@@ -28,7 +30,9 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".server.ServerService" />
|
||||
<service android:name=".server.ServerService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -25,6 +25,7 @@ class HomeFragment : Fragment() {
|
||||
private var toggleServerBtn: Button? = null
|
||||
private var appContext: AppContext? = null
|
||||
private val SMS_PERMISSION_REQUEST = 100
|
||||
private val NOTIFICATION_PERMISSION_REQUEST = 101
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val rootView = inflater.inflate(R.layout.fragment_home, container, false)
|
||||
@@ -42,6 +43,16 @@ class HomeFragment : Fragment() {
|
||||
ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.SEND_SMS), SMS_PERMISSION_REQUEST)
|
||||
return@setOnClickListener
|
||||
}
|
||||
// Check if Notification-Permission is grant
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
if (ActivityCompat.checkSelfPermission(v.context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
//Show Error Toast
|
||||
Toast.makeText(v.context, resources.getText(R.string.no_notification_permission), Toast.LENGTH_LONG).show()
|
||||
//Request Permission
|
||||
ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.POST_NOTIFICATIONS), NOTIFICATION_PERMISSION_REQUEST)
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
//Check if Device has a Sim-Card
|
||||
try {
|
||||
val telephonyManager = v.context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<string name="server_failed_bindex">Server can not run on this port! (Bind-Exception)</string>
|
||||
<string name="invalid_sim">Sim-Card is missing or not ready to send sms!</string>
|
||||
<string name="no_sms_permission">SMS-Permission is required to run the server!</string>
|
||||
<string name="no_notification_permission">Notification-Permission is required to run the server as a foreground-service!</string>
|
||||
|
||||
<string name="notification_text">Server is running! On port: %1$d</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user