Browse Source

增加媒资播放和后台toast弹出功能

wjg 1 năm trước cách đây
mục cha
commit
25d0b4a22d

+ 4 - 0
app/src/main/AndroidManifest.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    android:sharedUserId="android.uid.system"
     xmlns:tools="http://schemas.android.com/tools">
 
     <uses-permission android:name="android.permission.INTERNET"/>
@@ -14,6 +15,8 @@
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
+    <uses-permission android:name="android.permission.GET_TASKS" />
+    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
 
     <application
         android:allowBackup="true"
@@ -25,6 +28,7 @@
         android:supportsRtl="true"
         android:theme="@style/Theme.JedgeGLMDemo"
         android:requestLegacyExternalStorage="true"
+        android:usesCleartextTraffic="true"
         tools:targetApi="31">
         <activity
             android:name=".MainActivity"

+ 11 - 2
app/src/main/java/com/ch/jedge/bots/tvass/JedgeTVAssistant.java

@@ -38,6 +38,8 @@ public class JedgeTVAssistant extends JBotAppBase {
             JSONObject param = eMsg.getJsonObject("param");
             if("playUSB".equals(cmd))
                 playUSBMedia(param);
+            else if ("playMovie".equals(cmd))
+                playMovie(param);
             else if("installUSBApp".equals(cmd))
                 installUSBApp(param);
 
@@ -148,7 +150,6 @@ public class JedgeTVAssistant extends JBotAppBase {
         String mode = param.getString("mode");
         JeageTVBridge tvBridge = JeageTVBridge.getInstance();
         tvBridge.TVsetPictureMode(mode);
-
     }
     private static void playUSBMedia(JSONObject param) {
         if(param.isEmpty())
@@ -159,7 +160,6 @@ public class JedgeTVAssistant extends JBotAppBase {
             return;
         JeageTVBridge tvBridge = JeageTVBridge.getInstance();
         tvBridge.TVplayUSBVideo(name);
-
     }
     private static void installUSBApp(JSONObject param) {
         if(param.isEmpty())
@@ -170,6 +170,15 @@ public class JedgeTVAssistant extends JBotAppBase {
             return;
         JeageTVBridge tvBridge = JeageTVBridge.getInstance();
         tvBridge.TVinstallUSBApp(name);
+    }
+    private static void playMovie(JSONObject param) {
+        if(param.isEmpty())
+            return;
 
+        String name = param.getString("name");
+        if(name == null)
+            return;
+        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+        tvBridge.TVplayMovie(name);
     }
 }

+ 23 - 25
app/src/main/java/com/ch/jedge/llm/filter/glm/MainActivity.java

@@ -49,11 +49,13 @@ public class MainActivity extends AppCompatActivity {
     private IntentFilter filter = new IntentFilter("intent.jedge.glm.msg");
     private IntentFilter asr_filter = new IntentFilter("com.ch.jedge.llm.filter.glm.asr");
 
-    private String dir, jedgeBasePath;
+    private static boolean isServiceStart = false;
 
     @SuppressLint("UnspecifiedRegisterReceiverFlag")
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+//        if(!this.isTaskRoot())
+//            return;
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
@@ -66,31 +68,27 @@ public class MainActivity extends AppCompatActivity {
 // 将RecyclerView定位到最后一行
         mRecyclerView.scrollToPosition(mMsgList.size() - 1);
 
-        String service = "services";
-        String cfg_dir = "cfg";
-        String jedgeBasePath = QAssetsCopyer.getLocalCachePath(this, service);
-        String jedgeCfgPath = QAssetsCopyer.getLocalCachePath(this, cfg_dir);
-        if(!QAssetsCopyer.copyAssetFolder(getAssets(), cfg_dir, jedgeCfgPath)) {
-            Log.e("JEDGE","Fail to copy service files : " + service);
-        }
-        String dir = FileUtils.contactPath(jedgeBasePath, "mgs");
-        String jik_dir = FileUtils.contactPath(dir, "jik");
+        if(!isServiceStart) {
+            String service = "services";
+            String cfg_dir = "cfg";
+            String jedgeBasePath = QAssetsCopyer.getLocalCachePath(this, service);
+            String jedgeCfgPath = QAssetsCopyer.getLocalCachePath(this, cfg_dir);
+            if(!QAssetsCopyer.copyAssetFolder(getAssets(), cfg_dir, jedgeCfgPath)) {
+                Log.e("JEDGE","Fail to copy service files : " + service);
+            }
+            String dir = FileUtils.contactPath(jedgeBasePath, "mgs");
+            String jik_dir = FileUtils.contactPath(dir, "jik");
 //        QAssetsCopyer.copyAssetFolder(getAssets(), "jik", jik_dir);
 
-        this.dir = dir;
-        this.jedgeBasePath = jedgeBasePath;
+            BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "mgs", MgsService.class);
+            BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jbot", JBotService.class);
+            BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "llm", JGlmService.class);
+            BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
+            BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvass", TVAgentService.class);
+            BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
 
-        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "mgs", MgsService.class);
-        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jbot", JBotService.class);
-        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "llm", JGlmService.class);
-        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
-
-//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "mgs", MgsService.class);
-//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jbot", JBotService.class);
-//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "llm", JGlmService.class);
-        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvass", TVAgentService.class);
-//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
-        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
+            isServiceStart = true;
+        }
 
         //注册广播
         registerReceiver(new AsrMsgReceiver(), asr_filter);
