diff --git a/README.md b/README.md index e25bf3953755e45947b3a7d048f259134f9aaef8..c36f188d06bc0214b3d20b6616680800d8e65dc1 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Command Line Support
UI Control Features (Status Bar and Navigation Bar)
TTS Features
Volume Control Features
+Yuki Push Service
## Current Version -1.0-git-201708111646 +1.0.7-git-201708281423 diff --git a/app/build.gradle b/app/build.gradle index 428f01005e3d857bf22deb1eee68f22879790913..906538460aa5cefb47717af99f1c616de4b2da4d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "26.0.0" defaultConfig { applicationId "jp.ruby.rubylibrary" - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 26 versionCode 1 versionName "1.0" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fa052eb49934abaa30e0c624dd8d615ca9623bc2..280a1f0c13d1488d30cca25ce525ee2c1f9853aa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,9 +19,17 @@ + + + + + + + \ No newline at end of file diff --git a/rubylib/build.gradle b/rubylib/build.gradle index 28233154116d011ca594956771177b81ff3a999d..f5eeb4a6a2f009fcccc30845b44daf9b2257eaab 100644 --- a/rubylib/build.gradle +++ b/rubylib/build.gradle @@ -7,7 +7,7 @@ publish { userOrg = 'takeya-yuki-studio' //bintray注册的用户名 groupId = 'jp.ruby.rubylib' //compile引用时的第1部分groupId artifactId = 'rubylib' //compile引用时的第2部分项目名 - publishVersion = '1.0.6' //compile引用时的第3部分版本号 + publishVersion = '1.0.7' //compile引用时的第3部分版本号 desc = 'Ruby Extended Controls' website = 'https://github.com/Takeya-Yuki/RubyLib.git' } @@ -18,10 +18,10 @@ android { buildToolsVersion "26.0.0" defaultConfig { - minSdkVersion 17 + minSdkVersion 21 targetSdkVersion 26 - versionCode 6 - versionName "1.0.6" + versionCode 7 + versionName "1.0.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/rubylib/src/main/java/yuki/msg/extended/NotificationController.java b/rubylib/src/main/java/yuki/msg/extended/NotificationController.java new file mode 100644 index 0000000000000000000000000000000000000000..92a4f0bd9db125fc3437dfde86c320bccaa6ae5a --- /dev/null +++ b/rubylib/src/main/java/yuki/msg/extended/NotificationController.java @@ -0,0 +1,23 @@ +package yuki.msg.extended; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Parcel; + +/** + * Created by Akeno on 2017/08/28. + */ + +public class NotificationController { + public static void Notify(Context context,int id, int icon, PendingIntent pendingIntent,String ticker, String title, String content, int flags){ + NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); + Notification.Builder nb=new Notification.Builder(context); + nb.setSmallIcon(icon).setContentIntent(pendingIntent).setTicker(ticker).setContentTitle(title).setContentText(content).setWhen(System.currentTimeMillis()); + Notification notification=nb.build(); + notification.flags=flags; + nm.notify(id,notification); + } +} diff --git a/rubylib/src/main/java/yuki/msg/extended/YukiPushService.java b/rubylib/src/main/java/yuki/msg/extended/YukiPushService.java new file mode 100644 index 0000000000000000000000000000000000000000..e980dba05fb2b1e24bcfefbd85a4ccee24bd2555 --- /dev/null +++ b/rubylib/src/main/java/yuki/msg/extended/YukiPushService.java @@ -0,0 +1,101 @@ +package yuki.msg.extended; + +import android.app.Notification; +import android.app.PendingIntent; +import android.app.Service; +import android.content.Intent; +import android.net.Uri; +import android.os.IBinder; +import android.support.annotation.IntDef; +import android.support.annotation.Nullable; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Socket; + +/** + * Created by Akeno on 2017/08/28. + */ + +public abstract class YukiPushService extends Service { + + public abstract String GetRemoteEndPoint(); + private Socket socket; + public abstract int GetIcon(); + public abstract int GetServiceID(); + + public void MessagePushed(String msg){ + Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse("msg://msg")); + PendingIntent pi=PendingIntent.getActivity(getApplicationContext(),0,i,PendingIntent.FLAG_UPDATE_CURRENT); + NotificationController.Notify(getApplicationContext(),GetServiceID(),GetIcon(),pi, + "Yuki Push Service","Yuki Push Service",msg, Notification.FLAG_NO_CLEAR|Notification.FLAG_AUTO_CANCEL); + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onCreate(){ + super.onCreate(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + + Thread thread=new Thread(new Runnable() { + @Override + public void run() { + try { + final String EndPoint=GetRemoteEndPoint(); + Log.e("ep",EndPoint); + Log.e("eph",EndPoint.split(":")[0]); + Log.e("epp",EndPoint.split(":")[1]); + socket = new Socket(EndPoint.split(":")[0], Integer.parseInt(EndPoint.split(":")[1])); + BufferedReader sin=new BufferedReader(new InputStreamReader(socket.getInputStream())); + String readline; + readline=sin.readLine(); + + while(readline!=null){ + readline=sin.readLine(); + if(readline.isEmpty()){continue;} + if(readline==null){ + break; + } + MessagePushed(readline); + } + socket.close(); + } + catch(IOException ex) { + + } + catch (Exception ex){ + + }finally { + if(socket.isClosed()){ + + } + else if(socket.isConnected()){ + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + }); + thread.start(); + return Service.START_STICKY; + //return super.onStartCommand(intent, flags, startId); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } +}