Google Plus one button android not working - android

Hi Guys I have integrated a google +1 button in Android.
The main difference is I have created it inside a dialog and not inside the Activity. Below is the code I have used
final Dialog dialog = new Dialog(this.getContext());
dialog.setContentView(R.layout.plus_one_layout);
dialog.setTitle("Title...");
dialog.setCancelable(false);
plusOneButton = (PlusOneButton) dialog.findViewById(R.id.plus_one_button);
if(!DotsCrazy.this.mGoogleApiClient.isConnected()) {
DotsCrazy.this.mGoogleApiClient.connect();
}
OnPlusOneClickListener listener = new OnPlusOneClickListener() {
#Override
public void onPlusOneClick(Intent intent) {
if(!DotsCrazy.this.mGoogleApiClient.isConnected()) {
DotsCrazy.this.mGoogleApiClient.connect();
} else {
startActivityForResult(intent, 0);
}
}
};
plusOneButton.initialize("http://plus.google.com/+Example",listener);
dialog.show();
The problem is it always show "There was a temporary problem with your +1 Please try again later". Anybody knows the reason?

Related

android Custom Dialog title doesnot show

Im new at android app development so i was following a youtuber on making a Database, im doing same as he is, but problem is that i can make db successfully but custom dialog title doesnt show but error mesage & textview text is visible in my app.
Im attaching screenshot of successful code on youtube.
screenshot
btninsert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean boolln=true;
try {
String firstname = firstnam.getText().toString();
String lstname = lastnam.getText().toString();
db1.insertname(firstname, lstname);
}catch (Exception ex){
boolln=false;
String error=ex.toString();
Dialog dl=new Dialog(Activity_DB.this);
dl.setTitle("Uncuceesful");
TextView tx=new TextView(Activity_DB.this);
tx.setText(error);
dl.setContentView(tx);
dl.show();
}finally {
if (boolln){
Dialog dl1=new Dialog(Activity_DB.this);
dl1.setTitle("succesful? YES");
TextView tx=new TextView(Activity_DB.this);
tx.setText("sucesss");
dl1.setContentView(tx);
dl1.show();
}
}
Solved this problem by adding AlerDialog.builder instead of using Dialog, now it works perfectly.
boolln=false;
String error=ex.toString();
AlertDialog.Builder dl=new AlertDialog.Builder(Activity_DB.this);
dl.setCancelable(true);
dl.setTitle("Uncuceesful");
dl.setMessage("No entry found. \n"+error);
dl.show()

My Xamarin Android app keeps restarting itsself

I've an app that checks version compatibility at startup from within the main activity's OnCreate function. Since Android doesn't (to my knowledge) have a modal dialog, if the version is not compatible I show an AlertDialog via AlertDialog.Builder and set the neutral button action to shut down the app. Unfortunately this causes the app to restart instead of shutting down. Could someone help me get the app to shut down please?
This is being tested on Android 7.0, but also needs to run on Android 4.2.2.
public class Activity1 : FragmentActivity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
if (!versionCheck.Success) {
ShowNotesReadonlyDialog("Version Incompatibility", versionCheck.Message, new Action(() => ShutdownApplication()) );
return;
}
}
private void ShutdownApplication() {
this.Finish();
// -- I've tried all the things below with the same result.
//this.FinishAffinity();
//this.Dispose();
//global::Android.OS.Process.KillProcess(global::Android.OS.Process.MyPid());
}
private void ShowNotesReadonlyDialog(String title, String message, Action action) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View layout = inflater.Inflate(Resource.Layout.GenericTextViewLayout, FindViewById<ViewGroup>(Resource.Id.GenericTextViewDialogRoot));
dialog.SetTitle(title);
dialog.SetView(layout);
TextView label = layout.FindViewById<TextView>(Resource.Id.GenericTextViewMessageLabel);
label.Text = message;
dialog.SetNeutralButton("Close", (o, e) => {
if (null != action) {
action.Invoke();
}
dialog.Dispose();
});
dialog.SetCancelable(false);
AlertDialog window = dialog.Create();
WindowManagerLayoutParams p = new WindowManagerLayoutParams();
p.CopyFrom(window.Window.Attributes);
p.Width = 900;
p.Height = WindowManagerLayoutParams.WrapContent;
window.Show();
window.Window.Attributes = p;
}
}
I've placed breakpoints in several lifecycle events. After calling Finish() the following events are called on the Activity:
OnStop()
OnCreate()
OnStart()
Additionally, the Activity disappears from the screen when Finish() is called, but pressing the "window manager" hardware key shows that the application is still running. Tapping the window shows it on screen.

Google Maps API v2 legal notices String too much long

