Android应用程序无法部署到虚拟设备
背景:
我正在用Xamarin.Forms创建一个内部移动应用程序,通过网络链接发布。 我已将Android和iOS启用并运行了几天,但请求是针对推送通知进行的。 我们决定与Pushwoosh一起提供这项服务。
我已经从pushwoosh复制了示例代码,并使用我们的软件包名称和密钥对其进行了修改,但出于某种原因,我收到了以下错误消息:
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.
我还应该注意Pushwoosh使用GCM,所以它也可能与此有关。
我试过的:
1.我的第一步显然是检查配置管理器。 它确实设置为Deploy并且它被设置为编译x86(其他问题的其他答案提到了该修复)
2.我确认MainActivity.cs文件中的活动是使用MainLauncher = true设置的。
3.根据其他问题/答案的建议,我从虚拟机器人中删除了该应用程序。 (实际上我完全重置了虚拟设备)。
4.正如一些GCM具体QA中所述,我已将我的软件包名称更改为全部小写。
我的相关代码:
[Activity(Label = "mobile", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new string[] { "company.MESSAGE" }, Categories = new string[] { "android.intent.category.DEFAULT" })]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
LocalMessageBroadcastReceiver mMessageReceiver;
LocalRegisterBroadcastReceiver mRegisterReceiver;
bool mBroadcastPush = true;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
mMessageReceiver = new LocalMessageBroadcastReceiver();
mMessageReceiver.activity = this;
mRegisterReceiver = new LocalRegisterBroadcastReceiver();
mRegisterReceiver.activity = this;
registerReceivers();
PushManager manager = PushManager.GetInstance(this);
manager.OnStartup(this);
//Register for push!
manager.RegisterForPushNotifications();
checkMessage(Intent);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
protected override void OnNewIntent(Intent intent)
{
checkMessage(intent);
}
public void checkMessage(Intent intent)
{
if (null != intent)
{
if (intent.HasExtra(PushManager.PushReceiveEvent))
{
doOnMessageReceive(intent.Extras.GetString(PushManager.PushReceiveEvent));
}
else if (intent.HasExtra(PushManager.RegisterEvent))
{
doOnRegistered(intent.Extras.GetString(PushManager.RegisterEvent));
}
else if (intent.HasExtra(PushManager.UnregisterEvent))
{
doOnUnregisteredError(intent.Extras.GetString(PushManager.UnregisterEvent));
}
else if (intent.HasExtra(PushManager.RegisterErrorEvent))
{
doOnRegisteredError(intent.Extras.GetString(PushManager.RegisterErrorEvent));
}
else if (intent.HasExtra(PushManager.UnregisterErrorEvent))
{
doOnUnregistered(intent.Extras.GetString(PushManager.UnregisterErrorEvent));
}
resetIntentValues();
}
}
public void doOnRegistered(String registrationId)
{
// code to run if device has succesfully registered
}
public void doOnRegisteredError(String errorId)
{
// code to run if device failed to register
}
public void doOnUnregistered(String registrationId)
{
// code to run if device has succesfully unregistered
}
public void doOnUnregisteredError(String errorId)
{
// code to run if device failed to unregister properly
}
public void doOnMessageReceive(String message)
{
// code to run when device receives notification
}
private void resetIntentValues()
{
Intent mainAppIntent = Intent;
if (mainAppIntent.HasExtra(PushManager.PushReceiveEvent))
{
mainAppIntent.RemoveExtra(PushManager.PushReceiveEvent);
}
else if (mainAppIntent.HasExtra(PushManager.RegisterEvent))
{
mainAppIntent.RemoveExtra(PushManager.RegisterEvent);
}
else if (mainAppIntent.HasExtra(PushManager.UnregisterEvent))
{
mainAppIntent.RemoveExtra(PushManager.UnregisterEvent);
}
else if (mainAppIntent.HasExtra(PushManager.RegisterErrorEvent))
{
mainAppIntent.RemoveExtra(PushManager.RegisterErrorEvent);
}
else if (mainAppIntent.HasExtra(PushManager.UnregisterErrorEvent))
{
mainAppIntent.RemoveExtra(PushManager.UnregisterErrorEvent);
}
Intent = mainAppIntent;
}
protected override void OnResume()
{
base.OnResume();
registerReceivers();
}
protected override void OnPause()
{
base.OnPause();
unregisterReceivers();
}
public void registerReceivers()
{
IntentFilter intentFilter = new IntentFilter(PackageName + ".action.PUSH_MESSAGE_RECEIVE");
if (mBroadcastPush)
{
RegisterReceiver(mMessageReceiver, intentFilter);
}
RegisterReceiver(mRegisterReceiver, new IntentFilter(PackageName + "." + PushManager.RegisterBroadCastAction));
}
public void unregisterReceivers()
{
UnregisterReceiver(mMessageReceiver);
UnregisterReceiver(mRegisterReceiver);
}
}
1
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.company.mobile" android:versionCode="1" android:versionName="1.9.8"> <!--GCM for Pushwoosh--> <permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" /> <uses-sdk android:minSdkVersion="15" /> <application android:label="Company Mobile" android:icon="@drawable/icon"> <meta-data android:name="com.google.android.gms.version" android:value="XXXXXXXX" /> <meta-data android:name="PW_APPID" android:value="XXXXX-XXXXX" /> <meta-data android:name="PW_PROJECT_ID" android:value="XXXXXXX-XXXXXX-XXXXXXX" /> <!--GCM--> <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.company.mobile" /> </intent-filter> </receiver> </application> </manifest>
我会承认我是android开发的新手(但不是.net或C#),所以这可能是相对明显的,但我不知所措。 我仔细研究了所有与此相关的问题,而且这些解决方案都没有帮助。 任何人都可以看到我做错了什么?
我相信在这两行中:
<permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />
应该将PACKAGE_NAME更改为您的实际软件包名称,您的情况为com.company.mobile
( <manifest>
元素中的package
属性)。
所以试试:
<permission android:name="com.company.mobile.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.mobile.permission.C2D_MESSAGE" />
链接地址: http://www.djcxy.com/p/92949.html