@@ -141,8 +139,8 @@ public class MainActivity extends AppCompatActivity {
 
         //将RecyclerView定位到最后一行
         mRecyclerView.scrollToPosition(mMsgList.size() - 1);
-        String s = content.getContent();
-        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
+//        String s = content.getContent();
+//        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
     }
 
     class MsgReceiver extends BroadcastReceiver {

+ 116 - 2
app/src/main/java/com/ch/jedge/tvmufis/JeageTVBridge.java

@@ -7,11 +7,16 @@ import android.media.AudioManager;
 
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
 import android.util.Log;
+import android.widget.Toast;
 
 
 import androidx.core.content.FileProvider;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.ch.jedge.llm.filter.glm.service.TVMufisService;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
@@ -21,16 +26,28 @@ import com.changhong.tvos.common.exception.TVManagerNotInitException;
 import com.changhong.tvos.model.ChOsType;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.Headers;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
 
 public class JeageTVBridge {
 
     private static JeageTVBridge bridge = null;
     private TVMufisService tvMufisService;
 
+    private static Toast toast;
+
     private JeageTVBridge(){
 
     }
@@ -51,6 +68,7 @@ public class JeageTVBridge {
 //            MsgContent msg = new MsgContent(content, MsgContent.TYPE_RECEIVED);
             String msg = "glm@"+content;
             tvMufisService.brodcastMsg(msg);
+            makeToast(content);
         }
     }
 
@@ -59,6 +77,7 @@ public class JeageTVBridge {
 //            MsgContent msg = new MsgContent(content, MsgContent.TYPE_SENT);
             String msg = "user@"+content;
             tvMufisService.brodcastMsg(msg);
+            makeToast(content);
         }
     }
 
@@ -79,6 +98,20 @@ public class JeageTVBridge {
         }
     }
 
