Skip to content

Commit

Permalink
an example with a JobIntentService
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSeker committed Sep 9, 2017
1 parent a6a1962 commit 5d0ac37
Show file tree
Hide file tree
Showing 37 changed files with 862 additions and 0 deletions.
9 changes: 9 additions & 0 deletions BoradcastBoot2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
22 changes: 22 additions & 0 deletions BoradcastBoot2/.idea/compiler.xml

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

3 changes: 3 additions & 0 deletions BoradcastBoot2/.idea/copyright/profiles_settings.xml

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

18 changes: 18 additions & 0 deletions BoradcastBoot2/.idea/gradle.xml

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

46 changes: 46 additions & 0 deletions BoradcastBoot2/.idea/misc.xml

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

9 changes: 9 additions & 0 deletions BoradcastBoot2/.idea/modules.xml

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

12 changes: 12 additions & 0 deletions BoradcastBoot2/.idea/runConfigurations.xml

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

1 change: 1 addition & 0 deletions BoradcastBoot2/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions BoradcastBoot2/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "edu.cs4730.boradcastboot2"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-compat:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:26.+'
}
25 changes: 25 additions & 0 deletions BoradcastBoot2/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Android\android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http:https://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
37 changes: 37 additions & 0 deletions BoradcastBoot2/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="edu.cs4730.boradcastboot2">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<service
android:name=".MyJobIntentService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package edu.cs4730.boradcastboot2;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
final String TAG = "MainActivity";
public static String id = "test_channel_01";
MainFragment mFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String info = "Nothing";
Bundle extras = getIntent().getExtras();
if (extras != null) {
info = extras.getString("mText");
}
Log.wtf(TAG, "info is " + info);
mFragment = MainFragment.newInstance(info);

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, mFragment).commit();
} else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, mFragment).commit();
}


createchannel();

}


/*
* for API 26+ create notification channels
*/
private void createchannel() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel = new NotificationChannel(id,
getString(R.string.channel_name), //name of the channel
NotificationManager.IMPORTANCE_DEFAULT); //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
@@ -0,0 +1,63 @@
package edu.cs4730.boradcastboot2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
* All this fragment does is display information.
* <p>
* It also has a button to "jump start" the process. Basically the first message.
*/

public class MainFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";

String info = "";
TextView logger;

public MainFragment() {
// Required empty public constructor
}

public static MainFragment newInstance(String param1) {
MainFragment fragment = new MainFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
info = getArguments().getString(ARG_PARAM1);

}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.fragment_main, container, false);
logger = myView.findViewById(R.id.textView2);
logger.setText(info);

myView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
//normally this intent should have something, like data...
MyJobIntentService.enqueueWork(getContext(),intent);
}
});
return myView;
}

}
Loading

0 comments on commit 5d0ac37

Please sign in to comment.