我怎么能';运行';android studio中的这个应用程序?
我学习tizen应用程序,我尝试使用示例应用程序-hello accesory 这是一份文件。但是它太简单了,我不知道怎么跑 这个项目有两部分,tizen应用程序和android服务。 但我首先使用安卓服务 我在android studio中导入(打开)项目并连接手机。但当我按下“运行”或“调试”按钮时,会发生此错误我怎么能';运行';android studio中的这个应用程序?,android,android-studio,android-service,tizen,Android,Android Studio,Android Service,Tizen,我学习tizen应用程序,我尝试使用示例应用程序-hello accesory 这是一份文件。但是它太简单了,我不知道怎么跑 这个项目有两部分,tizen应用程序和android服务。 但我首先使用安卓服务 我在android studio中导入(打开)项目并连接手机。但当我按下“运行”或“调试”按钮时,会发生此错误 Error running 'app' Default Activity not found 我看到一个博客,他说“使用构建-生成签名apk”。它起作用了。我通过apk文件安装
Error running 'app'
Default Activity not found
我看到一个博客,他说“使用构建-生成签名apk”。它起作用了。我通过apk文件安装到手机上。
但我不知道它真的有用。因为我安装了tizen应用程序并尝试连接,tizen android连接无法工作
我认为android服务有问题,或者tizen应用程序有问题,但我不能在android上进行任何测试
我想知道如何知道服务正在运行,以及如何在android studio中调试。
下面是androidManifest.xml和源代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samsung.android.sdk.accessory.example.helloaccessory.provider"
android:versionCode="4"
android:versionName="2.0.2" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="com.samsung.WATCH_APP_TYPE.Companion" />
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" >
<service android:name="com.samsung.android.sdk.accessory.example.helloaccessory.provider.ProviderService" />
<receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver" >
<intent-filter>
<action android:name="com.samsung.accessory.action.REGISTER_AGENT" />
</intent-filter>
</receiver>
<receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" >
<intent-filter>
<action android:name="com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED" />
</intent-filter>
</receiver>
<meta-data
android:name="AccessoryServicesLocation"
android:value="/res/xml/accessoryservices.xml" />
<meta-data
android:name="GearAppType"
android:value="tpk" />
</application>
</manifest>
package com.samsung.android.sdk.accessory.example.helloaccessory.provider;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.widget.Toast;
import android.util.Log;
import com.samsung.android.sdk.SsdkUnsupportedException;
import com.samsung.android.sdk.accessory.*;
public class ProviderService extends SAAgent {
private static final String TAG = "HelloAccessory(P)";
private static final Class<ServiceConnection> SASOCKET_CLASS = ServiceConnection.class;
private final IBinder mBinder = new LocalBinder();
private ServiceConnection mConnectionHandler = null;
Handler mHandler = new Handler();
public ProviderService() {
super(TAG, SASOCKET_CLASS);
}
@Override
public void onCreate() {
super.onCreate();
SA mAccessory = new SA();
try {
mAccessory.initialize(this);
} catch (SsdkUnsupportedException e) {
// try to handle SsdkUnsupportedException
if (processUnsupportedException(e) == true) {
return;
}
} catch (Exception e1) {
e1.printStackTrace();
/*
* Your application can not use Samsung Accessory SDK. Your application should work smoothly
* without using this SDK, or you may want to notify user and close your application gracefully
* (release resources, stop Service threads, close UI thread, etc.)
*/
stopSelf();
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
protected void onFindPeerAgentsResponse(SAPeerAgent[] peerAgents, int result) {
Log.d(TAG, "onFindPeerAgentResponse : result =" + result);
}
@Override
protected void onServiceConnectionRequested(SAPeerAgent peerAgent) {
if (peerAgent != null) {
Toast.makeText(getBaseContext(), R.string.ConnectionAcceptedMsg, Toast.LENGTH_SHORT).show();
acceptServiceConnectionRequest(peerAgent);
}
}
@Override
protected void onServiceConnectionResponse(SAPeerAgent peerAgent, SASocket socket, int result) {
if (result == SAAgent.CONNECTION_SUCCESS) {
if (socket != null) {
mConnectionHandler = (ServiceConnection) socket;
}
} else if (result == SAAgent.CONNECTION_ALREADY_EXIST) {
Log.e(TAG, "onServiceConnectionResponse, CONNECTION_ALREADY_EXIST");
}
}
@Override
protected void onAuthenticationResponse(SAPeerAgent peerAgent, SAAuthenticationToken authToken, int error) {
/*
* The authenticatePeerAgent(peerAgent) API may not be working properly depending on the firmware
* version of accessory device. Please refer to another sample application for Security.
*/
}
@Override
protected void onError(SAPeerAgent peerAgent, String errorMessage, int errorCode) {
super.onError(peerAgent, errorMessage, errorCode);
}
private boolean processUnsupportedException(SsdkUnsupportedException e) {
e.printStackTrace();
int errType = e.getType();
if (errType == SsdkUnsupportedException.VENDOR_NOT_SUPPORTED
|| errType == SsdkUnsupportedException.DEVICE_NOT_SUPPORTED) {
/*
* Your application can not use Samsung Accessory SDK. You application should work smoothly
* without using this SDK, or you may want to notify user and close your app gracefully (release
* resources, stop Service threads, close UI thread, etc.)
*/
stopSelf();
} else if (errType == SsdkUnsupportedException.LIBRARY_NOT_INSTALLED) {
Log.e(TAG, "You need to install Samsung Accessory SDK to use this application.");
} else if (errType == SsdkUnsupportedException.LIBRARY_UPDATE_IS_REQUIRED) {
Log.e(TAG, "You need to update Samsung Accessory SDK to use this application.");
} else if (errType == SsdkUnsupportedException.LIBRARY_UPDATE_IS_RECOMMENDED) {
Log.e(TAG, "We recommend that you update your Samsung Accessory SDK before using this application.");
return false;
}
return true;
}
public class LocalBinder extends Binder {
public ProviderService getService() {
return ProviderService.this;
}
}
public class ServiceConnection extends SASocket {
public ServiceConnection() {
super(ServiceConnection.class.getName());
}
@Override
public void onError(int channelId, String errorMessage, int errorCode) {
}
@Override
public void onReceive(int channelId, byte[] data) {
if (mConnectionHandler == null) {
return;
}
Calendar calendar = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd aa hh:mm:ss.SSS");
String timeStr = " " + dateFormat.format(calendar.getTime());
String strToUpdateUI = new String(data);
final String message = strToUpdateUI.concat(timeStr);
new Thread(new Runnable() {
public void run() {
try {
mConnectionHandler.send(getServiceChannelId(0), message.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
@Override
protected void onServiceConnectionLost(int reason) {
mConnectionHandler = null;
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getBaseContext(), R.string.ConnectionTerminateddMsg, Toast.LENGTH_SHORT).show();
}
});
}
}
}
源代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samsung.android.sdk.accessory.example.helloaccessory.provider"
android:versionCode="4"
android:versionName="2.0.2" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="com.samsung.WATCH_APP_TYPE.Companion" />
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" >
<service android:name="com.samsung.android.sdk.accessory.example.helloaccessory.provider.ProviderService" />
<receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver" >
<intent-filter>
<action android:name="com.samsung.accessory.action.REGISTER_AGENT" />
</intent-filter>
</receiver>
<receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" >
<intent-filter>
<action android:name="com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED" />
</intent-filter>
</receiver>
<meta-data
android:name="AccessoryServicesLocation"
android:value="/res/xml/accessoryservices.xml" />
<meta-data
android:name="GearAppType"
android:value="tpk" />
</application>
</manifest>
package com.samsung.android.sdk.accessory.example.helloaccessory.provider;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.widget.Toast;
import android.util.Log;
import com.samsung.android.sdk.SsdkUnsupportedException;
import com.samsung.android.sdk.accessory.*;
public class ProviderService extends SAAgent {
private static final String TAG = "HelloAccessory(P)";
private static final Class<ServiceConnection> SASOCKET_CLASS = ServiceConnection.class;
private final IBinder mBinder = new LocalBinder();
private ServiceConnection mConnectionHandler = null;
Handler mHandler = new Handler();
public ProviderService() {
super(TAG, SASOCKET_CLASS);
}
@Override
public void onCreate() {
super.onCreate();
SA mAccessory = new SA();
try {
mAccessory.initialize(this);
} catch (SsdkUnsupportedException e) {
// try to handle SsdkUnsupportedException
if (processUnsupportedException(e) == true) {
return;
}
} catch (Exception e1) {
e1.printStackTrace();
/*
* Your application can not use Samsung Accessory SDK. Your application should work smoothly
* without using this SDK, or you may want to notify user and close your application gracefully
* (release resources, stop Service threads, close UI thread, etc.)
*/
stopSelf();
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
protected void onFindPeerAgentsResponse(SAPeerAgent[] peerAgents, int result) {
Log.d(TAG, "onFindPeerAgentResponse : result =" + result);
}
@Override
protected void onServiceConnectionRequested(SAPeerAgent peerAgent) {
if (peerAgent != null) {
Toast.makeText(getBaseContext(), R.string.ConnectionAcceptedMsg, Toast.LENGTH_SHORT).show();
acceptServiceConnectionRequest(peerAgent);
}
}
@Override
protected void onServiceConnectionResponse(SAPeerAgent peerAgent, SASocket socket, int result) {
if (result == SAAgent.CONNECTION_SUCCESS) {
if (socket != null) {
mConnectionHandler = (ServiceConnection) socket;
}
} else if (result == SAAgent.CONNECTION_ALREADY_EXIST) {
Log.e(TAG, "onServiceConnectionResponse, CONNECTION_ALREADY_EXIST");
}
}
@Override
protected void onAuthenticationResponse(SAPeerAgent peerAgent, SAAuthenticationToken authToken, int error) {
/*
* The authenticatePeerAgent(peerAgent) API may not be working properly depending on the firmware
* version of accessory device. Please refer to another sample application for Security.
*/
}
@Override
protected void onError(SAPeerAgent peerAgent, String errorMessage, int errorCode) {
super.onError(peerAgent, errorMessage, errorCode);
}
private boolean processUnsupportedException(SsdkUnsupportedException e) {
e.printStackTrace();
int errType = e.getType();
if (errType == SsdkUnsupportedException.VENDOR_NOT_SUPPORTED
|| errType == SsdkUnsupportedException.DEVICE_NOT_SUPPORTED) {
/*
* Your application can not use Samsung Accessory SDK. You application should work smoothly
* without using this SDK, or you may want to notify user and close your app gracefully (release
* resources, stop Service threads, close UI thread, etc.)
*/
stopSelf();
} else if (errType == SsdkUnsupportedException.LIBRARY_NOT_INSTALLED) {
Log.e(TAG, "You need to install Samsung Accessory SDK to use this application.");
} else if (errType == SsdkUnsupportedException.LIBRARY_UPDATE_IS_REQUIRED) {
Log.e(TAG, "You need to update Samsung Accessory SDK to use this application.");
} else if (errType == SsdkUnsupportedException.LIBRARY_UPDATE_IS_RECOMMENDED) {
Log.e(TAG, "We recommend that you update your Samsung Accessory SDK before using this application.");
return false;
}
return true;
}
public class LocalBinder extends Binder {
public ProviderService getService() {
return ProviderService.this;
}
}
public class ServiceConnection extends SASocket {
public ServiceConnection() {
super(ServiceConnection.class.getName());
}
@Override
public void onError(int channelId, String errorMessage, int errorCode) {
}
@Override
public void onReceive(int channelId, byte[] data) {
if (mConnectionHandler == null) {
return;
}
Calendar calendar = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd aa hh:mm:ss.SSS");
String timeStr = " " + dateFormat.format(calendar.getTime());
String strToUpdateUI = new String(data);
final String message = strToUpdateUI.concat(timeStr);
new Thread(new Runnable() {
public void run() {
try {
mConnectionHandler.send(getServiceChannelId(0), message.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
@Override
protected void onServiceConnectionLost(int reason) {
mConnectionHandler = null;
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getBaseContext(), R.string.ConnectionTerminateddMsg, Toast.LENGTH_SHORT).show();
}
});
}
}
}
package com.samsung.android.sdk.accessory.example.helloaccessory.provider;
导入java.io.IOException;
导入java.text.simpleDataFormat;
导入java.util.Calendar;
导入java.util.GregorianCalendar;
导入android.content.Intent;
导入android.os.Binder;
导入android.os.Handler;
导入android.os.IBinder;
导入android.widget.Toast;
导入android.util.Log;
导入com.samsung.android.sdk.ssdk不支持异常;
导入com.samsung.android.sdk.accessory.*;
公共类ProviderService扩展了SaaAgent{
私有静态最终字符串TAG=“HelloAccessory(P)”;
私有静态最终类SASOCKET_Class=ServiceConnection.Class;
private final IBinder mBinder=new LocalBinder();
私有ServiceConnection mConnectionHandler=null;
Handler mHandler=新的Handler();
公共供应商服务(){
超级(标签,SASOCKET_类);
}
@凌驾
public void onCreate(){
super.onCreate();
SA mAccessory=新SA();
试一试{
mAccessory.initialize(这个);
}捕获(SsdkUnsupportedException){
//尝试处理SsdkUnsupportedException
if(processUnsupportedException(e)==true){
回来
}
}捕获(异常e1){
e1.printStackTrace();
/*
*您的应用程序无法使用三星附件SDK。您的应用程序应能顺利运行
*不使用此SDK,或者您可能希望通知用户并优雅地关闭应用程序
*(释放资源、停止服务线程、关闭UI线程等)
*/
stopSelf();
}
}
@凌驾
公共IBinder onBind(意向){
返回mBinder;
}
@凌驾
受保护的void onFindPeeragents响应(SAPeerAgent[]peerAgents,int结果){
Log.d(标记“onfindpeeragentreponse:result=“+result”);
}
@凌驾
请求的服务连接上的受保护无效(SAPeerAgent对等连接){
if(peerAgent!=null){
Toast.makeText(getBaseContext(),R.string.connectionAcceptedMg,Toast.LENGTH_SHORT).show();
acceptServiceConnectionRequest(对等连接);
}
}
@凌驾
受保护的void onServiceConnectionResponse(SAPeerAgent对等代理、SASocket套接字、int结果){
if(result==SAAgent.CONNECTION\u SUCCESS){
if(套接字!=null){
mConnectionHandler=(ServiceConnection)套接字;
}
}else if(result==SAAgent.CONNECTION\u已存在){
Log.e(标记“onServiceConnectionResponse,连接已经存在”);
}
}
@凌驾
AuthenticationResponse上受保护的void(SAPeerAgent对等代理、SAAuthenticationToken authToken、int错误){
/*
*authenticatePeerAgent(peerAgent)API可能无法正常工作,具体取决于固件
*附件设备的版本。有关安全性,请参阅另一个示例应用程序。
*/
}
@凌驾
受保护的void onError(SAPeerAgent对等代理、字符串错误消息、int错误代码){
super.onError(peerAgent、errorMessage、errorCode);
}
私有布尔进程UnsupportedException(SsdkUnsupportedException e){
e、 printStackTrace();
int errType=e.getType();
if(errType==ssdkunstupportedException.VENDOR\u不受支持
||errType==ssdkunstupportedException.DEVICE(不支持){
/*
*你的应用程序不能使用三星附件SDK。你的应用程序应该工作顺利
*不使用此SDK,或者您可能希望通知用户并优雅地关闭您的应用程序(发布版)
*资源、停止服务线程、关闭UI线程等)
*/
stopSelf();
}else if(errType==ssdkunstupportedException.LIBRARY\u未安装){
Log.e(标记“您需要安装三星附件SDK才能使用此应用程序”);
}else if(errType==ssdkunstupportedException.LIBRARY\u UPDATE\u是必需的){
Log.e(标记“您需要更新三星附件SDK才能使用此应用程序”);
}else if(errType==ssdkunstupportedException.LIBRARY\u UPDATE\u推荐){
Log.e(标记“我们建议您在使用此应用程序之前更新三星附件SDK”);
返回false;
}
返回true;
}
公共类LocalBinder扩展了Binder{
公共ProviderService getService(){
返回ProviderService.this;
}
}
公共类ServiceConnection扩展了SASocket{
公共服务连接(){
super(ServiceConnection.class.getName());
}
@凌驾
public void onError(int channelId、String errorMessage、int errorCode){
}
@凌驾
公共vo