Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Notification on alarm. PendingIntent is disabled!
Browse files Browse the repository at this point in the history
  • Loading branch information
tacticalDevC authored and tacticalDevC committed Nov 26, 2018
1 parent c677cb9 commit 7c77b23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation "com.android.support:support-compat:28.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/at/tacticaldevc/panictrigger/SMSListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package at.tacticaldevc.panictrigger;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -8,8 +10,8 @@
import android.media.RingtoneManager;
import android.net.Uri;
import android.provider.Telephony;
import android.support.v4.app.NotificationCompat;
import android.telephony.SmsMessage;
import android.widget.Toast;

import java.io.IOException;
import java.util.HashSet;
Expand Down Expand Up @@ -38,19 +40,25 @@ public void onReceive(Context context, Intent intent) {
private void triggerAlarm(Context context, String address) {
AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
MediaPlayer mp = new MediaPlayer();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + address));

audioManager.setStreamVolume(AudioManager.STREAM_ALARM, audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0);
try {
mp.setDataSource(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
mp.setLooping(true);
mp.prepare();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "")
.setContentTitle("!!! PANIC !!!")
.setContentText(address + "triggered alarm! Calling in 1 minute!")
.setPriority(NotificationCompat.PRIORITY_MAX);
//.setContentIntent(PendingIntent.getBroadcast(context, 0, callIntent, 0));
mp.start();
TimeUnit.MINUTES.sleep(1);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
mp.stop();
mp.release();
context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + address)));
context.startActivity(callIntent);
}
}

0 comments on commit 7c77b23

Please sign in to comment.