I'm trying to add, in my android app, the legal notices for Google Maps v2 API, that can be obtained calling: GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo()
So, my code is the following:
String LicenseInfo = GooglePlayServicesUtil
.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MyActivity.this);
LicenseDialog.setTitle("Lagal Notices");
LicenseDialog.setMessage(LicenseInfo);
LicenseDialog.show();
But when I execute this code, the system required about 10 seconds before the dialog is shown (considering that my device is a OnePlus One, it seems pretty strange) .
If I try to replace the LicenseInfo with a simple (shorter) string, the Dialog is open pretty fast. So I think that the problem is the length of the legal notices information retrieved from the Google play utils.
How can I solve this problem?
I had the same problem, but I found this on GitHub and based my solution on it. This does help but when the alert dialog shows, there is still a small hang on the UI thread but only for a few seconds.
https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/src/android/plugin/google/maps/AsyncLicenseInfo.java
private class AsyncLoadLicenseInfo extends AsyncTask<Void,Void,AlertDialog.Builder>
{
#Override
protected void onPreExecute()
{
progressDialog = new ProgressDialog(context);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(context.getResources().getString(R.string.LegalNoticesLoading));
progressDialog.setCancelable(false);
progressDialog.show();
}
#Override
protected AlertDialog.Builder doInBackground(Void... params)
{
String googleAttribution = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(context);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder
.setTitle(context.getResources().getString(R.string.AboutLegalNotices))
.setCancelable(false)
.setMessage(googleAttribution)
.setPositiveButton(context.getResources().getString(R.string.Close),null);
return builder;
}
#Override
protected void onPostExecute(AlertDialog.Builder builder)
{
AlertDialog attributionDialog = builder.create();
attributionDialog.setOnShowListener(new DialogInterface.OnShowListener()
{
#Override
public void onShow(DialogInterface dialog)
{
progressDialog.dismiss();
progressDialog = null;
}
});
attributionDialog.show();
}
}
As tasomaniac suggested, using WebView instead of TextView works without problems - there is just a small delay.
Here is the complete code to show the dialog:
private void legalDialog(){
String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);
licenseInfo = licenseInfo.replace("\n", "<br/>");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.legal_notice);
WebView webView = new WebView(this);
webView.loadData("<html><body>"+licenseInfo+"</body></html>", "text/html", "utf-8");
WebSettings webSettings = webView.getSettings();
webSettings.setDefaultFontSize(12);
builder.setView(webView);
builder.setPositiveButton(R.string.dialog_close, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
final AlertDialog createDialog = builder.create();
createDialog.show();
}
Make sure to check if GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this) doesn't return null, before calling legalDialog().
On a Motorola G5 running Android 6 the licence string returned by GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo() (or more recently GoogleApiAvailability.getInstance().getOpenSourceSoftwareLicenseInfo(getActivity())) is over 600,000 characters long. The delay occurs when loading the string into the TextView, which must be done on the UI thread.
LongStringLoader may be a solution to this. Full disclosure - I worked on the development team.
Another solution would be to use a WebView instead of a TextView.
You can have a really small Html template and you can fill its body with license text returned by
String result = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);
I was not able to show a progress dialog because the UI freezes. Plus the time consuming part was when dialog.show() took place and that could not be done on a background thread. Instead, I changed the text of the legal notices link to "Please wait" and then showed up the dialog with the legal notice. When the dialog dismissed I changed the text back to "Legal Notices" (Ofcourse the new dialog took up the whole screen where my background text was covered. If not then use dialog.setOnShowListener to change the text to/from Please Wait)
legalNoticeTV.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
legalNoticeTV.setText(getResources().getString(R.string.please_wait));
legalNoticeTV.setEnabled(false);
String result = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);
TextView tv = new TextView(this);
tv.setBackgroundColor(getResources().getColor(R.color.dialogbackgroundcolorgrey));
tv.setText(result);
tv.setPadding(8, 8, 8, 8);
ScrollView sc = new ScrollView(this);
sc.addView(tv);
legalNotice = new Dialog(this, R.style.DialogNoTitle);
legalNotice .requestWindowFeature(Window.FEATURE_NO_TITLE);
legalNotice.setContentView(sc);
legalNotice.show();
legalNotice.setOnDismissListener(new OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
legalNoticeTV.setText(getResources().getString(R.string.legal_notices));
legalNoticeTV.setEnabled(true);
}
});
}
});
While using WebView as in lenooh's answer, it is better to use TextUtils.htmlEncode(licenseInfo) instead of manually converting string to HTML string.
String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);
licenseInfo = TextUtils.htmlEncode(licenseInfo);

Android Facebook - Login / Logout Dialog

