I'm trying to create a launcher/homescreen. The application crashes on restart.
Debugger displays : "Unable to get provider mono.MonoRuntimeProvider". You have to wait a long time before the MonoRuntimeProvider is started, and then the app works. Any ideas to resolve this problem?
Activity1.cs
[Activity(Label = "Test application", MainLauncher = true, Icon = "#drawable/icon")]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
try
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.NoTitle);
Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
}
catch (Exception ex)
{
Log.Error("TestError","Test Error:" + ex.Message);
}
//
}
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="Test.AndroidMono" android:versionCode="1" android:versionName="test">
<application android:label="Test AndroidMono" >
<activity android:name="monoandroidapplication2.Activity1"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.CATEGORY_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
Find the solution:
MonoRuntimeProvider is required for debugging. Once I made a release, it worked perfectly...
Related
I'm recieving the above error when deploying my Xamarin Android application using Visual Studio in debug mode, the compile process completes fine but I can't deploy.
The app runs fine in Android 8.1.0 but not in any other lower version.
Error:
>Project "Empresa1.SMPay.Target.Droid.csproj" (Install target(s)):
>C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\zipalign.exe 4 "E:\HenkoTI\Empresa1\SMPay\src\mpay\app\Empresa1.SMPay.Target.Droid\obj\Debug\android\bin\br.com.henkoti.empresaum.smpay.apk" "bin\Debug\\br.com.henkoti.empresaum.smpay-Signed.apk"
>C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\apksigner.BAT sign --ks "C:\Users\rodri\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 18 --max-sdk-version 27 bin\Debug\br.com.henkoti.empresaum.smpay-Signed.apk
>Unexpected install output: pkg: /data/local/tmp/br.com.henkoti.empresaum.smpay-Signed.apk
>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
>
> at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
> at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
> at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
> at System.Threading.Tasks.Task.Execute()
>Done building project "Empresa1.SMPay.Target.Droid.csproj".
>Build succeeded.
>Unexpected install output: pkg: /data/local/tmp/br.com.henkoti.empresaum.smpay-Signed.apk
>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
>
> at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
> at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
> at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
> at System.Threading.Tasks.Task.Execute()
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.henkoti.empresaum.smpay" android:installLocation="auto" android:versionName="20181108.0" android:versionCode="4">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
<application android:icon="#drawable/ic_launcher" android:theme="#style/MainTheme" android:label="SIGO" android:allowBackup="true" android:fullBackupContent="#xml/my_backup_rules">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
</provider>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id" />
</application>
</manifest>
Compiled AndroidManifest - Obj Folder
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.henkoti.empresaum.smpay" android:installLocation="auto" android:versionName="20181108.0" android:versionCode="4">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.location.network" />
<application android:icon="#drawable/ic_launcher" android:theme="#style/MainTheme" android:label="SIGO" android:allowBackup="true" android:fullBackupContent="#xml/my_backup_rules" android:name="md5eaa617bc1882abd453813d82db97fb16.MainApplication" android:debuggable="true">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="br.com.henkoti.empresaum.smpay.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
</provider>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id" />
<service android:enabled="true" android:exported="true" android:name="Empresa1.SMPay.HCECardService" android:permission="android.permission.BIND_NFC_SERVICE">
<meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="#xml/aid_list" />
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<activity android:configChanges="orientation|screenSize" android:launchMode="standard" android:screenOrientation="portrait" android:theme="#style/MainTheme" android:name="md5eaa617bc1882abd453813d82db97fb16.MainActivity" />
<activity android:icon="#drawable/ic_launcher" android:label="SIGO" android:noHistory="true" android:screenOrientation="portrait" android:theme="#style/SplashTheme" android:name="md5eaa617bc1882abd453813d82db97fb16.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:enabled="true" android:label="Connectivity Plugin Broadcast Receiver" android:name="md592d74be4bac08a7af63848ae15d2f86e.ConnectivityChangeBroadcastReceiver" />
<activity android:configChanges="orientation|screenSize" android:name="md5cf4be63b82b35b5ba951617c70f88a94.FilePickerActivity" />
<activity android:configChanges="orientation|screenSize" android:name="md591f613f6733d8b6e91e929a922515c0e.MediaPickerActivity" />
<receiver android:enabled="true" android:exported="false" android:name="md5b60ffeb829f638581ab2bb9b1a7f4f3f.PowerSaveModeBroadcastReceiver" />
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="br.com.henkoti.empresaum.smpay.mono.MonoRuntimeProvider.__mono_init__" />
<!--suppress ExportedReceiver-->
<receiver android:name="mono.android.Seppuku">
<intent-filter>
<action android:name="mono.android.intent.action.SEPPUKU" />
<category android:name="mono.android.intent.category.SEPPUKU.br.com.henkoti.empresaum.smpay" />
</intent-filter>
</receiver>
<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="#style/com_facebook_activity_theme" />
<activity android:name="com.facebook.CustomTabMainActivity" />
<!--
The initialization ContentProvider will call FacebookSdk.sdkInitialize automatically
with the application context. This config is merged in with the host app's manifest,
but there can only be one provider with the same authority activated at any given
point; so if the end user has two or more different apps that use Facebook SDK, only the
first one will be able to use the provider. To work around this problem, we use the
following placeholder in the authority to identify each host application as if it was
a completely different provider.
-->
<provider android:name="com.facebook.internal.FacebookInitProvider" android:authorities="br.com.henkoti.empresaum.smpay.FacebookInitProvider" android:exported="false" />
<activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar" android:excludeFromRecents="true" android:exported="false" />
<!--Service handling Google Sign-In user revocation. For apps that do not integrate with
Google Sign-In, this service will never be started.-->
<service android:name="com.google.android.gms.auth.api.signin.RevocationBoundService" android:exported="true" android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar" android:exported="false" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
</manifest>
SplashActivity
using Android.OS;
using Android.App;
using Android.Content.PM;
namespace Empresa1.SMPay.Target.Droid
{
[Activity(Label = "SIGO",
Icon = "#drawable/ic_launcher",
Theme = "#style/SplashTheme",
MainLauncher = true,
NoHistory = true,
ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.StartActivity(typeof(MainActivity));
}
}
}
MainActivity
using System.Net;
using Android.App;
using Android.OS;
using Android.Content;
using Android.Content.PM;
using Xamarin.Forms;
using Xamarin.Facebook;
using Plugin.Toasts;
using Plugin.Permissions;
using Acr.UserDialogs;
using Autofac;
using Empresa1.SMPay.Application;
using Empresa1.SMPay.Application.IoC;
using Empresa1.SMPay.Target.Droid.Services;
using Empresa1.SMPay.Infra.Platform.Services;
using Android.Gms.Auth.Api;
using InteractiveAlert;
using Xfx;
using FFImageLoading.Forms.Droid;
namespace Empresa1.SMPay.Target.Droid
{
[Activity(Theme = "#style/MainTheme",
LaunchMode = LaunchMode.Multiple,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
// Facebook
FacebookSdk.SdkInitialize(this.ApplicationContext);
global::Xamarin.Forms.Forms.Init(this, bundle);
// Calendar
XamForms.Controls.Droid.Calendar.Init();
// SSL
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
// Permissions
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
// Toast
DependencyService.Register<ToastNotification>();
ToastNotification.Init(this);
// Dialogs
UserDialogs.Init(() => (Activity)Forms.Context);
InteractiveAlerts.Init(() => this);
// XfxControls
XfxControls.Init();
// FFImageLoading
CachedImageRenderer.Init(true);
LoadApplication(new Empresa1.SMPay.Application.App(new Setup(this.ApplicationContext, this, TelephonyService)));
}
protected override void OnStart()
{
base.OnStart();
}
protected override void OnResume()
{
base.OnResume();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnStop()
{
base.OnStop();
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
//base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (App.FacebookSinging)
{
// facebook auth
var facebookService = IoCContainer.Container.Resolve<IFacebookService>();
if (facebookService != null)
{
(facebookService as DroidFacebookService)._callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
}
}
else if (App.GoogleSinging)
{
// google auth
if (requestCode == 1)
{
var result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
DroidGoogleService.Instance.OnAuthCompleted(result); // TODO
}
}
}
}
}
Anyone here knows, what do i need to do?
I took some screenshots to add here:
Finally I was able to solve the problem, the solution was to change the prefix name of the HCECardService to lowecase.
Before: Empresa1.SMPay.HCECardService
After: empresa1.smpay.HCECardService
[Service(Exported = true, Enabled = true, Permission = "android.permission.BIND_NFC_SERVICE", Name = "empresa1.smpay.HCECardService"), IntentFilter(new[] { "android.nfc.cardemulation.action.HOST_APDU_SERVICE" }, Categories = new[] { "android.intent.category.DEFAULT" }),
MetaData("android.nfc.cardemulation.host_apdu_service", Resource = "#xml/aid_list")]
public class HCECardService : HostApduService
{ ... }
This is my service:
public class KeepAliveService extends Service {
Alarm alarm = new Alarm();
public void onCreate()
{
Log.i("","KEEPALIVE onCreate");
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onCreate start command");
return START_STICKY;
}
#Override
public void onStart(Intent intent, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onStart");
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
}
I have it declared like this in my manifest, after my :
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:icon="#drawable/ic_launcher"
android:name="com.vidyo.vidyomod.VidyoModApplication"
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:allowBackup="true"
android:supportsRtl="true"
tools:replace="android:icon">
<activity
android:name="com.vidyo.vidyomod.activities.BaseActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vidyocore" />
</intent-filter>
</activity>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:process=":remote" android:name="com.vidyo.vidyomod.utils.Alarm"></receiver>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
And on my onCreate of my BaseActivity, I do this:
Intent i= new Intent(BaseActivity.this, KeepAliveService.class);
startService(i);
I debugged, my breakpoint at startService does stop, but OnCreate is not called. why?
You have to put your Service and your BroadcastReceiver inside your application tag:
<application>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
Also, you are starting service in a different process.
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
The debugger is attached to your main process. When the new one starts, it has no debugger attached, so it will ignore your breakpoints.
Im sending a push message with a custom action but in the onPushReceive the action that I get is com.parse.push.intent.RECEIVE instead of com.hellboy.beat.STATUS_DONE
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hellboy.beat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<!-- permission required for Notification -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- permission required to Send SMS -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- permission required to get Location & Number -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- permission required to Vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- permission required to use Parse -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- permission required to use Parse Push -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.parse.starter.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hellboy.beat.permission.C2D_MESSAGE" />
<application
android:name="com.hellboy.beat.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hellboy.beat.main.Activity_main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.hellboy.beat.login.Activity_login" />
<activity android:name="com.hellboy.beat.requests.Activity_requests" />
<activity android:name="com.hellboy.beat.settings.Activity_settings" />
<!-- Register the Notification Receiver -->
<service android:name="com.parse.PushService" />
<!-- Regular Push Notification -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
<!-- Our Reciver -->
<receiver
android:name="com.hellboy.beat.PushRec"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.hellboy.beat" />
</intent-filter>
</receiver>
</application>
</manifest>
PushRec.java
public class PushRec extends ParsePushBroadcastReceiver
{
private static final String TAG = "BEAT_PUSHREC";
Context context;
#Override
public void onPushReceive(Context context, Intent intent)
{
this.context = context;
Log.i(TAG, "Receiver");
if (intent == null)
{
Log.i(TAG, "Receiver intent null");
}else
{
Log.i(TAG, "Receiver intent not null");
String action = intent.getAction();
Log.i(TAG, "got action " + action );
if (action.equals("com.hellboy.beat.STATUS_DONE"))
{
//DOES NOT COME OVER HERE
}
}
}
}
Sending-Push:
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", subscriberQuery);
JSONObject obj=null;
obj =new JSONObject();
try
{
obj.put("action","com.hellboy.beat.STATUS_DONE");
obj.put("statusdone_message" , message);
} catch (JSONException e1) {
e1.printStackTrace();
}
//TODO move this to the 'cloud'
ParsePush pPush = new ParsePush();
pPush.setQuery(pushQuery);
pPush.setData(obj);
pPush.sendInBackground();
NOTE: My understanding is I'm making a mistake in the Manfiest since the notification arrives, but the wrong action is called
You can override onReceive method to dispatch your custom action.
#Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
switch (intentAction) {
case "com.hellboy.beat.STATUS_DONE":
onPushReceive(context, intent);
break;
case ACTION_PUSH_DELETE:
onPushDismiss(context, intent);
break;
case ACTION_PUSH_OPEN:
onPushOpen(context, intent);
break;
}
}
https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParsePushBroadcastReceiver.java
The error was in the Manifest; ParseBroadcastReceiver should be ParsePushBroadcastReceiver
Snippet:
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.hellboy.beat.PushRec" >
<intent-filter>
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
And remove this from the Manifest:
<!-- Regular Push Notification -->
<!-- REMOVE THIS -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
Also in the Receiver:
public class PushRec extends ParsePushBroadcastReceiver
{
}
becomes
public class PushRec extends BroadcastReceiver
{
}
I just updated the latest Parse SDK (1.11.0) and now I'm not receiving push notifications. I am able to register successfully and can see on the parse site that that my "developer" channel has been subscribed but pushes never get sent and I get this error:
PPNS - Outdated device - The records on this installation are
outdated, the user might have uninstalled the app.
Can someone please take a look at my code and see if you notice anything incorrect?
public class LSIApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "********", "********");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("developer", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
}
}`
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="${applicationId}.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="${applicationId}.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<permission android:protectionLevel="signature"
android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:name=".LSIApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="********" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name=".startup.PushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
Note: The ${applicationId} is 'com.broker.schlisimobile.dev' and/or 'com.broker.schlisimobile' depending on whether it's a production or developer build.
Here is my custom PushBroadcastReceiver class:
public class PushBroadcastReceiver extends ParsePushBroadcastReceiver {
#Override
protected void onPushOpen(Context context, Intent intent) {
if ( storyJSONExists(intent) ) {
if (!DataController.getInstance().getCurrentUser().isGuestUser() ) {
Intent i = new Intent(context, PushLoadingActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Intent i = new Intent(context, HomeActivity.class);
i.putExtra("promptForLogin", true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
} else {
Intent i = new Intent(context, HomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtras(i);
context.startActivity(i);
}
}
private boolean storyJSONExists(Intent intent) {
try {
String jsonString = intent.getExtras().getString("com.parse.Data");
JSONObject json = new JSONObject(jsonString);
if ( json.has("postID") ) {
return true;
}
} catch (JSONException jsonE) {
jsonE.printStackTrace();
}
return false;
}
}
In your manifest.xml comment/delete below code,
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
then add below code in manifest.xml
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--IMPORTANT: Change "com.parse.starter" to match your app's package name.-->
<category android:name="your_application_id" />
</intent-filter>
</receiver>
hope it works.
When user want to uninstall app from android device, I want user uninstall button click event for that application.
I am getting event of application is removed from device, but I want to show pop-up before application is removed. I am trying to achieve same like doing in 'App Lock' application.
Here is my code to get application removed event through broadcast receiver. But I am totally blank about uninstall button click or before pop-up click. Please guide me in right direction.
Thanks in advance.
public class MainActivity extends Activity {
CustomBroadcastReceiver mApplicationsReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mApplicationsReceiver=new CustomBroadcastReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
filter.addAction(Intent.ACTION_PACKAGE_VERIFIED);
filter.addAction(Intent.ACTION_PACKAGE_INSTALL);
filter.addAction(Intent.ACTION_PACKAGE_FIRST_LAUNCH);
filter.addAction(Intent.ACTION_DELETE);
filter.addAction(Intent.ACTION_DEFAULT);
filter.addDataScheme("package");
registerReceiver(mApplicationsReceiver, filter);
}
}
public class CustomBroadcastReceiver extends BroadcastReceiver {
/**
* This method captures the event when a package has been removed
*/
#Override
public void onReceive(Context context, Intent intent)
{
System.out.println("Hello from CustomBroadcastReceiver");
if (intent != null) {
String action = intent.getAction();
System.out.println("L1123 : "+action);
if (action.equals(intent.ACTION_PACKAGE_REMOVED)) {
//Log the event capture in the log file ...
System.out.println("The package has been removed");
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bits.uninstallappdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <receiver android:name=".CustomBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
</intent-filter>
</receiver> -->
</application>
</manifest>
Please try to get the top activity in the task via ActivityManager, and check if it is the uninstall activity.
Core code:
ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
String packageName = topActivity.getPackageName();
String className = topActivity.getClassName();
Log.v(TAG, "packageName" + packageName);
Log.v(TAG, "className" + className);
if ("com.android.packageinstaller".equals(packageName)
&& "com.android.packageinstaller.UninstallerActivity".equals(className)) {
//Do anything you want here
}
The following permissions which you are using are granted to system apps only. Make sure you have rooted device to allow such permissions.
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />