- Home /
android time cheat plugin problem with broadcastreceiver
Hi, i want to make an android plugin wich use android.intent.action.TIME_SET so when user changing the time i can tell he cheated ! so here is android java class :
package com.mahdi.detecttime;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.unity3d.player.UnityPlayer;
public class MahdiBridge extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
UnityPlayer.UnitySendMessage("TimeDetector", "OnTchanged", "yes" );
}
}
_ and here is the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="@style/UnityThemeSelector"
android:icon="@drawable/app_icon"
android:label="@string/app_name">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<receiver android:name="com.mahdi.detecttime.MahdiBridge">
<intent-filter>
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
</application>
</manifest>
__ and in unity i have a gameobject call "TimeDetector" and a class call "onTimeChanged" and a public function call "OnTchanged" and when OnTchanged function is called i know user is cheating ! and everything is working (when i change time in device that function is called) but its only working if app is running and when i close the unity app in the logcat i get this message: "Unity: Native libraries not loaded - dropping message for TimeDetector.OnTchanged" its mean the broadcastreceiver has been called but unity is not running to run that function. so how can i fix this i want to when broadcastreceiver is called its wait until i start unity app then its run the function so how can i do this thanks.
I don't think that this forum is suitable for that kind of issue. sounds to me as if that's a more android in general problem.
the problem is we can not call unity function from android broadcast receiver when app is not running. so is it not a unity problem ?
no, because it's not running. this means there must be some other mechanism on the OS to queue that or something and if that mechanism exists it's for more than just Unity apps.
Answer by generalhak · Jul 01, 2018 at 03:08 PM
i fix the problem with just save the broadcast in a SharedPreferences and then when starting unity i just start check that value and now i can tell if user changing the time. thanks