Service Intent not found Android plugin for Unity - java

I'm a bit new to developing for android, but I feel like I've scoured quite a few forums and tried everything I can find, to no avail.
At any rate, I'm trying to build an Android plugin for my Unity project, and essentially I'd like to start an Android service from Unity. It seems as though I have all my ducks in a row, but when it goes to start the service, I get the following error message on the Android Monitor LogCat:
Unable to start service Intent{ cmd=com.activetime.androidplugin/.services.StepsService } U=0; not found
My suspicion is that the "/" between "androidplugin" and ".services" isn't suppose to be there, which is why it can't find the service, but I can't for the life of me figure out why it's there. I've seen other similar issues out there but none of the solutions seem to work; perhaps there's some issue with merging manifests?
In any case, here's the Java class from Android Studio:
private static DBReader instance;
public DBReader(){
this.instance = this;
}
public static DBReader instance(){
if(instance == null){
instance = new DBReader();
}
return instance;
}
public void startStepsService(Activity unityActivity){
unityActivity.startService(new Intent(unityActivity, StepsService.class));
}
}
And then the C# in Unity:
void Start(){
#if UNITY_ANDROID
using(AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
}
using(AndroidJavaClass pluginClass = new AndroidJavaClass("com.activetime.androidplugin.DBReader")) {
if(pluginClass != null) {
databaseplugin = pluginClass.CallStatic<AndroidJavaObject>("instance");
databaseplugin.Call("startStepsService", activityContext);
}
}
#endif
}
And finally my Android Studio XML manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.activetime.androidplugin">
<application android:allowBackup="true" android:label="#string/app_name"
android:supportsRtl="true">
<service
android:name="com.activetime.androidplugin.services.StepsService">
</service>
</application>

Related

Android AIDL Service not executing

