/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import com.topway.swiftplayservice.IPlayAIDLService;
import com.topway.swiftplayservice.PlayParams;
/* Name of the class has to be "Main" only if the class is public. */
public class MainActivity extends AppCompatActivity {
//private PlayParams playParams;
private IPlayAIDLService tService;
private ServiceConnection connection = new ServiceConnection()
{
public void onServiceConnected(ComponentName name, IBinder service)
{
//从远程service中获得AIDL实例化对象
tService
= IPlayAIDLService.
Stub.
asInterface(service
); Toast.makeText(MainActivity.this, "connect", Toast.LENGTH_SHORT).show();
Log.v("hello", "connect");
}
public void onServiceDisconnected(ComponentName name)
{
tService = null;
Toast.makeText(MainActivity.this, "disconnrct", Toast.LENGTH_SHORT).show();
Log.v("hello", "disconnect");
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1
= (Button)findViewById
(R.
id.
button); btn1.
setOnClickListener(new View.
OnClickListener() {
@Override
public void onClick
(View v
) { Intent intent = new Intent(IPlayAIDLService.class.getName());
intent.setPackage("com.topway.swiftplayservice.IPlayAIDLService");
bindService
(intent, connection,
Context.
BIND_AUTO_CREATE); Log.v("hello", "startService");
startService(intent);
PlayParams playParams = new PlayParams();
playParams.setFrequency(363);
playParams.setSymbolRate(6875);
playParams.setModulation(64);
playParams.setServiceId(2);
playParams.setCoordinateX(10);
playParams.setCoordinateY(10);
playParams.setPlayWidth(640);
playParams.setPlayHeight(320);
playParams.setSoundTrack(0);
playParams.setStopMode(1);
playParams.setProgramTag("xxx");
if(tService == null){
Toast.makeText(MainActivity.this, "tservice = null!!!!!!", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this, "tv start now", Toast.LENGTH_SHORT).show();
}
//try {
//Toast.makeText(MainActivity.this, playParams.getPlayHeight(), Toast.LENGTH_SHORT).show();
// tService.startPlay(playParams);
//} catch (RemoteException e) {
// e.printStackTrace();
//}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(connection);
}