+    public void makeToast(String msg){
+        Handler handler = new Handler(Looper.getMainLooper());
+        handler.post(new Runnable() {
+            @Override
+            public void run() {
+                if(toast != null)
+                    toast.cancel();
+
+                toast = Toast.makeText(tvMufisService, msg, Toast.LENGTH_SHORT);
+                toast.show();
+            }
+        });
+    }
+
     public void TVsetVolume(int volume) {
         if((volume<0)||(volume>100))
             return;
@@ -182,7 +215,7 @@ public class JeageTVBridge {
         else {
             for(HashMap<String, String>hmap : mapList){
                 String fname = hmap.get("name");
-                if(name.equals(fname)) {
+                if(name.equals(fname)||fname.contains(name)) {
                     file = hmap.get("path");
                     break;
                 }
@@ -225,7 +258,7 @@ public class JeageTVBridge {
         else {
             for(HashMap<String, String>hmap : mapList){
                 String fname = hmap.get("name");
-                if(name.equals(fname)) {
+                if(name.equals(fname)||fname.contains(name)) {
                     file = hmap.get("path");
                     break;
                 }
@@ -249,4 +282,85 @@ public class JeageTVBridge {
         intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE,true);
         tvMufisService.startActivity(intent);
     }
+
+    public void TVplayMovie(String name) {
+        String url = "http://124.70.7.59/chiq_webservice/services?appKey=mr3z5f&method=ch.tvmall.chiq.voice.search&v=3&format=json";
+
+        JSONObject root = new JSONObject();
+        JSONObject client = new JSONObject();
+
+        client.put("agent_name", "com.changhong.chrecommendersystem");
+        client.put("agent_ver", "2.1.12");
+        client.put("device", "TV");
+        client.put("mac", "b4:9e:80:b0:99:1f");
+//        client.put("tv_model", "75Q10ART");
+        client.put("clienttype", "CH-ZM110ART-DTV-00-ICNTV");
+        client.put("tv_version", "ZM110ART_0.00031");
+
+        root.put("client", client);
+        root.put("providerCode", "chiq3");
+        root.put("resIconType", "VER_MIDDLE");
+        root.put("safeFlag", "2");
+        root.put("searchName", name);
+        root.put("searchDomain", "video");
+        root.put("sequence", 1);
+        root.put("word", "我想看"+name);
+        root.put("version", "5");
+
+        String reqBodyStr = root.toString();
+        RequestBody formBody = RequestBody.create(MediaType.get("application/json; charset=utf-8"), reqBodyStr);
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json; charset=utf-8");
+//        headers.put("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+        headers.put("Accept", "application/json; charset=utf-8");
+
+        Request request = new Request.Builder()
+                .url(url)
+                .post(formBody)
+                .headers(Headers.of(headers))
+                .build();
+
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(5, TimeUnit.SECONDS)
+                .readTimeout(3, TimeUnit.MINUTES)
+                .build();
+
+        Response okHttpResp;
+        String resultDataStr;
+        JSONObject resp;
+        try {
+            okHttpResp = okHttpClient.newCall(request).execute();
+            ResponseBody respBody = okHttpResp.body();
+            resultDataStr = respBody.string();
+            resp = JSONObject.parseObject(resultDataStr);
+            JSONObject content = resp.getJSONObject("content");
+            String code = content.getString("code");
+            if(code!=null) {
+                if("1000".equals(code)) {
+                    JSONArray resources =  content.getJSONArray("resources");
+                    if(resources.size() > 0) {
+                        JSONObject job = resources.getJSONObject(0);
+                        JSONObject startintent = job.getJSONObject("startintent");
+                        String action = startintent.getString("action");
+                        String pkgname = startintent.getString("pkgname");
+                        String clsname = startintent.getString("clsname");
+                        String starttype = startintent.getString("starttype");
+                        String uri = startintent.getString("uri");
+
+                        Intent intent = new Intent();
+
+                        intent.setPackage(pkgname);
+                        intent.setAction(action);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+                        intent.setData(Uri.parse(uri));
+                        tvMufisService.startActivity(intent);
+                    }
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 1 - 1
app/src/main/java/com/ch/jedge/tvmufis/JedgeTvMufisService.java

@@ -60,8 +60,8 @@ public class JedgeTvMufisService extends JMgbusService {
 //        if(isEnd) {
             JeageTVBridge bridge = JeageTVBridge.getInstance();
             String msg = glm_msg.replace("\n", "");
-            bridge.putglmMsg(msg);
             glm_msg = "";
+            bridge.putglmMsg(msg);
 //        }
         return JMgbusUtil.MgbusResult(200,"ok");
     }