I would like to know if it is possible to create an AlertDialog before a text message is sent from the default messaging app. I have looked at other people's questions on intercepting outgoing sms messages, however, those only seem to show how to read the message and not actually prevent it from being sent. I also do not want to create my own messaging app from scratch, so please do not suggest that. Thank you.
First of all create a new AlertDialog object like this
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Now lets say the SMS you want to send is triggered by the click of a button. Lets call it sendSMS. Inside the onClick method set the parameters of the AlertDialog object like this :
sendSMS.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
builder.setMessage("You are about to send an SMS! are you sure you want to send it?")
.setTitle("Warning!")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(#SuppressWarnings("unused") final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
//*******************************
//PUT HERE THE SMS SENDING CODE!!!
//*******************************
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
//closes the dialog; nothing interesting happens here
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
});
return true;
}
This displays an AlertDialog with the click of a button, warning the user that he/she is about to send an SMS. If he/she clicks yes then, the SMS code is triggered. If he/she clicks no nothing happens.
Related
I am getting security alert from google play saying:
Your APK has been rejected for containing security vulnerabilities, which violates the Malicious Behavior policy. If you submitted an update, the previous version of your app is still live on Google Play.
If I remove onReceivedSslError (handler.proceed()), page won't open.
Is there anyway I can open page in webview and avoid security alert.
and my website to put in my app need http or https ? I'm using http://mywebsite...
If you use onReceivedSslError method, then please remove onReceivedSslError method and make new APK.
Change onReceivedSslError() to:
#Override
public void onReceivedSslError(WebView v, final SslErrorHandler handler, SslError er) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Problem with Security");
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
Hope this will help you.
I am trying to update a record in kinvey collection but it keep saying insufficient credentials
i found a similar question on the forum that said i have to setGloballyWriteable to the acl of my model i have done that but still have the error
here is my code
public void loadMenuHelper(){
menu_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Order order = my_orders[position];
order.getAcl().setGloballyWriteable(true);
order.getAcl().setGloballyReadable(true);
int requests = order.getRequests();
////////////have the handler
AlertDialog.Builder alert = new AlertDialog.Builder(
new ContextThemeWrapper(ImageTargets.this, R.style.AlertDialogCustom));
LinearLayout layout = new LinearLayout(ImageTargets.this);
layout.setOrientation(LinearLayout.VERTICAL);
alert.setTitle("There are " + requests + "Before you");
alert.setView(layout);
alert.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
///////////////
order.getAcl().setGloballyWriteable(true);
order.getAcl().setGloballyReadable(true);
order.setRequests(order.getRequests() + 1);
AsyncAppData<Order> myevents = mKinveyClient.appData("Order", Order.class);
myevents.save(order, new KinveyClientCallback<Order>() {
#Override
public void onFailure(Throwable e) {
Log.i("TAG", "failed to save event data" + e.getMessage());
Log.i("TAG", sharedpreferences.getString("owner_name", ""));
}
#Override
public void onSuccess(Order r) {
Log.d("TAG", "saved data for entity " + r.getName());
Toast.makeText(getApplicationContext(), "Your Order was Created Sucessfully", Toast.LENGTH_SHORT).show();
}
});
}
////////////
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
}
});
alert.show();
////////////////
}
});
///////////////
}
Considering that you have a user properly logged in, this seems to be related to collection permissions.
Your collection is in shared mode, that's why you are able to read the order object created by somebody else. But, because only creator can modify the object, you are getting "insufficient credentials" error.
You have two options here. The first option is to change collection permissions to public so that anybody can edit any order object. You can do that in Kinvey web console by going to settings tab in the data browser for the Order collection. After this, you won't need to use setGloballyWriteable/setGloballyReadable.
Other option (better suitable according to me) is to create another collection for requests for specific orders. In this new collection, you will be able to store a reference of the order object as well as store user information about the user who requested it.
You can find necessary documentation related to collection permissions here - http://devcenter.kinvey.com/android/guides/security
I have implemented a login DialogFragment in my app (API 19). I'm using Retrofit 1.7.1 for networking. The implementation is below:
public class SignInDialogFragment extends DialogFragment {
private EditText mUsernameEditText;
private EditText mPasswordEditText;
public static SignInDialogFragment newInstance() {
return new SignInDialogFragment();
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Builder builder = new AlertDialog.Builder(getActivity())
.setPositiveButton(R.string.action_sign_in, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
String username = mUsernameEditText.getText().toString();
APIFactory.getAPI().register(username, new Callback<RegistrationResponseModel>() {
#Override
public void success(RegistrationResponseModel registrationResponse, Response response) {
Toast.makeText(getActivity(), "Totally worked!", Toast.LENGTH_SHORT).show();
}
#Override
public void failure(RetrofitError error) {
Toast.makeText(getActivity(), "Something failed!", Toast.LENGTH_SHORT).show();
}
});
}
})
.setNegativeButton(R.string.action_cancel, null);
View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_sign_in, null);
builder.setView(view);
mUsernameEditText = (EditText)view.findViewById(R.id.usernameEditText);
return builder.create();
}
}
As you might predict, this crashes upon success or failure when getActivity() hits a null reference. What is the best way to handle an asynchronous request such as this, including getting callbacks after the dialog has been dismissed?
I thought of a few options; are any of them viable?
I could simply hold the dialog open if there is a request in progress. I haven't implemented this because I'm not sure of the cleanest way to keep the dialog around (handling the Back button, etc).
I would really like to just cancel the Request if the dialog is closed, but I can't, because there is not currently a way to cancel Retrofit requests.
If there is an option that I'm not aware of, I'd like to hear about it.
You should move your action out of Dialog. Dialog is not Activity - once user did a choice, dialog should be dismissed and if there's any action to trigger it should be done as response to user action with dialog, but it should not be part of dialog. Therefore you should just react to user choice in your parent Fragment or Activity, not in Dialog.
How would you handle displaying a connection error message to the user when we can't connect via Google Play and is missing?
This has to be Froyo compatible.
Display an alert when you got message from Google Play as Connection Error as below:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Found some unknown Error. Please try again after some time.")
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
I have an application that uses the Facebook SDK for Android to login into my application. But I am having some problems in checking whether the user is already logged-in or not. After the login page, the main interface will be displayed to the user. What I want is that, if the user has logged-in in its past interaction with application, the next time the application is launched, no more login screen just the main interface. So at start-up my application should check whether a user is logged in or not. How will I do it?
I tried using mFacebook.isSessionValid(), but it's always returning a false.
You can try the following code :
if(mFacebook.isSessionValid()) {
onFacebookClick();
}
private void onFacebookClick() {
if (mFacebook.isSessionValid()) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Delete current Facebook connection?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
fbLogout();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
facebook_btn.setText(getResources().getString(R.string.signinout));
}
});
final AlertDialog alert = builder.create();
alert.show();
} else {
facebook_btn.setText(getResources().getString(R.string.signin));
mFacebook.authorize(this, PERMISSIONS, -1,new FbLoginDialogListener());
}
}