I am just starting off with Google Web Toolkit, coming from programming in Android. Since it's all java(ish) I expected it to be similar. In my app I have an entrypoint where the user will upload an excel file and hit submit. After they hit submit they should be taken to a new page where I will be displaying some information from the excel that they just uploaded.
In Android it would look something like
myAndroidBTN.setOnClickListener (new OnClickListener() {
public void onClick(View v) {
try {
final Intent myIntent = new Intent(this, NextClass.class));
startActivity(myIntent);
} catch (Exception e) { }
}
In the GWT App I have
Button btnSubmit = new Button("Submit");
btnSubmit.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
Documentation for GWT is doesn't seem to be anywhere near what it is for android so I can't find the right way to open a new java file. How should this be done?
EDIT
Some of you have miss-interpreted my question. I don't want to imply that I can build the equivalent of an android app in a browser with GWT, I just wanted to see the equivalent of an OnClick event taking you to a new page/section.
Look at Activities and Places.
https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
Related
I would like to open the Facebook app and go directly to a Facebook page when the user presses a button in my app.
How do I do that using the official Facebook SDK?
So far, all the solutions I've seen is fairly hacky, checking to see if the FB app is installed using Package Manager or something. This might become an issue in the future, given the precedent of Package Visibility.
Another solution relies on a list of unofficial URIs sourced from the decompiled Facebook APK, which can break at any time.
I have tried this code. It is work to open the facebook application
https://stackoverflow.com/a/52480045/14215175
try
{
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
#Override
public void run() {
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
}
}, 1000 * 2);
}
catch (Exception e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name>")));
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
}
if you want to intent to the specific profile / Group / Page , you need to change the code
fb://profile --> "fb://group" / "fb://page"
I am creating an android application wherein I have mentioned the phone number, email, website of the business similar to the screenshot of google maps as attached.
Just like in the g maps where
Single click makes an intent to the respective app (opens dialer with phone number copied) etc.
Long Click/Press & hold will copy the number to clipboard displaying a toast that "Phone number is copied to clicpboard".
Now I have set up the intents properly and they are working fine --> step-1 achieved.
When I try to display the toast using "OnLongClickListener" method it is taking quite some time to display the toast message. Is there any way we can speed this up or am I missing something or should I use some other alternative like onTouch() method?
(Stuck with this, yet to learn and try out copying to clipboard thing. Inputs in this regards are also welcome!)
In the g maps app, the toast message appears almost instantly on press & hold. So the same is to be achieved.
The code extract from MainActivity.java (The website, phone number, email id are text views with drawableLeft. And I found out that we cannot use setOnItemLongClick on TextView as it is only for ListView)
// This method is called when the website text view is clicked and opens the compnay website
public void openWebsite(View v) {
TextView textView = (TextView) findViewById(R.id.webURL_text_view);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent openWebsiteIntent = new Intent(Intent.ACTION_VIEW);
openWebsiteIntent.setData(Uri.parse("https://www.company.com"));
if (openWebsiteIntent.resolveActivity(getPackageManager()) != null) {
startActivity(openWebsiteIntent);
}
}
});
textView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
showMessage();
return true;
}
});
}
public void showMessage(){
Toast.makeText(this,"Information copied to Clipboard", Toast.LENGTH_LONG).show();
}
I am new to android development and just trying out something, so please be as elaborative as possible. Thank You.
I want to be able to switch between my app and twitters app to show a search for a pre-determined hashtag.
I have an on click listener & sending the user to the twitter app... loading the tweets and allowing the discussion of that hashtag. There is the logic but how can I do this? What I get now is just my feed and a drop down list of previous searches.
Here is the listener & intent code:
final Button button = (Button) view.findViewById(R.id.C_Twitter_Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("twitter://search?f=realtime&q=%23KeyWord"));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/search?f=realtime&q=%23KeyWord")));
}
}
});
Can anyone offer me a solution?
Thanks
The search query was wrong :(
The solution is to use the following url to search the twitter app:
twitter://search?query=%23hashtag
Cheers
In my Android app, I have a button with the background image of an Amazon.com product (let's say a shirt or something), and when clicked I would like it to open in the Amazon app (com.amazon.mShop.android) if is already installed rather than in the browser, and in the browser if the app is not installed.
I have been able to find how to add a deep link to a specific Amazon client app, but not how to link to a specific item that would open with open with the Amazon app.
Currently, my click listener opens in a browser by doing the following:
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(urlOfItemOnAmazonSite));
startActivity(intent);
}
})
The Amazon developer's home page is probably the best place for this answer. This may be a good start: https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs/deeplink#Link%20Configuration. Here they explain how to construct the Uri you'll need to use to set the Intent data.
Of course, you may want to be careful and wrap startActivity in a try/catch in case Amazon isn't installed and it throws an ActivityNotFoundException
You can simply do the following:
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri uri=Uri.parse(productUrl);
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
})
//Note extract url of product store in var productUrl(or any other var) and //parse it.
If I create an app that depends on another app or apps (eg: the Facebook and Twitter apps), yet they are not installed, is there a method of checking for those dependencies and installing them at the same time as my own app?
I did this in my application which requires the zxing scanner app to be installed.
You will want this inside your onclick or ontouch:
try{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
startActivityForResult(intent, 0);
} catch (Exception e) {
createAlert("Barcode Scanner not installed!", "This application uses " +
"the open source barcode scanner by ZXing Team, you need to install " +
"this before you can use this software!", true);
}
which calls
public void createAlert(String title, String message, Boolean button) {
// http://androidideasblog.blogspot.com/2010/02/how-to-add-messagebox-in-android.html
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if ((button == true)) {
alertDialog.setButton("Download Now",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:com.google.zxing.client.android"));
startActivity(browserIntent);
}
});
}
alertDialog.show();
}
Then after sorting out all that code out I realise you asked for it to be installed at the same time as your app. Not sure if i should post this code, but it may be helpful
Short answer: No, you cannot automatically install other applications as dependencies.
Longer answer:
Android Market does not let you declare other applications to install as a dependency. As a system, Market appears to be designed for single application installs -- not Linux distro style mega dependency graphs.
At runtime, you can test for installed apps and punt your user over to the Market if so. See the techniques suggested by #QuickNick (testing if an app is installed) and #TerryProbert (punting to market) if that's what you want.
Your best bet is probably to design your app to gracefully degrade if dependencies are not available, and suggest (or insist) that they head over to market to install them.
Start from this:
Intent mediaIntent = new Intent("com.example.intent.action.NAME");
// add needed categories
List<ResolveInfo> listResolveInfo = getPackageManager().queryIntentServices(mediaIntent, 0);
if (listResolveInfo.size() != 0) {
//normal behavior
} else {
//install what you need
}
I give you example of querying services. If you want to check activities, then you will call queryIntentActivities().
I think following the pattern outlined in this post on the Android Developer Blog will help you.
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
As TerryProbert points out if you know that the Intent is not available prompt the user to install the missing app.
Here's what I use to return the first mission activity that exists:
try {
Class<?> missionClass = Class.forName(mPackageName+".Mission"+mission);
Method missionDescription;
missionDescription = missionClass.getMethod("missionDescription");
mMissionDescription = (String) missionDescription.invoke(null);
if (mMissionDescription.length() > 0) {
nextMission = mission;
break;
}
} catch (Exception e) {
//DEBUG*/Log.v(this.getClass().getName(), "onResume: Mission no "+mission+" not found: "+e.getMessage());
}
Each mission is held in a separate class, derived from a Mission base class. Derived classes are called Mission1, Mission24 etc.
Not all missions are defined.
The base class has an abstract class missionDescription which returns a string describing the mission.
This code is inside a loop so tests mission=1 to 99, trying to call missionDescription. It returns when the Description for the first mission found is returned.