Skip to content

Commit

Permalink
updated to API 26, but not working yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSeker committed Aug 24, 2017
1 parent e117a24 commit 0cc69d9
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 32 deletions.
30 changes: 19 additions & 11 deletions BroadCastDemo2/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,33 @@
<sourceFolder url="file:https://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file:https://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file:https://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file:https://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file:https://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file:https://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-core-ui-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-25.4.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-fragment-25.4.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-26.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-compat-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-26.0.1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-26.0.1" level="project" />
</component>
</module>
6 changes: 3 additions & 3 deletions BroadCastDemo2/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
applicationId "edu.cs4730.broadcastdemo2"
Expand All @@ -21,5 +21,5 @@ android {
}

dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:appcompat-v7:26.0.1'
}
22 changes: 11 additions & 11 deletions BroadcastNoti/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@
<excludeFolder url="file:https://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file:https://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-core-ui-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-25.4.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-fragment-25.4.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-25.4.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-26.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-compat-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-26.0.1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-26.0.1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-26.0.1" level="project" />
</component>
</module>
8 changes: 4 additions & 4 deletions BroadcastNoti/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
applicationId "edu.cs4730.broadcastnoti"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
versionCode = "1"
versionName = "1.0"
}
Expand All @@ -22,5 +22,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:appcompat-v7:26.0.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Calendar;

import android.app.AlarmManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
Expand All @@ -11,15 +13,18 @@
import android.util.Log;



public class MainActivity extends AppCompatActivity {
public static final String ACTION = "edu.cs4730.bcr.noti";

public static String id = "test_channel_01";
NotificationManager nm;
MainFragment mFragment = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

//check see if there is data in the bundle, ie launched from a notification!
String info = "Nothing";
Expand All @@ -38,7 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, mFragment).commit();
}

createchannel();
}

public void setalarm() {
Expand All @@ -56,6 +61,7 @@ public void setalarm() {
//---PendingIntent to launch receiver when the alarm triggers-
//Intent notificationIntent = new Intent(getApplicationContext(), MyReceiver.class);
Intent notificationIntent = new Intent(MainActivity.ACTION);
notificationIntent.setPackage("edu.cs4730.broadcastnoti"); //in API 26, it must be explicit now.
notificationIntent.putExtra("NotifID", NotID);

//Note there is only one difference in this code from the notificationdemo code. and it's
Expand All @@ -68,4 +74,27 @@ public void setalarm() {
//sendBroadcast(notificationIntent);//let's see if it works... without the alarm.
finish(); //exit the app.
}

/*
* for API 26+ create notification channels
*/
private void createchannel() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(id,
getString(R.string.channel_name), //name of the channel
NotificationManager.IMPORTANCE_LOW); //importance level
//important level: default is is high on the phone. high is urgent on the phone. low is medium, so none is low?
// Configure the notification channel.
mChannel.setDescription(getString(R.string.channel_description));
// mChannel.enableLights(true);
// Sets the notification light color for notifications posted to this channel, if the device supports this feature.
//mChannel.setLightColor(Color.RED);
// mChannel.enableVibration(true);
mChannel.setShowBadge(true);
//mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
nm.createNotificationChannel(mChannel);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public void onReceive(Context context, Intent intent) {
notificationIntent.putExtra("mytype", "2 minutes later?");
PendingIntent contentIntent = PendingIntent.getActivity(context, notifID, notificationIntent, 0);
//create the notification
Notification notif = new NotificationCompat.Builder(context)
Notification notif = new NotificationCompat.Builder(context, MainActivity.id)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis()) //When the event occurred, now, since noti are stored by time.
.setContentTitle("Time's up!") //Title message top row.
.setContentText("This is your alert, courtesy of the AlarmManager") //message when looking at the notification, second row
.setContentIntent(contentIntent) //what activity to open.
.setChannelId(MainActivity.id)
.setAutoCancel(true) //allow auto cancel when pressed.
.build(); //finally build and return a Notification.
//Show the notification
Expand Down
3 changes: 3 additions & 0 deletions BroadcastNoti/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<string name="action_settings">Settings</string>
<string name="hello_blank_fragment">Hello blank fragment</string>


<string name="channel_name">Test Channel 1</string>
<string name="channel_description">This is a test channel at level a high level, where lights, sound, and vibration are active.</string>
</resources>

0 comments on commit 0cc69d9

Please sign in to comment.