Merge pull request #26 from shacharr/master
Implement Persistent Notification
This commit is contained in:
@@ -4,7 +4,7 @@ sudo: true
|
||||
install:
|
||||
- echo y | android update sdk -u -a -t tools
|
||||
- echo y | android update sdk -u -a -t platform-tools
|
||||
- echo y | android update sdk -u -a -t build-tools-25.0.2
|
||||
- echo y | android update sdk -u -a -t build-tools-26.0.2
|
||||
- echo y | android update sdk -u -a -t android-25
|
||||
- echo y | android update sdk -u -a -t extra-google-m2repository
|
||||
- echo y | android update sdk -u -a -t extra-android-m2repository
|
||||
|
||||
@@ -8,7 +8,6 @@ findbugs {
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "protect.babymonitor"
|
||||
@@ -22,6 +21,10 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.android.support:support-compat:25.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
task findbugs(type: FindBugs, dependsOn: 'assembleDebug') {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
android:versionName="0.2" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="8" />
|
||||
android:minSdkVersion="16"
|
||||
android:targetSdkVersion="17" />
|
||||
<uses-permission android:required="true" android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:required="true" android:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission android:required="true" android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioTrack;
|
||||
@@ -29,14 +30,19 @@ import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
|
||||
public class ListenActivity extends Activity
|
||||
{
|
||||
final String TAG = "BabyMonitor";
|
||||
// Sets an ID for the notification
|
||||
final static int mNotificationId = 1;
|
||||
|
||||
String _address;
|
||||
int _port;
|
||||
String _name;
|
||||
NotificationManagerCompat _mNotifyMgr;
|
||||
|
||||
Thread _listenThread;
|
||||
private void streamAudio(final Socket socket) throws IllegalArgumentException, IllegalStateException, IOException
|
||||
@@ -93,6 +99,9 @@ public class ListenActivity extends Activity
|
||||
_address = b.getString("address");
|
||||
_port = b.getInt("port");
|
||||
_name = b.getString("name");
|
||||
// Gets an instance of the NotificationManager service
|
||||
_mNotifyMgr =
|
||||
NotificationManagerCompat.from(this);
|
||||
|
||||
setContentView(R.layout.activity_listen);
|
||||
|
||||
@@ -101,6 +110,15 @@ public class ListenActivity extends Activity
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
NotificationCompat.Builder mBuilder =
|
||||
new NotificationCompat.Builder(ListenActivity.this)
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.listening));
|
||||
|
||||
|
||||
_mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
|
||||
final TextView connectedText = (TextView) findViewById(R.id.connectedTo);
|
||||
connectedText.setText(_name);
|
||||
|
||||
@@ -146,6 +164,12 @@ public class ListenActivity extends Activity
|
||||
|
||||
final TextView statusText = (TextView) findViewById(R.id.textStatus);
|
||||
statusText.setText(R.string.disconnected);
|
||||
NotificationCompat.Builder mBuilder =
|
||||
new NotificationCompat.Builder(ListenActivity.this)
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.disconnected));
|
||||
_mNotifyMgr.notify(mNotificationId, mBuilder.build());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -174,7 +174,9 @@ public class MonitorActivity extends Activity
|
||||
{
|
||||
final TextView addressText = (TextView) findViewById(R.id.address);
|
||||
|
||||
final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
// Use the application context to get WifiManager, to avoid leak before Android 5.1
|
||||
final WifiManager wifiManager =
|
||||
(WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
final WifiInfo info = wifiManager.getConnectionInfo();
|
||||
final int address = info.getIpAddress();
|
||||
if(address != 0)
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Dec 28 10:00:20 PST 2015
|
||||
#Sun Dec 24 10:02:44 PST 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
|
||||
|
||||
Reference in New Issue
Block a user