I use Android Automotive 11 environment, The below code actually also does not run under Regular Android 11 environemnt.
I Use the emulator that I've built from source Android 11 r35.
When I try to open the AIDL service I get the following error:
PermissionMonitor: NameNotFoundException
BroadcastQueue: Background execution not allowed
Here is the code:
public class MySimpService extends Service {
#Override
public void onCreate() {
super.onCreate();
}
#Nullable
#Override
public IBinder onBind(Intent intent) {
return new SimpServiceImp();
}
}
SimpServiceImp Class:
public class SimpServiceImp extends ISimp.Stub {
#Override
public int add(int a, int b) throws RemoteException {
return a+b;
}
#Override
public int sub(int a, int b) throws RemoteException {
return a-b;
}
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AIDLService" >
<service android:name=".MySimpService">
<intent-filter>
<action android:name="com.example.aidlservice.MySimpService"/>
</intent-filter>
</service>
</application>
There were a lot of basic Android issues which made this not work.
Part of it is Service had to have Notification to keep alive.
https://github.com/NewstHet/AndroidAidlClient
https://github.com/NewstHet/AndroidAIDLService
Github links contains working AIDL service using Android 11 API 30.

Why the Active Android Library reports this error = Before Android 4.1, ... would have incorrectly overridden the package-private method in Drawable

I use the Active Android Library, and every time I launch it, it will be displayed to me in the Logcat (Android Studio) , Error Type = Warning
Picture of the complete program error
I also want to know if this problem does not cause me a problem like Force Stop
The first two lines of program error (Warning):
Logcat
01-04 12:20:20.378 2166-2166/com.xxxx.yyyy W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-04 12:20:20.419 2166-2166/com.xxxx.yyyy I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.JobIntentService$JobServiceEngineImpl>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/app/job/JobServiceEngine;
...
AppController.java
public class AppController extends Application {
#Override
public void onCreate() {
super.onCreate();
ActiveAndroid.initialize(this);
}
}
...
AndroidManidest.xml
...
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#stylexxyyTheme"
tools:replace="android:icon">
<meta-data
android:name="AA_DB_NAME"
android:value="RestClient.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="1" />
<meta-data
android:name="AA_MODELS"
android:value="com.xxxx.yyyyy.model.DBUserInfo" />
...
DBUserInfo.java
#Table(name = "user_info")
public class DBUserInfo extends Model {
#Column(name = "user_id", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
public int user_id;
#Column(name = "name")
public String name;
public DBUserInfo() {
super();
}
public DBUserInfo(int user_id, String name) {
this.user_id = user_id;
this.name = name;
}
public static DBUserInfo getRandom() {
return new Select().from(DBUserInfo.class).executeSingle();
}
public static DBUserInfo getUserInfo() {
return new Select().from(DBUserInfo.class).executeSingle();
}
public List<DBUserInfo> getAll() {
return getMany(DBUserInfo.class, "name");
}
public static List<DBUserInfo> getAll() {
return new Select().from(DBUserInfo.class).orderBy("user_id ASC").execute();
}
}
I don't see any code related to your error. Did you share the code where the issue happens? Are you testing on a KitKat or previous device? KitKat and older have issues with Vector Graphics and you have to enable Vector Support as well as handle the vectorSupport tag on src on all images. So I have to assume you have drawable vectors in your project and have put these in the wrong folder or have not properly handled them based on that error, but without more details, that is only a speculation.
Keep in mind folders like no-dpi didn't exist in KitKat days as well as memory issues happen like crazy if not managed very meticulously.

Android: Suppress Warning on method call

I'm trying to do a method that checks for android permissions. But when I call it I have a Missing Permission warning.
Here is a simplification of my code:
public void lintTestMethod(){
if(isPermissionGranted()) {
requiresLocationPermission();
}
}
public boolean isPermissionGranted(){
return true;
}
#RequiresPermission(anyOf = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION})
public void requiresLocationPermission(){
}
I tried adding:
#SuppressLint("MissingPermission")
public boolean isPermissionGranted(){
return true;
}
But it's not working (I also tried using SuppressWarning).
Ideally, I would like to not have to modify the lintTestMethod method.
Does anyone have an idea on how to deal with that ?
I found a workaround to my problem by reading the lint code checking the permissions (Code). The solution is to name my method called 'isPermissionGranted' : 'check*Permission'. It's not really the solution I was looking for but it works. If anyone has a better way to do it I'm still interested.
Here is the interesting part of the code:
String name = node.astName().astValue();
if ((name.startsWith("check") || name.startsWith("enforce")) && name.endsWith("Permission")) {
mChecksPermission = true;
mDone = true;
}
You place suppression in wrong place:
Single statement suppression:
public void lintTestMethod(){
if(isPermissionGranted()) {
//noinspection MissingPermission
requiresLocationPermission();
}
}
Method range suppression:
#SuppressWarnings("MissingPermission")
public void lintTestMethod(){
if(isPermissionGranted()) {
requiresLocationPermission();
}
}
It can be done using Android Studio quick fix menu.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Add this in your AndroidManifest.xml file.

How to detect airplane mode on whole application in android [duplicate]

This question already has answers here:
How can one detect airplane mode on Android?
(13 answers)
Closed 7 years ago.
I am working on developing an Android app that will detect airplane mode throughout whole application. where to i add this code?
#SuppressWarnings("deprecation")
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAirplaneModeOn(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} else {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}
You can add this code where you want to detect whether connection is available.
for example:
#Override
public void onClick(View v) {
boolean isonair = myApp.isAirplaneModeOn(this);
Toast.makeText(this, "IS on AIR? " + isonair, Toast.LENGTH_LONG).show();
}
If you want to have an access for static function use them in Application class:
public class myApp extends Application {
public static function isAirplaneModeOn() {
...
}
}
in any activity use this access: myApp.isAirplaneModeOn()
do not forget update your AndroidManifest.xml:
<application
android:largeHeap="true"
android:name=".myApp" <<<<<<<<<<<<<<<<<<< this is your class name
android:icon="#drawable/somedrawable"
android:label="#string/app_alias"
android:theme="#style/AppTheme" >
Create a Interface like AirplaneModeManager whose Implementation extending broadcast receiver to get notified in the scenario when airplane mode is activated
you can use this code in Implementation to keep a track and use its methods in whole application to get the status !!

Android app not using Application class

I added the application to the Manifest and extended the class but something like onCreate won't get used in the class.
I don't know what I am doing wrong. Am I missing something? Isn't that all you should do for an application class you use?
Any help is much appreciated. I will probably just begin a new project instead and copy over the code.Manifest:
<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="#drawable/smalllogo"
android:label="#string/app_name"
>
Class:
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class MyApplication extends Application {
Tracker tracker;
synchronized public Tracker getDefaultTracker() {
if (tracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.setLocalDispatchPeriod(1800);
tracker = analytics.newTracker();
tracker.enableExceptionReporting(true);
tracker.enableAdvertisingIdCollection(true);
tracker.enableAutoActivityTracking(true);
}
return tracker;
}
}
And it is telling me getDefaultTracker() is never used...
All right, I feel really stupid. I have to access this method from another class it isn't automatically used. So I just called on it from another class and it works. Thank you all

Categories