AndroidAudioRecordService.java
Go to the documentation of this file.
00001 package org.ros.android.android_camera_viewer;
00002 
00003 
00004 import java.net.URI;
00005 import java.net.URISyntaxException;
00006 import java.util.List;
00007 
00008 import org.ros.address.InetAddressFactory;
00009 import org.ros.node.DefaultNodeMainExecutor;
00010 import org.ros.node.NodeConfiguration;
00011 import org.ros.node.NodeMain;
00012 import org.ros.node.NodeMainExecutor;
00013 
00014 import android.app.IntentService;
00015 import android.app.PendingIntent;
00016 import android.content.Intent;
00017 
00018 
00019 import android.os.Binder;
00020 import android.os.Bundle;
00021 import android.os.IBinder;
00022 import android.util.Log;
00023 
00024 
00025 public class AndroidAudioRecordService extends IntentService{
00026 
00027 
00028     AndroidAudioRecordNode main_node;
00029     NodeMain talker;
00030     Intent mintent;
00031 
00032     private String package_name;
00033 
00034     final IBinder binder = new MyBinder();
00035 
00036     public class MyBinder extends Binder{
00037         AndroidAudioRecordService getService(){
00038             return AndroidAudioRecordService.this;
00039         }
00040     }
00041 
00042     public AndroidAudioRecordService(){
00043         super("Service");
00044     }
00045 
00046     @Override
00047         public IBinder onBind(Intent intent){
00048         mintent = intent;
00049 
00050         return binder;
00051     }
00052 
00053 
00054     public void setNode(String package_name){
00055         showNotification();
00056         this.package_name = package_name;
00057 
00058 
00059         // We use this bundle                                 
00060         Bundle b = mintent.getExtras();
00061 
00062 
00063         if(this.main_node == null){
00064             try{
00065                 URI masterUri = new URI(b.getString("masterUri"));
00066                 String hostLocal = InetAddressFactory.newNonLoopback().getHostAddress();
00067                 // At this point, the user has already been prompted to either enter the URI                                  // of a master to use or to start a master locally.           
00068                     NodeMainExecutor e = DefaultNodeMainExecutor.newDefault();
00069 
00070                 NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(hostLocal,masterUri);
00071                 nodeConfiguration.setMasterUri(masterUri);
00072                 nodeConfiguration.setNodeName("/android/audio");
00073 
00074                 talker = new AndroidAudioRecordNode(package_name);
00075 
00076                 e.execute(talker, nodeConfiguration);
00077 
00078 
00079             }catch(URISyntaxException e){
00080                 e.printStackTrace();
00081             }
00082         }
00083     }
00084 
00085     @Override
00086         protected void onHandleIntent(Intent intent) {
00087         try {
00088             Thread.sleep(10000);
00089         } catch (InterruptedException e) {
00090             e.printStackTrace();
00091         }
00092 
00093     }
00094 
00095 
00099     private void showNotification() {
00100 
00101         Intent i=new Intent(this, MainActivity.class);
00102 
00103         i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
00104                    Intent.FLAG_ACTIVITY_SINGLE_TOP);
00105 
00106         PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0);
00107 
00108     }
00109 
00110     @Override
00111         public void onDestroy(){
00112         this.talker.onShutdown(null);
00113     }
00114 }
00115 


jsk_android_apps
Author(s): Kazuto Murase
autogenerated on Thu Jun 6 2019 18:03:46