-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from vernu/feature/receive-sms
Receive Messages Feature
- Loading branch information
Showing
57 changed files
with
1,822 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.vernu.sms; | ||
|
||
import com.vernu.sms.services.GatewayApiService; | ||
|
||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
public class ApiManager { | ||
private static GatewayApiService apiService; | ||
|
||
public static GatewayApiService getApiService() { | ||
if (apiService == null) { | ||
apiService = createApiService(); | ||
} | ||
return apiService; | ||
} | ||
|
||
private static GatewayApiService createApiService() { | ||
// OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); | ||
// HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); | ||
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | ||
// httpClient.addInterceptor(loggingInterceptor); | ||
|
||
Retrofit retrofit = new Retrofit.Builder() | ||
.baseUrl(AppConstants.API_BASE_URL) | ||
// .client(httpClient.build()) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build(); | ||
apiService = retrofit.create(GatewayApiService.class); | ||
|
||
return retrofit.create(GatewayApiService.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vernu.sms; | ||
|
||
import android.Manifest; | ||
|
||
public class AppConstants { | ||
public static final String API_BASE_URL = "https://api.textbee.dev/api/v1/"; | ||
public static final String[] requiredPermissions = new String[]{ | ||
Manifest.permission.SEND_SMS, | ||
Manifest.permission.READ_SMS, | ||
Manifest.permission.RECEIVE_SMS, | ||
Manifest.permission.READ_PHONE_STATE | ||
}; | ||
public static final String SHARED_PREFS_DEVICE_ID_KEY = "DEVICE_ID"; | ||
public static final String SHARED_PREFS_API_KEY_KEY = "API_KEY"; | ||
public static final String SHARED_PREFS_GATEWAY_ENABLED_KEY = "GATEWAY_ENABLED"; | ||
public static final String SHARED_PREFS_PREFERRED_SIM_KEY = "PREFERRED_SIM"; | ||
public static final String SHARED_PREFS_RECEIVE_SMS_ENABLED_KEY = "RECEIVE_SMS_ENABLED"; | ||
public static final String SHARED_PREFS_TRACK_SENT_SMS_STATUS_KEY = "TRACK_SENT_SMS_STATUS"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.vernu.sms; | ||
|
||
import android.Manifest; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
import android.telephony.SubscriptionInfo; | ||
import android.telephony.SubscriptionManager; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
import androidx.core.content.ContextCompat; | ||
|
||
import com.vernu.sms.services.StickyNotificationService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TextBeeUtils { | ||
public static boolean isPermissionGranted(Context context, String permission) { | ||
return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; | ||
} | ||
|
||
public static List<SubscriptionInfo> getAvailableSimSlots(Context context) { | ||
|
||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { | ||
return new ArrayList<>(); | ||
} | ||
|
||
SubscriptionManager subscriptionManager = SubscriptionManager.from(context); | ||
return subscriptionManager.getActiveSubscriptionInfoList(); | ||
|
||
} | ||
|
||
public static void startStickyNotificationService(Context context) { | ||
|
||
if(!isPermissionGranted(context, Manifest.permission.RECEIVE_SMS)){ | ||
return; | ||
} | ||
|
||
Intent notificationIntent = new Intent(context, StickyNotificationService.class); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
context.startForegroundService(notificationIntent); | ||
} else { | ||
context.startService(notificationIntent); | ||
} | ||
} | ||
|
||
public static void stopStickyNotificationService(Context context) { | ||
Intent notificationIntent = new Intent(context, StickyNotificationService.class); | ||
context.stopService(notificationIntent); | ||
} | ||
} |
Oops, something went wrong.