This is a sample application working on notification service.
The applicaion guides how to use APIs of notification service
on android platform.
Change-Id: Ia2fa461ad299a74507ee5898d7f4174f777611b5
Signed-off-by: ch79.cho <ch79.cho@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8283
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
--- /dev/null
+*.iml\r
+.gradle\r
+/local.properties\r
+/.idea/workspace.xml\r
+/.idea/libraries\r
+.DS_Store\r
+/build\r
+/captures\r
--- /dev/null
+NotiProviderExample
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="CompilerConfiguration">
+ <resourceExtensions />
+ <wildcardResourcePatterns>
+ <entry name="!?*.java" />
+ <entry name="!?*.form" />
+ <entry name="!?*.class" />
+ <entry name="!?*.groovy" />
+ <entry name="!?*.scala" />
+ <entry name="!?*.flex" />
+ <entry name="!?*.kt" />
+ <entry name="!?*.clj" />
+ <entry name="!?*.aj" />
+ </wildcardResourcePatterns>
+ <annotationProcessing>
+ <profile default="true" name="Default" enabled="false">
+ <processorPath useClasspath="true" />
+ </profile>
+ </annotationProcessing>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<component name="CopyrightManager">
+ <settings default="" />
+</component>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="GradleSettings">
+ <option name="linkedExternalProjectsSettings">
+ <GradleProjectSettings>
+ <option name="distributionType" value="DEFAULT_WRAPPED" />
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
+ <option name="gradleJvm" value="1.8" />
+ <option name="modules">
+ <set>
+ <option value="$PROJECT_DIR$" />
+ <option value="$PROJECT_DIR$/app" />
+ <option value="$PROJECT_DIR$/iotivity-armeabi-notification-service-debug" />
+ <option value="$PROJECT_DIR$/iotivity-base-armeabi-debug" />
+ </set>
+ </option>
+ </GradleProjectSettings>
+ </option>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="EntryPointsManager">
+ <entry_points version="2.0" />
+ </component>
+ <component name="NullableNotNullManager">
+ <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
+ <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
+ <option name="myNullables">
+ <value>
+ <list size="4">
+ <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
+ <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
+ <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
+ <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
+ </list>
+ </value>
+ </option>
+ <option name="myNotNulls">
+ <value>
+ <list size="4">
+ <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
+ <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
+ <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
+ <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
+ </list>
+ </value>
+ </option>
+ </component>
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
+ <OptionsSetting value="true" id="Add" />
+ <OptionsSetting value="true" id="Remove" />
+ <OptionsSetting value="true" id="Checkout" />
+ <OptionsSetting value="true" id="Update" />
+ <OptionsSetting value="true" id="Status" />
+ <OptionsSetting value="true" id="Edit" />
+ <ConfirmationsSetting value="0" id="Add" />
+ <ConfirmationsSetting value="0" id="Remove" />
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/build/classes" />
+ </component>
+ <component name="ProjectType">
+ <option name="id" value="Android" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/NotiProviderExample.iml" filepath="$PROJECT_DIR$/NotiProviderExample.iml" />
+ <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
+ <module fileurl="file://$PROJECT_DIR$/iotivity-armeabi-notification-service-debug/iotivity-armeabi-notification-service-debug.iml" filepath="$PROJECT_DIR$/iotivity-armeabi-notification-service-debug/iotivity-armeabi-notification-service-debug.iml" />
+ <module fileurl="file://$PROJECT_DIR$/iotivity-base-armeabi-debug/iotivity-base-armeabi-debug.iml" filepath="$PROJECT_DIR$/iotivity-base-armeabi-debug/iotivity-base-armeabi-debug.iml" />
+ </modules>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="RunConfigurationProducerService">
+ <option name="ignoredProducers">
+ <set>
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
+ </set>
+ </option>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$/../../../../../../.." vcs="Git" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null
+apply plugin: 'com.android.application'\r
+\r
+android {\r
+ compileSdkVersion 23\r
+ buildToolsVersion "23.0.1"\r
+\r
+ defaultConfig {\r
+ applicationId "sample.notification.service.iotivity.org.notificationsample"\r
+ minSdkVersion 23\r
+ targetSdkVersion 23\r
+ versionCode 1\r
+ versionName "1.0"\r
+ }\r
+}\r
+\r
+dependencies {\r
+ compile fileTree(include: ['*.jar'], dir: 'libs')\r
+ compile 'com.android.support:appcompat-v7:23.0.1'\r
+ compile project(':iotivity-base-armeabi-debug')\r
+ compile project(':iotivity-armeabi-notification-service-debug')\r
+}\r
--- /dev/null
+# Add project specific ProGuard rules here.\r
+# By default, the flags in this file are appended to flags specified\r
+# in D:\adt-bundle-windows-x86_64-20140321\sdk/tools/proguard/proguard-android.txt\r
+# You can edit the include path and order by changing the proguardFiles\r
+# directive in build.gradle.\r
+#\r
+# For more details, see\r
+# http://developer.android.com/guide/developing/tools/proguard.html\r
+\r
+# Add any project specific keep options here:\r
+\r
+# If your project uses WebView with JS, uncomment the following\r
+# and specify the fully qualified class name to the JavaScript interface\r
+# class:\r
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\r
+# public *;\r
+#}\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"\r
+ package="com.sec.notiproviderexample">\r
+\r
+ <uses-feature android:name="android.hardware.nfc" />\r
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />\r
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />\r
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />\r
+ <uses-permission android:name="android.permission.BLUETOOTH"/>\r
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>\r
+ <uses-permission android:name="android.permission.INTERNET"/>\r
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>\r
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>\r
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>\r
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>\r
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>\r
+ <uses-permission android:name="android.permission.NFC" />\r
+\r
+ <application\r
+ android:allowBackup="true"\r
+ android:icon="@mipmap/ic_launcher"\r
+ android:label="@string/app_name"\r
+ android:supportsRtl="true"\r
+ android:theme="@style/AppTheme">\r
+ <activity android:name=".MainActivity">\r
+ <intent-filter>\r
+ <action android:name="android.intent.action.MAIN" />\r
+\r
+ <category android:name="android.intent.category.LAUNCHER" />\r
+ </intent-filter>\r
+ </activity>\r
+\r
+ <service\r
+ android:name="com.sec.notiproviderexample.NotiListener"\r
+ android:label="@string/app_name"\r
+ android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">\r
+\r
+ <intent-filter>\r
+ <action android:name="android.service.notification.NotificationListenerService" />\r
+ <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />\r
+ </intent-filter>\r
+ </service>\r
+ </application>\r
+\r
+</manifest>\r
--- /dev/null
+/*\r
+ *******************************************************************\r
+ *\r
+ * Copyright 2015 Intel Corporation.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+\r
+package com.sec.notiproviderexample;\r
+\r
+import android.app.Notification;\r
+import android.app.NotificationManager;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.support.v7.app.AppCompatActivity;\r
+import android.util.Log;\r
+import android.view.View;\r
+import android.widget.Button;\r
+import android.widget.EditText;\r
+import android.widget.TextView;\r
+import java.util.Random;\r
+\r
+public class MainActivity extends AppCompatActivity {\r
+\r
+ private static final int PERMISSIONS_REQUEST_READ_PHONE_STATE = 0;\r
+ private final String TAG = "NS_JNI_MAIN_ACTIVITY";\r
+\r
+ private Button btnTitle;\r
+ private Button btnBody;\r
+ private Button btnSend;\r
+ private Button btnStart;\r
+ private Button btnStop;\r
+ private Button btnAccept;\r
+ private Button btnSync;\r
+ private EditText editTextTitle;\r
+ private EditText editTextBody;\r
+ private TextView TvLog;\r
+\r
+ private static int notiId = 0;\r
+\r
+ private boolean isStarted = false;\r
+ private String LastMessageId = null;\r
+ private String consumerId;\r
+\r
+ private NotiListener mNotiListener = null;\r
+ private ProviderProxy mProviderProxy = null;\r
+\r
+ @Override\r
+ protected void onCreate(Bundle savedInstanceState) {\r
+ super.onCreate(savedInstanceState);\r
+ setContentView(R.layout.activity_main);\r
+\r
+ btnTitle = (Button) findViewById(R.id.BtnTitle);\r
+ btnBody = (Button) findViewById(R.id.BtnBody);\r
+ btnSend = (Button) findViewById(R.id.BtnCreateNoti);\r
+\r
+ btnStart = (Button) findViewById(R.id.BtnStart);\r
+ btnAccept = (Button) findViewById(R.id.BtnAccept);\r
+ btnSync = (Button) findViewById(R.id.BtnSync);\r
+ btnStop = (Button) findViewById(R.id.BtnStop);\r
+\r
+ editTextTitle = (EditText) findViewById(R.id.EditTextTitle);\r
+ editTextBody = (EditText) findViewById(R.id.EditTextBody);\r
+\r
+ TvLog = (TextView) findViewById(R.id.TvLog);\r
+\r
+ btnTitle.setEnabled(false);\r
+ btnBody.setEnabled(false);\r
+\r
+ btnSend.setOnClickListener(mClickListener);\r
+\r
+ btnStart.setOnClickListener(mClickListener);\r
+\r
+ btnAccept.setOnClickListener(mClickListener);\r
+ btnAccept.setVisibility(View.INVISIBLE);\r
+\r
+ btnSync.setOnClickListener(mClickListener);\r
+ btnSync.setVisibility(View.INVISIBLE);\r
+\r
+ btnStop.setOnClickListener(mClickListener);\r
+\r
+ mProviderProxy = new ProviderProxy(getApplicationContext());\r
+ mNotiListener = new NotiListener(this);\r
+\r
+ Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");\r
+ startActivity(intent);\r
+ }\r
+\r
+ public ProviderProxy getProviderExample() {\r
+ return mProviderProxy;\r
+ }\r
+\r
+ Button.OnClickListener mClickListener = new View.OnClickListener() {\r
+ public void onClick(View v) {\r
+ switch (v.getId()) {\r
+\r
+ case R.id.BtnStart: {\r
+ if (isStarted == false) {\r
+ Log.i(TAG, "Start NS Provider Service");\r
+\r
+ boolean access = true; // ptovider controls the acceptance of consumers\r
+ mProviderProxy.startNotificationServer(access);\r
+ isStarted = true;\r
+ } else {\r
+ Log.e(TAG, "NS Provider Service had already started");\r
+ }\r
+ }\r
+ break;\r
+\r
+ case R.id.BtnAccept: {\r
+ if(isStarted == false)\r
+ {\r
+ Log.e(TAG, "Fail to request Accept");\r
+ break;\r
+ }\r
+ mProviderProxy.accept("#consumerid", true);\r
+ }\r
+ break;\r
+\r
+ case R.id.BtnCreateNoti: {\r
+\r
+ Random r = new Random();\r
+ int notiId = r.nextInt(901) + 100; //[100, 1000]\r
+\r
+ String id = Integer.toString(notiId); // generate notificaion ID\r
+ String title = editTextTitle.getText().toString();\r
+ String body = editTextBody.getText().toString();\r
+\r
+ if(isStarted == false)\r
+ {\r
+ Log.e(TAG, "Fail to send NSMessage");\r
+ break;\r
+ }\r
+\r
+ // Build android noti object and send it to Notification service receiver\r
+ Notification.Builder notiBuilder = new Notification.Builder(getApplicationContext());\r
+ notiBuilder.setContentTitle(title);\r
+ notiBuilder.setContentText(body);\r
+ notiBuilder.setSmallIcon(R.mipmap.ic_launcher);\r
+ NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);\r
+ notiMgr.notify(notiId, notiBuilder.build());\r
+\r
+ LastMessageId= id; // for test to send sync\r
+\r
+ Log.i(TAG, "#" + notiId + " notified ..");\r
+\r
+ }\r
+ break;\r
+\r
+ case R.id.BtnSync: {\r
+ if(isStarted == false)\r
+ {\r
+ Log.e(TAG, "Fail to send sync");\r
+ break;\r
+ }\r
+ mProviderProxy.readCheck(LastMessageId);\r
+ }\r
+ break;\r
+\r
+ case R.id.BtnStop: {\r
+ if(isStarted == false)\r
+ {\r
+ Log.e(TAG, "Fail to stop service");\r
+ break;\r
+ }\r
+\r
+ mProviderProxy.stopNotificationServer();\r
+ isStarted = false;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ };\r
+}\r
+\r
--- /dev/null
+/*\r
+ *******************************************************************\r
+ *\r
+ * Copyright 2015 Intel Corporation.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+\r
+package com.sec.notiproviderexample;\r
+\r
+import android.app.Notification;\r
+import android.os.Bundle;\r
+import android.service.notification.NotificationListenerService;\r
+import android.service.notification.StatusBarNotification;\r
+import android.util.Log;\r
+\r
+public class NotiListener extends NotificationListenerService {\r
+\r
+ private final String TAG = "NS_JNI_NOTI_LISTENER";\r
+ private static ProviderProxy mProviderProxy = null;\r
+ private MainActivity mActivity = null;\r
+\r
+ public NotiListener() {\r
+\r
+ Log.i(TAG, "Create NotiListener");\r
+ }\r
+\r
+ public NotiListener(MainActivity activity) {\r
+\r
+ Log.i(TAG, "Create NotiListener with MainActivity");\r
+\r
+ this.mActivity = activity;\r
+ this.mProviderProxy = mActivity.getProviderExample();\r
+\r
+ if(mProviderProxy == null) {\r
+ Log.i(TAG, "Fail to get providerProxy instance");\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void onNotificationPosted(StatusBarNotification sbn) {\r
+ super.onNotificationPosted(sbn);\r
+\r
+ Bundle bundle = sbn.getNotification().extras;\r
+ //Log.i("PACKAGENAME : ", sbn.getPackageName());\r
+\r
+ if (sbn.getPackageName().equals("android"))\r
+ return;\r
+\r
+ String id = Integer.toString(sbn.getId());\r
+ String title = bundle.getString(Notification.EXTRA_TITLE, "");\r
+ String body = bundle.getString(Notification.EXTRA_TEXT, "");\r
+\r
+ Log.i(TAG, "onNotificationPosted .. ");\r
+ Log.i(TAG, "Id : " + id);\r
+ Log.i(TAG, "Title : " + title);\r
+ Log.i(TAG, "Body : " + body);\r
+\r
+ if (mProviderProxy != null) {\r
+\r
+ NotificationObject notiObject = new NotificationObject(id, title);\r
+ notiObject.setContentText(body);\r
+ mProviderProxy.sendNSMessage(id, title, body);\r
+\r
+ } else {\r
+ Log.i(TAG, "providerExample is NULL");\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void onNotificationRemoved(StatusBarNotification sbn) {\r
+ super.onNotificationRemoved(sbn);\r
+\r
+ Log.i(TAG, "onNotificationRemoved .. ");\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ *******************************************************************\r
+ *\r
+ * Copyright 2015 Intel Corporation.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+\r
+package com.sec.notiproviderexample;\r
+\r
+public class NotificationObject {\r
+\r
+ private static final String TITLE_KEY = "title";\r
+ private static final String ID_KEY = "id";\r
+ private static final String CONTENT_TEXT_KEY = "contentText";\r
+ private static final String TAG = "NS_JNI_NOTI_OBJECT";\r
+\r
+ private String mId = null;\r
+ private String mTitle = null;\r
+ private String mContentText = null;\r
+\r
+ public NotificationObject(String id, String title) {\r
+ this.mId = id;\r
+ this.mTitle = title;\r
+ }\r
+\r
+ public String getContentText() {\r
+\r
+ return mContentText;\r
+ }\r
+ public String getmTitle() {\r
+\r
+ return mTitle;\r
+ }\r
+ public String getmId() {\r
+\r
+ return mId;\r
+ }\r
+\r
+ public void setmId(String mId) {\r
+\r
+ this.mId = mId;\r
+ }\r
+\r
+ public void setContentText(String contentText) {\r
+\r
+ this.mContentText = contentText;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ *******************************************************************\r
+ *\r
+ * Copyright 2015 Intel Corporation.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+\r
+package com.sec.notiproviderexample;\r
+\r
+import android.content.Context;\r
+import android.util.Log;\r
+\r
+import org.iotivity.base.ModeType;\r
+import org.iotivity.base.OcPlatform;\r
+import org.iotivity.base.OcResourceHandle;\r
+import org.iotivity.base.PlatformConfig;\r
+import org.iotivity.base.QualityOfService;\r
+import org.iotivity.base.ServiceType;\r
+import org.iotivity.service.notification.IoTNotification;\r
+import org.iotivity.service.notification.NSConsumer;\r
+import org.iotivity.service.notification.NSMessage;\r
+\r
+public class ProviderProxy {\r
+\r
+ private static final String TAG = "NS_JNI_PROVIDER_PROXY";\r
+\r
+ private Context mContext = null;\r
+ private OcResourceHandle mResourceHandle; //resource handle\r
+ private IoTNotification ioTNotification = null;\r
+\r
+ private final int SUCCESS = 200;\r
+\r
+ public ProviderProxy(Context context) {\r
+ Log.i(TAG, "Create providerProxy Instance");\r
+\r
+ this.mContext = context;\r
+ ioTNotification = new IoTNotification();\r
+ }\r
+\r
+ private void configurePlatform() {\r
+\r
+ PlatformConfig platformConfig = new PlatformConfig(\r
+ mContext,\r
+ ServiceType.IN_PROC,\r
+ ModeType.CLIENT_SERVER,\r
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces\r
+ 0, // Uses randomly available port\r
+ QualityOfService.LOW\r
+ );\r
+\r
+ Log.i(TAG, "Configuring platform.");\r
+ OcPlatform.Configure(platformConfig);\r
+ try {\r
+ OcPlatform.stopPresence(); // Initialize OcPlatform\r
+ } catch(Exception e) {\r
+ Log.e(TAG, "Exception during sropPresence: " + e);\r
+ }\r
+ Log.i(TAG, "Configuration done Successfully");\r
+ }\r
+\r
+ public void startNotificationServer(boolean access)\r
+ {\r
+ configurePlatform();\r
+ ioTNotification.NSStartProvider(access);\r
+ }\r
+\r
+ public void stopNotificationServer() {\r
+\r
+ try {\r
+ OcPlatform.stopPresence();\r
+ } catch (Exception e) {\r
+ Log.e(TAG, "Exception during stopPresence to terminate ns: " + e);\r
+ }\r
+\r
+ ioTNotification.NSStopProvider();\r
+ }\r
+\r
+ public void sendNSMessage(String id, String title, String body) {\r
+\r
+ NSMessage notiMessage = new NSMessage(id);\r
+ notiMessage.setTitle(title);\r
+ notiMessage.setBody(body);\r
+ ioTNotification.NSSendNotification(notiMessage);\r
+ }\r
+\r
+ public void readCheck(String messageId) {\r
+\r
+ NSMessage notiMessage = new NSMessage(messageId);\r
+ ioTNotification.NSProviderReadCheck(notiMessage);\r
+ }\r
+\r
+ public void accept(String consumerId, boolean accepted)\r
+ {\r
+ NSConsumer consumer = new NSConsumer(consumerId);\r
+ ioTNotification.NSAccept(consumer, accepted);\r
+ }\r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ xmlns:tools="http://schemas.android.com/tools"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:paddingBottom="@dimen/activity_vertical_margin"\r
+ android:paddingLeft="@dimen/activity_horizontal_margin"\r
+ android:paddingRight="@dimen/activity_horizontal_margin"\r
+ android:paddingTop="@dimen/activity_vertical_margin"\r
+ tools:context="com.sec.notificationexample.MainActivity">\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="16dp"\r
+ android:paddingRight="16dp"\r
+ android:orientation="vertical" >\r
+\r
+ <View\r
+ android:layout_width="match_parent"\r
+ android:layout_height="1dp"\r
+ android:layout_alignParentBottom="true"\r
+ android:background="@android:color/darker_gray"/>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="10dp">\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <Button\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="60dp"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/BtnStart"\r
+ android:text="START"/>\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <Button\r
+\r
+ android:layout_height="wrap_content"\r
+ android:layout_width="150dp"\r
+ android:id="@+id/BtnAccept"\r
+ android:text="ACCEPT"/>\r
+\r
+ <Button\r
+\r
+ android:layout_height="wrap_content"\r
+ android:layout_width="150dp"\r
+ android:id="@+id/BtnSync"\r
+ android:text="SYNC"/>\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <Button\r
+ android:layout_height="wrap_content"\r
+ android:layout_width="wrap_content"\r
+ android:id="@+id/BtnTitle"\r
+ android:text="@string/btn_title"\r
+ android:onClick="selfDestruct" />\r
+\r
+ <EditText\r
+ android:id="@+id/EditTextTitle"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:windowSoftInputMode="stateHidden"\r
+ android:hint="글자를 입력하세요" />\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:id="@+id/LinearBody"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <Button\r
+ android:layout_height="wrap_content"\r
+ android:layout_width="wrap_content"\r
+ android:id="@+id/BtnBody"\r
+ android:text="@string/btn_body"\r
+ android:onClick="selfDestruct" />\r
+\r
+ <EditText\r
+ android:id="@+id/EditTextBody"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:windowSoftInputMode="stateHidden"\r
+ android:hint="글자를 입력하세요" />\r
+ </LinearLayout>\r
+\r
+ <Button\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="60dp"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/BtnCreateNoti"\r
+ android:text="@string/btn_create_noti"\r
+ />\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="10dp">\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <TextView\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="200dp"\r
+ android:layout_width="match_parent"\r
+ android:scrollbars="vertical"\r
+ android:id="@+id/TvLog"\r
+ android:text="Log.."/>\r
+ </LinearLayout>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:paddingLeft="5dp"\r
+ android:paddingRight="5dp"\r
+ android:orientation="horizontal" >\r
+\r
+ <Button\r
+ android:layout_gravity="center_vertical|center_horizontal"\r
+ android:layout_height="60dp"\r
+ android:layout_width="match_parent"\r
+ android:id="@+id/BtnStop"\r
+ android:text="STOP"/>\r
+ </LinearLayout>\r
+\r
+ <View\r
+ android:layout_width="match_parent"\r
+ android:layout_height="1dp"\r
+ android:layout_alignParentBottom="true"\r
+ android:background="@android:color/darker_gray"/>\r
+\r
+ <LinearLayout\r
+ android:layout_width="match_parent"\r
+ android:layout_height="20dp">\r
+ </LinearLayout>\r
+\r
+ </LinearLayout>\r
+\r
+\r
+</RelativeLayout>\r
--- /dev/null
+<resources>\r
+ <!-- Example customization of dimensions originally defined in res/values/dimens.xml\r
+ (such as screen margins) for screens with more than 820dp of available width. This\r
+ would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->\r
+ <dimen name="activity_horizontal_margin">64dp</dimen>\r
+</resources>\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<resources>\r
+ <color name="colorPrimary">#3F51B5</color>\r
+ <color name="colorPrimaryDark">#303F9F</color>\r
+ <color name="colorAccent">#FF4081</color>\r
+</resources>\r
--- /dev/null
+<resources>\r
+ <!-- Default screen margins, per the Android Design guidelines. -->\r
+ <dimen name="activity_horizontal_margin">16dp</dimen>\r
+ <dimen name="activity_vertical_margin">16dp</dimen>\r
+</resources>\r
--- /dev/null
+<resources>\r
+ <string name="app_name">NotificationProviderExample</string>\r
+ <string name="btn_title">Title</string>\r
+ <string name="btn_body">Body</string>\r
+ <string name="btn_send">Send Notification</string>\r
+ <string name="btn_create_noti">Create Notification</string>\r
+</resources>\r
--- /dev/null
+<resources>\r
+\r
+ <!-- Base application theme. -->\r
+ <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">\r
+ <!-- Customize your theme here. -->\r
+ <item name="colorPrimary">@color/colorPrimary</item>\r
+ <item name="colorPrimaryDark">@color/colorPrimaryDark</item>\r
+ <item name="colorAccent">@color/colorAccent</item>\r
+ </style>\r
+\r
+</resources>\r
--- /dev/null
+package com.sec.notiproviderexample;\r
+\r
+import org.junit.Test;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+/**\r
+ * To work on unit tests, switch the Test Artifact in the Build Variants view.\r
+ */\r
+public class ExampleUnitTest {\r
+ @Test\r
+ public void addition_isCorrect() throws Exception {\r
+ assertEquals(4, 2 + 2);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+// Top-level build file where you can add configuration options common to all sub-projects/modules.\r
+\r
+buildscript {\r
+ repositories {\r
+ jcenter()\r
+ }\r
+ dependencies {\r
+ classpath 'com.android.tools.build:gradle:1.5.0'\r
+\r
+ // NOTE: Do not place your application dependencies here; they belong\r
+ // in the individual module build.gradle files\r
+ }\r
+}\r
+\r
+allprojects {\r
+ repositories {\r
+ jcenter()\r
+ }\r
+}\r
+\r
+task clean(type: Delete) {\r
+ delete rootProject.buildDir\r
+}\r
--- /dev/null
+@if "%DEBUG%" == "" @echo off\r
+@rem ##########################################################################\r
+@rem\r
+@rem Gradle startup script for Windows\r
+@rem\r
+@rem ##########################################################################\r
+\r
+@rem Set local scope for the variables with windows NT shell\r
+if "%OS%"=="Windows_NT" setlocal\r
+\r
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r
+set DEFAULT_JVM_OPTS=\r
+\r
+set DIRNAME=%~dp0\r
+if "%DIRNAME%" == "" set DIRNAME=.\r
+set APP_BASE_NAME=%~n0\r
+set APP_HOME=%DIRNAME%\r
+\r
+@rem Find java.exe\r
+if defined JAVA_HOME goto findJavaFromJavaHome\r
+\r
+set JAVA_EXE=java.exe\r
+%JAVA_EXE% -version >NUL 2>&1\r
+if "%ERRORLEVEL%" == "0" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:findJavaFromJavaHome\r
+set JAVA_HOME=%JAVA_HOME:"=%\r
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe\r
+\r
+if exist "%JAVA_EXE%" goto init\r
+\r
+echo.\r
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r
+echo.\r
+echo Please set the JAVA_HOME variable in your environment to match the\r
+echo location of your Java installation.\r
+\r
+goto fail\r
+\r
+:init\r
+@rem Get command-line arguments, handling Windowz variants\r
+\r
+if not "%OS%" == "Windows_NT" goto win9xME_args\r
+if "%@eval[2+2]" == "4" goto 4NT_args\r
+\r
+:win9xME_args\r
+@rem Slurp the command line arguments.\r
+set CMD_LINE_ARGS=\r
+set _SKIP=2\r
+\r
+:win9xME_args_slurp\r
+if "x%~1" == "x" goto execute\r
+\r
+set CMD_LINE_ARGS=%*\r
+goto execute\r
+\r
+:4NT_args\r
+@rem Get arguments from the 4NT Shell from JP Software\r
+set CMD_LINE_ARGS=%$\r
+\r
+:execute\r
+@rem Setup the command line\r
+\r
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar\r
+\r
+@rem Execute Gradle\r
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r
+\r
+:end\r
+@rem End local scope for the variables with windows NT shell\r
+if "%ERRORLEVEL%"=="0" goto mainEnd\r
+\r
+:fail\r
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r
+rem the _cmd.exe /c_ return code!\r
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1\r
+exit /b 1\r
+\r
+:mainEnd\r
+if "%OS%"=="Windows_NT" endlocal\r
+\r
+:omega\r
--- /dev/null
+include ':app', ':iotivity-base-armeabi-debug', ':iotivity-armeabi-notification-service-debug'\r