提交 42d13da9 编写于 作者: T Takeya Yuki

Add Push Service

上级 0993a844
......@@ -9,6 +9,7 @@ Command Line Support<br/>
UI Control Features (Status Bar and Navigation Bar)<br/>
TTS Features<br/>
Volume Control Features<br/>
Yuki Push Service<br/>
## Current Version
1.0-git-201708111646
1.0.7-git-201708281423
......@@ -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"
......
......@@ -19,9 +19,17 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name="jp.ruby.rubylibrary.TestService" android:description="@string/app_name"
android:process="Yuki.Test.Service" android:exported="true">
<intent-filter>
<action android:name="AAA"/>
</intent-filter>
</service>
</application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
</manifest>
\ No newline at end of file
......@@ -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"
......
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);
}
}
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();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册