зеркало из https://github.com/mozilla/Jisort.git
Merge pull request #172 from iHub/bugfixes
Merging Notification functionality
This commit is contained in:
Коммит
01138d9027
|
@ -88,33 +88,39 @@
|
|||
android:name=".recievers.DSOAirplaneModeReceiver"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
|
||||
<action android:name="android.intent.action.AIRPLANE_MODE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".recievers.DSOChangedBroadcastReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
|
||||
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
|
||||
<action android:name="android.bluetooth.adapter.action.BATTERY_CHANGED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".recievers.DSOStorageReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
|
||||
<action android:name="android.intent.action.DEVICE_STORAGE_LOW" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".recievers.DSONetworkStateReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
|
||||
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".recievers.DSOBatteryReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
|
||||
<action android:name="android.intent.action.ACTION_BATTERY_LOW" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".recievers.DSOLocationReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
|
||||
<action android:name="android.location.PROVIDERS_CHANGED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
@ -148,5 +154,4 @@
|
|||
android:name=".services.DataBootstrapService"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,10 +1,15 @@
|
|||
package com.mozilla.hackathon.kiboko;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.activities.TutorialSlideActivity;
|
||||
import com.mozilla.hackathon.kiboko.recievers.DSOBatteryReceiver;
|
||||
|
||||
/**
|
||||
|
@ -25,4 +30,28 @@ public class App extends Application {
|
|||
public static Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void createNotification(String msg, String tag) {
|
||||
// Prepare intent which is triggered if the
|
||||
// notification is selected
|
||||
Intent intent = new Intent(getContext(), TutorialSlideActivity.class);
|
||||
intent.putExtra("topic", tag);
|
||||
PendingIntent pIntent = PendingIntent.getActivity(getContext(), (int) System.currentTimeMillis(), intent, 0);
|
||||
|
||||
// Build notification
|
||||
// Actions are just fake
|
||||
Notification notification = new NotificationCompat.Builder(getContext())
|
||||
.setContentTitle(getContext().getString(R.string.app_name))
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
|
||||
// .setSmallIcon(R.drawable.ic_launcher)
|
||||
.setContentIntent(pIntent)
|
||||
.setAutoCancel(true)
|
||||
.addAction(0, "Lear More", pIntent).build();
|
||||
NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(NOTIFICATION_SERVICE);
|
||||
// hide the notification after its selected
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
|
||||
notificationManager.notify(0, notification);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.App;
|
||||
|
||||
public class DSOAirplaneModeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
boolean isAirplaneModeOn = intent.getBooleanExtra("state", false);
|
||||
if(isAirplaneModeOn){
|
||||
|
||||
App.createNotification("You have enabled Airplane mode. Your device is now offline.", "airplane_mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.os.BatteryManager;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.App;
|
||||
|
||||
/**
|
||||
* Created by mwadime on 6/7/2016.
|
||||
*/
|
||||
|
@ -15,6 +17,7 @@ public class DSOBatteryReceiver extends BroadcastReceiver {
|
|||
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||
|
||||
if(rawlevel <= 25){
|
||||
App.createNotification("Your phone battery is running low.", "battery");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.App;
|
||||
import com.mozilla.hackathon.kiboko.utilities.NetworkUtils;
|
||||
|
||||
/**
|
||||
|
@ -19,14 +20,7 @@ import com.mozilla.hackathon.kiboko.utilities.NetworkUtils;
|
|||
NetworkInfo ni=(NetworkInfo) intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
|
||||
if(ni!=null && ni.getState()==NetworkInfo.State.CONNECTED)
|
||||
{
|
||||
// there is Internet connection
|
||||
} else
|
||||
|
||||
|
||||
if(intent .getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,Boolean.FALSE))
|
||||
{
|
||||
// no Internet connection, send network state changed
|
||||
|
||||
App.createNotification("Your device is now connected to wifi.", "wifi");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.App;
|
||||
|
||||
/**
|
||||
* Created by mwadime on 6/7/2016.
|
||||
*/
|
||||
|
@ -11,7 +13,7 @@ public class DSOStorageReceiver extends BroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(intent.getAction().matches(Intent.ACTION_DEVICE_STORAGE_LOW)){
|
||||
|
||||
App.createNotification("Your device is running out of storage.", "storage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче