Skip to content

Commit

Permalink
Default SMS app helper NPE fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliturin committed Sep 13, 2017
1 parent 81579e1 commit 8017221
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Telephony;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.kaliturin.blacklist.receivers.SMSBroadcastReceiver;
Expand Down Expand Up @@ -69,20 +70,23 @@ public static void askForDefaultAppChange(Fragment fragment, int requestCode) {
String packageName;
// current app package is already set as default
if (isDefault(context)) {
// get native app package as default
// get previously saved app package as default
packageName = Settings.getStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE);
} else {
// save native app package to the settings
String nativePackage = Telephony.Sms.getDefaultSmsPackage(context);
Settings.setStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE, nativePackage);
// get current app package as default
// get blacklist app package as default
packageName = context.getPackageName();
// save current default sms app package to the settings
String nativePackage = Telephony.Sms.getDefaultSmsPackage(context);
if (nativePackage != null) {
Settings.setStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE, nativePackage);
}
}
// start sms app change dialog
askForDefaultAppChange(fragment, packageName, requestCode);
}

@TargetApi(19)
private static void askForDefaultAppChange(Fragment fragment, String packageName, int requestCode) {
private static void askForDefaultAppChange(Fragment fragment, @Nullable String packageName, int requestCode) {
if (!isAvailable()) return;
Intent intent;
if (packageName == null) {
Expand Down

0 comments on commit 8017221

Please sign in to comment.