Pop up notification on first succesful Tap to Share.
Change-Id: Id2ddeea908af1159e5738e52a92f7f9818496761
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d8d62d9..248669c 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -21,6 +21,12 @@
<!-- A notification action string prompting the user to share their contact details over NFC [CHAR-LIMIT=64] -->
<string name="outbound_me_profile_text">Tap to give this person your contact info</string>
+ <!-- A notification description string telling the user he has shared something over NFC [CHAR-LIMIT=64] -->
+ <string name="first_share_title">You just tapped to share!</string>
+
+ <!-- A notification action string telling the user to tap to learn more about sharing over NFC [CHAR-LIMIT=64] -->
+ <string name="first_share_text">Tap to learn more or disable this feature.</string>
+
<!-- Content description of the NFC enabled notification icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_nfc_enabled">NFC enabled.</string>
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index f72aa8a..efacaed 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -30,6 +30,8 @@
import android.app.Application;
import android.app.KeyguardManager;
+import android.app.Notification;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -68,6 +70,7 @@
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.provider.Settings;
import android.util.Log;
import java.io.DataInputStream;
@@ -111,6 +114,9 @@
private static final boolean ZEROCLICK_ON_DEFAULT = true;
private static final String PREF_FIRST_BOOT = "first_boot";
+ private static final String PREF_FIRST_SHARE = "first_share";
+
+ private static final int NOTIFICATION_FIRST_SHARE = 0;
static final int MSG_NDEF_TAG = 0;
static final int MSG_CARD_EMULATION = 1;
@@ -178,6 +184,7 @@
private SharedPreferences mPrefs;
private SharedPreferences.Editor mPrefsEditor;
private PowerManager.WakeLock mWakeLock;
+ private NotificationManager mNotificationManager;
NdefP2pManager mP2pManager;
int mStartSound;
int mEndSound;
@@ -315,6 +322,9 @@
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
+ mNotificationManager = (NotificationManager) this.getSystemService(
+ Context.NOTIFICATION_SERVICE);
+
registerReceiver(mReceiver, filter);
Thread t = new Thread() {
@@ -330,6 +340,20 @@
t.start();
}
+ private void onFirstShare() {
+ Intent intent = new Intent(Settings.ACTION_NFCSHARING_SETTINGS);
+ PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ Notification notification = new Notification.Builder(mContext)
+ .setContentTitle(mContext.getString(R.string.first_share_title))
+ .setContentText(mContext.getString(R.string.first_share_text))
+ .setContentIntent(pi)
+ .setSmallIcon(R.drawable.stat_sys_nfc)
+ .setAutoCancel(true)
+ .getNotification();
+ mNotificationManager.notify(NOTIFICATION_FIRST_SHARE, notification);
+ }
+
private void playSound(int sound) {
synchronized (this) {
mSoundPool.play(sound, 1.0f, 1.0f, 0, 0, 1.0f);
@@ -349,6 +373,14 @@
if (mP2pStarted) {
playSound(mEndSound);
mP2pStarted = false;
+
+ // If first time, throw up a notification
+ if (mPrefs.getBoolean(PREF_FIRST_SHARE, true)) {
+ Log.i(TAG, "First NFC share");
+ mPrefsEditor.putBoolean(PREF_FIRST_SHARE, false);
+ mPrefsEditor.apply();
+ onFirstShare();
+ }
}
}