I've managed to successfully implement Facebook login into my Android app.The issue I'm facing is,on my logout,whenever I click the logout button,I would like to capture the click of "Cancel / Logout" options.How do I go about doing this?Below are images attached for a much clearer illustration.
As shown in the images,how do I go about capturing the clicks in the highlighted red circles?
Below attached are my codes for the login/logout activity as well.Thank you :)
View view = inflater.inflate(R.layout.splash, container, false);
LoginButton authButton = (LoginButton) view
.findViewById(R.id.login_button);
authButton.setFragment(this);
// Get more permissions
authButton.setPublishPermissions(Arrays
.asList("publish_actions,read_stream"));
authButton.setFragment(getParentFragment());
I now this post is very old but...
I had the same problem as you, what I did was:
(only sure for facebook sdk v2.0)
1. Go to package com.facebook.widget;
2. Open the file LoginButton.java;
3. Go to line 819 inside the public void onClick(View v);
4. See the allert Dialog? I just comented the code as follows:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message)
.setCancelable(true)
.setPositiveButton(logout, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
openSession.closeAndClearTokenInformation();
}
});
/*.setNegativeButton(cancel, null);*/
builder.create().show();
And it is done!, no more annoying cancel button on dialog.
(You can also remove the whole dialog)
I got the same problem and searched some many answers,but they doesnot work,so I just write some new codes in LoginButton.java in facebook sdk,my frist step:
public interface LogoutListener{
public void afterLogin();
}
private LogoutListener mLoginoutListener;
public void setLogoutListener(LogoutListener loginoutListener){
this.mLoginoutListener = loginoutListener;
}
second step:find 811 lines in LoginButton.java and you will see the code just like this:
private class LoginClickListener implements OnClickListener {
#Override
public void onClick(View v) {
Context context = getContext();
final Session openSession = sessionTracker.getOpenSession();
if (openSession != null) {
// If the Session is currently open, it must mean we need to log out
if (confirmLogout) {
// Create a confirmation dialog
String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
String message;
if (user != null && user.getName() != null) {
message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.getName());
} else {
message = getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message)
.setCancelable(true)
.setPositiveButton(logout, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
openSession.closeAndClearTokenInformation();
// here is what I added
if(mLoginoutListener != null){
mLoginoutListener.afterLogin();
}
}
})
.setNegativeButton(cancel, null);
builder.create().show();
} else {
openSession.closeAndClearTokenInformation();
}
third step,and this is how I use :
LoginButton floginButton = (LoginButton)findViewById(R.id.flogin_button);
floginButton.setLogoutListener(new LogoutListener() {
#Override
public void afterLogin() {
// do what you want ,when user click the "OK" button.
}
});
I changed a little bit codes in facebook sdk,and it worked for me,I hope this can help you.

Show DialogBox in loop in android

I am trying to show dialog boxes with contents from the database .The fetched data from the database may contain more than 1 data.So I have to show dialog in for loop.But the dialog shows only for the first row in the database.Here is the code
cursor = sqldb.query(Database_Handler.dbdectab, null,"((" + Database_Handler.gendtime + "<='" + after_1hr + "' and " + Database_Handler.gendtime + ">='" + before_1hr + "') and ("
+ Database_Handler.calused + "='Gregorian' or " + Database_Handler.calused + "='both')) ", null, null, null, null);
notif_count = cursor.getCount();
//dec_name_ctr_builder = new StringBuilder("");
if(notif_count>0)
{
dialog1 = new Dialog(this);
cursor.moveToFirst();
do
{
dec_name =cursor.getString(cursor.getColumnIndex(Database_Handler.decname));
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.custom_dialog_alert);
TextView tv_alert = (TextView)dialog1.findViewById(R.id.txt_alert);
tv_alert.setText( dec_name );
Button yes = (Button) dialog1.findViewById(R.id.btn_yes);
Button no = (Button) dialog1.findViewById(R.id.btn_no);
yes.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(donateurl));
startActivity(intent);
dialog1.dismiss();
cursor.close();
sqldb.close();
finish();
}
});
no.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
dialog1.dismiss();
cursor.close();
sqldb.close();
finish();
}
});
dialog1.show();
}while(cursor.moveToNext());
Android dialog boxes are not modal (which is to say, they don't block the background processes).Hence your work is done asycnhronuosly and according to :
Romain guy
We've designed Android to prevent developers from writing synchronous dialogs so you don't really have much of a choice.
SO you can not block the while loop execution in between using Dialog.
Karan_Rana is right. The simplest solution for your answer would be storing the results somewhere else and displaying a new dialog each time some data is left and user clicks on a previous dialogs button.
I know this is a bit late, but I had a similar problem once. I used recursion to loop a dialog box. My situation was unique as I needed to detect an internet connection during app startup. So, this approach may not work for you. But I was able to implement the solution without for loops and blocking the main UI thread. Because I was on a splash screen, there was no other UI I needed to contend so I would simple call the dialog box again until the user chooses to "Quit".
I had a splash screen that would only continue to the landing activity of the app if a network connection was detected.
Sample code below to demonstrate the concept. Note that there are custom methods, but you should get the idea to call the prompt again from within onClick method.
protected void onCreate(Bundle savedInstanceState) {
if (isNetworkAvailable()) {
launchApp();
} else {
retryPrompt();
}
}
private void retryPrompt() {
if (isNetworkAvailable()) {
launchApp();
} else {
final ConfirmDialog dialog = new ConfirmDialog.CustomAlertBuilder(this,
"Internet Connection",
"Internet Connection not detected. Please check your connection.",
"Retry").
setNegBtnLabel("Quit").
setCustomCallback(new CustomDialogCallback() {
#Override
public void onClickPositiveBtn(DialogInterface dialogInterface, int which) {
// go around again.
retryPrompt(); // <<== Call method recursively
}
#Override
public void onClickNegativeBtn(DialogInterface dialogInterface, int which) {
// abort app.
finish();
}
}).build();
dialog.show();
}
}

Categories

Resources