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.
Related
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
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("*/*").
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.
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
I'm trying to launch an Activity when clicking a link inside a WebView component.
My Webview is loaded inside Main.java and I would like to launch SubActivity.java when clicking a link inside the Website which is in Main.java?
Also, how can I pass parameters to this activity?
Example: inspection://Project/1
"Inspection" is the name of my application, inspection is the Activity I would like to launch and 1 is the ID I would like to have.
You could use WebView's addJavaScriptInterface to allow JavaScript to control your application (in this case, to allow JavaScript to fire an Intent when a link is clicked).
To do this you need to pass a class instance to bind to JavaScript, this could be something like the following:
private final class JsInterface {
public void launchIntent(final String payload) {
Activity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
// use the payload if you want, attach as an extra, switch destination, etc.
Activity.this.startActivity(new Intent(Activity.this, SomeOtherActivity.class));
}
});
}
}
Then you add that to the WebView with something along these lines:
webView.addJavascriptInterface(js, "Android");
Then in JavaScript from the WebView you just use your new "Android" object's "launchIntent" method.
One option is to override the URL loading of the web view and pick up the click you want to launch the new activity. Check out the use of a subclassed WebViewClient in the docs:
http://developer.android.com/resources/tutorials/views/hello-webview.html
Another option is to bind your activity to a custom URL scheme. It's pretty common in doing client side OAuth, frequently through the browser instead of a WebView, but it should work similarly enough. There's a full example here:
https://github.com/brione/Brion-Learns-OAuth
Which shows how to bind the url scheme handler as well as handling getting launched via the Intent it generates (see onResume() in OAUTH.java).
First Add javascript method on your webpage's button onclick()
The function defined below..
function showAndroidToast(toast) {
AndroidFunction.showToast(toast);
}
Android Code is here for javascript Interface..
public class MyJavaScriptInterface {
Context mContext;
private Activity activity;
public MyJavaScriptInterface(Activity activiy) {
this.activity = activiy;
}
#JavascriptInterface
public void showToast(String toast){
Intent i=new Intent(getApplicationContext(), Subactivity.class);
i.putExtra("data", "tosecondActivity");
startActivity(i);
}