I've tried to hide app from launcher by adding and changing codes form the app source but failed every time.
Is it possible to hide a specific app from the launcher by editing Launcher3 source code? btw I'm working with AOSP build and want to integrate a 3rd party Open Source app into Settings, so that it can only be opened from Settings.
Looking through the original Launcher3 source code, you will find AppFilter file under /src/com/android/launcher3. From the file name itself, we know it’s a class to filter applications. There is a method called shouldShowApp, as its name suggest, is to consider if an application is needed to show.
Following this, AllAppsList.java uses this method in the add method. Clearly, when mAppFilter.shouldShowApp return false, it will return directly, making the applications to exclude from the application list, which will not be displayed.
Thus,
The easiest way is by simply change Line the line in AppFilter.java to be return !"com.google.android.gm".equals(app.getPackageName());, where this snippet of code will make sure that the package “com.google.android.gm” (Gmail) to be excluded from showing up in Launcher.
package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
public class AppFilter {
public static AppFilter newInstance(Context context) {
return Utilities.getOverrideObject(AppFilter.class, context,
R.string.app_filter_class);
}
public boolean shouldShowApp(ComponentName app) {
return !"com.google.android.gm".equals(app.getPackageName());
}
}
Hope this help.
Related
I'm modifying someone else's code to implement a new functionality and I can't do it without changing the return of one of the functions. As I've said, this is not my code, so I can't change a single line of code.
The function itself is the following:
package me.Mohamad82.MineableGems.Core;
public class DropReader {
...
public DropReader() {}
public CustomDrop readCustomDrop(ConfigurationSection section, String mined, #Nullable String sectionNumber) {
...
}
}
And I'm trying to do something like this:
package com.rogermiranda1000.mineit;
public class DropReader extends me.Mohamad82.MineableGems.Core.DropReader {
public DropReader() {
super();
}
#Override
public CustomDrop readCustomDrop(ConfigurationSection section, String mined, #Nullable String sectionNumber) {
CustomDrop drop = super.readCustomDrop(section, mined, sectionNumber);
if (drop != null) {...}
return drop;
}
}
The problem is that I have no idea where to start. I can't change their code to call the other object, and I can't change the function call either.
The object is created every time (inside the functions that uses DropReader) so Reflection won't work, and searching I found something named Javassist but it won't work if the class is already loaded. I should be able to load by code before, but even with that I don't know if I'm approaching to the problem correctly, what do you think?
Edit: I'll try to explain better the situation. There's a class named Commands that runs the command new DropReader().readCustomDrop(section, mined, sectionNumber). The problem is that if section.getString("mine") != null I need to change the readCustomDrop return (I need to add an aditional property).
I can't change Commands's code, nor DropReader. Commands MUST get the modified object.
Edit2: It should work on both Java 8 and 17.
Probably the best way to do this is Java Instrumentation, but it was too complex for me so I did the following (assuming you have the .jar, and the .jar it's not already loaded):
Open the .jar as a Zip using ZipFile class
Send the .java to ClassFileToJavaSourceDecompiler (from JD-Core) and decompile it
Change the .java code
Compile the new code running javac with Runtime.getRuntime().exec (note: you'll probably need to add the dependencies using -classpath)
Add the compiled .java to the .jar
Recently I have read about the "Create and monitor geofences" section at android developers official website and I found I can't use this section of code:
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Actually my android studio doesn't accept GeofenceErrorMessages class and I can't import with ALT+ENTER shortcut because the android studio doesn't recognize this class at all.
I managed to solve the problem with this code but I really want to know what happened with GeofenceErrorMessages class:
String errorMessage = GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode());
For GeofenceStatusCodes I used this import:
import com.google.android.gms.location.GeofenceStatusCodes;
QUESTION:
Do I need to import something in a project or GeofenceErrorMessages class is maybe deprecated?
I'm using the android studio 3.5.1 version with the newest update.
I ANSWERED ON THIS QUESTION BY MYSELF BECAUSE I THINK MANY DEVELOPER BEGINNERS WIIL SOMETIMES GET STUCK ON SILLY PROBLEMS LIKE THIS ONE.
I just have returned to this section and realized how silly I am.
GeofenceErrorMessages is not a predefined class provided by an android library it's actually class what you need to create by yourself and you can call it whatever you want.
I was confused because it is presented at official android developer website.
Here is an example code with GeofenceErrorMessages class (you can call it Stupid class if you want):
import android.content.Context;
import com.google.android.gms.location.GeofenceStatusCodes;
public class GeofenceErrorMessages {
public static String getErrorCode(Context context, int errorCode) {
switch (errorCode) {
case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
return "geofence_not_available";
case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
return "geofence_too_many_geofences";
case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
return "geofence_too_many_pending_intents";
default:
return "unknown_geofence_error";
}
}
}
You can see here GeofenceStatusCodes class is a predefined class from the android library and I used it to sort different types of geofence status.
I am making my first Android plugin by extending UnityPlayerNativeActivity. The package name is com.inno.myPlugin and that name is registered in Manifest.xml in Plugins/Android folder.
The class that extends "com.inno.myPlugin" is "MyClass".
The plugin is compiled as .jar file and it uses "AndroidJavaClass" and "AndroidJavaObject" on Unity side to call functions and is placed in Plugins/Android folder.
Each time I compile my example, on my android device, the app package name is always "com.inno.myPlugin". Even when I change the package name from Unity settings, the default package name is still the package name from the jar plugin which is "com.inno.myPlugin". The package name can only be renamed from the source code of the jar file...
I want to publish the plugin to Unity Asset store but I have a question that is bugging me.
If the package name "com.inno.myPlugin" is already used on the Android store, will this prevent the user of my plugin from uploading their app with this plugin?
How do I solve this problem of package naming?
This is one of the larger issues with Unity Android Plugins.
There's a few possibilities here. Use the below to get to the right answer
a) Does your plugin require that the Main Activity (i.e. Launcher activity) be "com.inno.myPlugin.MyClass"?
b) Do you override OnActivityResult in MyClass?
c) Neither of the above
If you answered yes to (a), then there's very little possibility that anyone but yourself can use this plugin, for a variety of reasons ranging from others being unable to tweak your code to conflicting packages.
If you answered yes to (b), then there's a decent possibility that others can use it, but they cannot use it if ANOTHER plugin requires that privilege as well
If you answered yes to (c) you should be good.
Easiest way to test it is to use your plugin in a fresh project, with a different package name, and check to see if it works.
Also, I'd advice that you stay away from extending UnityPlayerNativeActivity. The only reasons to extend UnityPlayerNativeActivity are
To get the currentActivity (i.e. UnityPlayer.currentActivity)
To use unitySendMessage
You can get both of these using reflection. currentActivity is a field, and unitySendMessage is a method. I won't go into detail here since it's not directly relevant to your question, but feel free to ping if you need some details.
Edit Adding some example code on request by the OP
Here's a sample plugin I made without extending UnityPlayerActivity or UnityPlayerNativeActivity. Note that I've just typed this straight in here, so there are probably errors in the code. One thing I know for sure is that the native code requires try-catch blocks, but any IDE should show up the error when you paste the code in.
Native Android Code
package com.myCompany.myProduct;
public class MyClass {
private Class<?> unityPlayerClass;
private Field unityCurrentActivity;
private Method unitySendMessage;
public void init () {
//Get the UnityPlayer class using Reflection
unityPlayerClass = Class.forName("com.unity3d.player.UnityPlayer");
//Get the currentActivity field
unityCurrentActivity= unityPlayerClass.getField("currentActivity");
//Get the UnitySendMessage method
unitySendMessage = unityPlayerClass.getMethod("UnitySendMessage", new Class [] { String.class, String.class, String.class } );
}
//Use this method to get UnityPlayer.currentActivity
public Activity currentActivity () {
Activity activity = (Activity) unityCurrentActivity.get(unityPlayerClass);
return activity;
}
public void unitySendMessageInvoke (String gameObject, String methodName, String param) {
//Invoke the UnitySendMessage Method
unitySendMessage.invoke(null, new Object[] { gameObject, methodName, param} );
}
public void makeToast (final String toastText, final int duration) {
currentActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getActivity(), toastText, duration).show();
}
});
}
}
Unity C# code
AndroidJavaObject myClass = null;
public void Init () {
if(myClass == null)
myClass = new AndroidJavaObject("com.myCompany.myProduct.MyClass");
if(myClass != null)
myClass.Call("init", new object[0]);
}
public void MakeToast (string toastText, int duration) {
if(myClass != null)
myClass.Call("makeToast", new object[] { toastText, duration } );
}
For the Manifest, change it to whatever you're calling the package name to be. Note that it DOES NOT have to match the package for the plugin! So, for example, here our plugin's package name is "com.myCompany.myProduct", you can use a package name like "com.someOtherCompany.someNewProduct"
How to test this plugin.
1. Add the native code above to "MyClass.java", and create a jar.
2. Copy this jar into Assets/Plugins/Android folder in your Unity Project.
3. Ensure that the package name is not the default package name in Unity
4. Copy the Unity C# code above into a new script
5. Put in some OnGUI code to call the "Init" & "MakeToast" methods in C#
Source - My expertise making plugins for Unity.
I'm trying to set up a tabbed interface for my application. I opened up the Support13Demos project distributed with the ADT. I am able to compile and run it. In order to work from it, I created a new project with a com.example.android.supportv13.app package and copied the appropriate files into it.
Then I copied over the referenced layouts and strings. All of my compilation errors are gone, but the application starts and immediately crashes with the error: Could not find class 'com.example.android.supportv13.app.ActionBarTabsPager$TabsAdapter', referenced from method com.example.android.supportv13.app.ActionBarTabsPager.onCreate.
The class ActionBarTabsPager does include a class TabsAdapter.
public class ActionBarTabsPager extends Activity {
…
public static class TabsAdapter extends FragmentPagerAdapter
implements ActionBar.TabListener, ViewPager.OnPageChangeListener { … }
}
I have tried cleaning the project and it didn't help. Private Libraries are also enabled.
i cant speak english well ,hope i can help u.
first right-click on your project--BuildPath--ConfigureBuildPath.
and then choose Order And ExPort
maybe some jar you need but you have not choose.
here's two picture(before modified and after modified)
before:http://img.my.csdn.net/uploads/201212/04/1354602396_3168.jpg;
after:http://img.my.csdn.net/uploads/201212/04/1354602436_2486.jpg
I added the android-support-v13.jar to the exports and removed Android Private Libraries.
I think I have misunderstood something about the Play 2 framework.
In my Application Controller I fetch a Company object from the DB
and I would like to make some operations on it in my view.
companyView.scala.html:
#(company: Company)
#main("Welcome to Play 2.0") {
<h1>#{company.name}</h1>
}
Application Controller:
package controllers;
import models.Company;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result company(String rest) {
Company company =
Company.find.where().ilike("restfulIdentifier.identifier", rest).findUnique();
return ok(companyView.render(company));
}
}
But return ok(companyView.render(company)); results in compilation error since companyView.render wants a string.
If I look at the forms sample application:
/**
* Handle the form submission.
*/
public static Result submit() {
Form<Contact> filledForm = contactForm.bindFromRequest();
if(filledForm.hasErrors()) {
return badRequest(form.render(filledForm));
} else {
Contact created = filledForm.get();
return ok(summary.render(created));
}
}
There is no problem with rendering an object. I guess that the solution is fairly simple and
that I have missed some crucial part of the documentation. Please explain this to me!
My steps in this case would be as follows:
Change the scala template, we hve to tell the scala templates the our Company belongs to the model class: (but also change to #company.name as suggested by Jordan.
#(company: models.Company)
#main("Welcome to Play 2.0") {
<h1>#company.name</h1>
}
run command play clean
Then run play debug ~run
By executing play debug ~run you will trigger to compile the the play application on each SAVE of one of your project files.
NOTE: The Play templates are basically functions. These functions needs to be compiled and everything used in these functions needs to be declared before use. Just as in regular Java development.
The fact that the your render object wants a string could be the result of:
#(company: Company) could not be resolved to the model Company.
The last compilation had a #(company: String)
Good luck!
I don't know if this will fix your problem or not but it's worth a try. Try removing changing:
#{company.name}
to:
#company.name