Is it possible to load a class without installing the APK? - android

I would like to download an apk file from my application and store it in device memory and then load some class from the downloaded APK. Is this possible? I read it is only possible when we install the apk but is there no way to do this without installing the apk?

To create an activity without a UI it makes sense to exit out of the Activity quickly and go to a Service (http://developer.android.com/guide/topics/fundamentals/services.html).
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
final String token = retrieveToken();
username = retrieveUsername();
if (!isEmpty(token) && !isEmpty(username)) {
Intent i = new Intent();
i.setClassName("net.mine", "net.mine.Service");
startService(i);
conn = new RemoteServiceConnection();
bindService(i, conn, Context.BIND_AUTO_CREATE);
finish();
}
setContentView(R.layout.main);
This isn't a complete example as I have some functions I didn't inline, but the basic idea should be here.
Basically, just start up and then go to an Android Service, as that is what should be used to run in the background, and then if you need to start up an Activity it can be done from there.

Related

Get parameters from android to unity

I have a problem, i want to send a parameter (int) from an app of build in android studio and receive it in an app build it in unity.
The apps work like this, you open the android app, press a botom and open the second app, i send and intent when i open the unity app but idkhow to recieve the param.
I know that are some questions about this but didn't work or maybe idk how to implement it to my code.
This is how i send the param
Java app
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.bodyar");
if(user!=null){
launchIntent.putExtra(Constant.TYPE,user.getLearningStyleId());
}else{
launchIntent.putExtra(Constant.TYPE,Constant.VISUAL);
}
startActivity(launchIntent);
but i dont know how to receive the value. I tried the stuff of UnityPlayer.UnitySendMessage(), but u just get an error from that
And the funciton of the Script that it´s attached to GameObjectUI is this
public void TipoTest(string token){
prueba.text = token;
}
And when i export the unity project to android, in the method OnCreate I recieve the params like this
public class UnityPlayerActivity extends Activity {
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Setup activity layout
#Override protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
#Override protected void onNewIntent(Intent intent) {
// To support deep linking, we need to make sure that the client can get access to
// the last sent intent. The clients access this through a JNI api that allows them
// to get the intent set on launch. To update that after launch we have to manually
// replace the intent with the one caught here.
setIntent(intent);
}
}
And It works but idk how to pass the variable to unity script

How to use firefox focus to open a url when use intent?

I tried write a app for open a special url use "intent". But I want to use firefox focus to open it. How to use firefox focus to open a url when use intent? And I don't know the component name of firefox focus.
public class MainActivity_EmbedLink extends AppCompatActivity {
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main__embed_link);
String url = "http://123.com ";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
finish();
}
}
I managed to get it to work with Tasker following the screenshot.
I am sure you can convert the same to code.

All apps associated with this action have been disabled, blocked, or are not installed Storage Access Framework

In my application I am trying to get MS-Word and PDF files through Storage Access Framework which works well on some devices I've tested upon but on Samsung note 4 API 6 I am getting an error
All apps associated with this action have been disabled, blocked, or
are not installed
Code:
warantyButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf,application/msword");
Intent i = Intent.createChooser(intent, "File");
getActivity().startActivityForResult(i, FILE_REQ_CODE);
}
});
I'm not sure if this is directly related to your issue, but it is related to an issue I personally had with this error when using Intents (Incorrectly). I have received this error when attempting to declare an Intent globally. For example:
public class MyClass{
// Class Variables (BAD)
private Intent someActivity = new Intent(this, SomeClass.class);
#Override
protected void onCreate(Bundle savedInstanceState){
// Some Code
}
}
Then, I found that this issue was resolved when I did this:
public class MyClass{
// Class Variables (Not Bad)
private Intent someActivity;
#Override
protected void onCreate(Bundle savedInstanceState){
someActivity = new Intent(this, SomeClass.class);
}
}
If this doesn't help you in your specific situation, I hope this helps someone at some point.
When debugging to find the reason behind this problem, I couldn't see any note of the Toast that generated the text "All apps associated with this action have been disabled, blocked, or are not installed." There was no trace of this being an "error." It seems to me more of an OS-handled exception for incorrect usage of Intents.
Since setType() method of Intent takes one argument as String i.e MIME type and its compulsary because based on the MIME type requested android system finds all actions that are supported.
For example if you want to choose any type of content then you can simply write setType("*/*").

Share activity context among intents

I have 3 screens in my app, each of which are in their own classes. When the app launches, my Driver class sets up some GUI elements, and then launches the first Intent.
I have a separate GUI class (which Driver invokes) which handles everything from menu's to dialog boxes. Previously my app didn't use Intents so I could pass the activity/context from Driver to Gui in its constructor as an object of type Activity and as a result could define layouts etc like LinearLayout ll = new LinearLayout(activity) and everything would be operating in the same activity/context.
Since I've moved to using intents, each Activity/Class has its own context, thus the previous dialogs and popup boxes from the Gui class are in the background and not running. I get an error saying android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy#406629a0 is not valid; is your activity running? when I click on a button to launch a dialog.
To me, this indicates the new Intents have taken over the foreground and the objects from the previous context are out of scope.
So, is there a way I can still pass the same context through to the new Intents so I can still access these shared dialogs? Or will I have to bring the code into each class (duplicate code)?
In case thats a bit hard to understand, here is some basic source code:
public class Driver extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Gui display = new Gui(this);
display.showScreen();
}
}
/////////////GUI.java///////////////////////
public class Gui
{
private Activity activity;
private Gui()
{}
public Gui(Activity _activity)//,Context _context)
{
this();
activity = _activity;
}
public void showScreen()
{
if(isLocationMode())
{
Intent i = new Intent(activity,LocationScreen.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(i);
//locatScreen = new LocationScreen(activity);
//mainLayout.addView(locatScreen.getView());
}
else if (isManageMode())
{
Intent i = new Intent(activity,ManageScreen.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(i);
//manageScreen = new ManageScreen(activity);
//mainLayout.addView(manageScreen.getView());
}
else if (isForwardMode())
{
Intent i = new Intent(activity,ForwardScreen.class);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(i);
//forwardScreen = new ForwardScreen(activity);
//mainLayout.addView(forwardScreen.getView());
}
}
}
Have a setContext(Activity _activity) method in your Gui and call this in the onCreate of each activity?

Check for 3rd party app, open-if not install

I am working on a class that when selected by the user should open an application. If that application is not installed they will click the "Find it" button and install it.
Here is what I have so far
public class calc extends Activity {
static final String MARKET_SEARCH_Q_PNAME_PROVIDER = "market://search?q=pname:com.packagename.package";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getpft);
setTitle("Install Marine PFT?");
((Button) findViewById(R.id.Ok)).setOnClickListener(new Openpft());
((Button) findViewById(R.id.FindIt)).setOnClickListener(new FindZxingOnclickListener());
}
public class FindZxingOnclickListener implements OnClickListener {
public void onClick(View v) {
Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
marketLaunch.setData(Uri.parse(MARKET_SEARCH_Q_PNAME_PROVIDER));
startActivity(marketLaunch);
}}
};
So far the page opens up and it searches correctly for the app. However now that the app is downloaded I need to automatically skip this screen and just open that app. How is that done?
Somehow, you are launching that app. Presumably, you have an Intent that you are passing to startActivity() that does this. If so, you have two choices:
Just call startActivity() and route to your above code in the ActivityNotFoundException catch block
Use PackageManager and queryIntentActivities() to see if anything will respond to your Intent, and if not, route to your above code without calling startActivity() first

Categories

Resources