Fix PendingIntent uniqueness issues
Notification actions should work correctly now.
This commit is contained in:
parent
d2fb4d69ea
commit
d79f1c0676
|
@ -17,6 +17,7 @@ public class InfoDialogActivity extends AppCompatActivity {
|
|||
public static Intent getIntent(Context context, String number) {
|
||||
Intent intent = new Intent(context, InfoDialogActivity.class);
|
||||
intent.putExtra(PARAM_NUMBER, number);
|
||||
intent.setData(IntentHelper.getUriForPhoneNumber(number));
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class IntentHelper {
|
||||
|
||||
public static Uri getUriForPhoneNumber(String number) {
|
||||
return Uri.parse("tel:" + (!TextUtils.isEmpty(number) ? number : "private"));
|
||||
}
|
||||
|
||||
public static PendingIntent pendingActivity(Context context, Intent intent) {
|
||||
return PendingIntent.getActivity(context, 0, intent, 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ import dummydomain.yetanothercallblocker.data.NumberInfo;
|
|||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
||||
|
||||
import static dummydomain.yetanothercallblocker.PendingIntentHelper.forActivity;
|
||||
import static dummydomain.yetanothercallblocker.IntentHelper.pendingActivity;
|
||||
|
||||
public class NotificationHelper {
|
||||
|
||||
|
@ -85,9 +85,8 @@ public class NotificationHelper {
|
|||
public static Notification createServiceNotification(Context context, String title) {
|
||||
if (title == null) title = context.getString(R.string.notification_background_operation);
|
||||
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(
|
||||
context, 0, intent, 0);
|
||||
PendingIntent contentIntent = pendingActivity(context,
|
||||
new Intent(context, MainActivity.class));
|
||||
|
||||
return new NotificationCompat.Builder(context, CHANNEL_ID_TASKS)
|
||||
.setSmallIcon(R.drawable.ic_file_download_24dp)
|
||||
|
@ -207,11 +206,11 @@ public class NotificationHelper {
|
|||
}
|
||||
|
||||
private static PendingIntent createInfoIntent(Context context, NumberInfo numberInfo) {
|
||||
return forActivity(context, InfoDialogActivity.getIntent(context, numberInfo.number));
|
||||
return pendingActivity(context, InfoDialogActivity.getIntent(context, numberInfo.number));
|
||||
}
|
||||
|
||||
private static PendingIntent createReviewsIntent(Context context, NumberInfo numberInfo) {
|
||||
return forActivity(context, ReviewsActivity.getNumberIntent(context, numberInfo.number));
|
||||
return pendingActivity(context, ReviewsActivity.getNumberIntent(context, numberInfo.number));
|
||||
}
|
||||
|
||||
static void createNotificationChannels(Context context) {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PendingIntentHelper {
|
||||
|
||||
public static PendingIntent forActivity(Context context, Intent intent) {
|
||||
// creates a new pending intent instead of returning an existing one
|
||||
return PendingIntent.getActivity(context, getRandomInt(), intent, 0);
|
||||
}
|
||||
|
||||
private static int getRandomInt() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return ThreadLocalRandom.current().nextInt();
|
||||
} else {
|
||||
return new Random().nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@ public class ReviewsActivity extends AppCompatActivity {
|
|||
public static Intent getNumberIntent(Context context, String number) {
|
||||
Intent intent = new Intent(context, ReviewsActivity.class);
|
||||
intent.putExtra(PARAM_NUMBER, number);
|
||||
intent.setData(IntentHelper.getUriForPhoneNumber(number));
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue