How to prevent alert dialog from appearing when some condition is fulfilled? - android-studio

//NotificationPermission Dialog
private void notificationPermissionDialog(){
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setCancelable(false)
.setMessage("Do you want to Enable Notifications?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("Yes");
dialogInterface.dismiss();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("No");
dialogInterface.dismiss();
}
}).show();
}
//Save Notification Permission in Preferences
private void savePermissionInPreferences(String isNotificationAllowed){
SharedPreferences sharedPreferences;
sharedPreferences = getContext().getSharedPreferences("PermissionPref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("isNotificationAllowed", isNotificationAllowed);
editor.apply();
}
I have created a dialogue which appears when fragment is opened and ask for permission if I click on NO its value is saved in shared preference for preventing it to appear again but when I replace my fragment in same activity dialogue appears again and again. Please anyone can guide me through it.
Thanks in advance.

So you can do something like below
private void notificationPermissionDialog(){
SharedPreferences sharedPreferences = getSharedPreferences("PermissionPref", Context.MODE_PRIVATE);//Add these
String permission = sharedPreferences.getString("isNotificationAllowed", "");
//Add this line
if(!permission == "No"){
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setCancelable(false)
.setMessage("Do you want to Enable Notifications?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("Yes");
dialogInterface.dismiss();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
savePermissionInPreferences("No");
dialogInterface.dismiss();
}
}).show();
}
}
//Save Notification Permission in Preferences
private void savePermissionInPreferences(String isNotificationAllowed){
SharedPreferences sharedPreferences;
sharedPreferences = getContext().getSharedPreferences("PermissionPref",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("isNotificationAllowed", isNotificationAllowed);
editor.apply();
}
If the user selected no to the Alert Dialog it wont appear again.

Related

Alert dialog , editText android java

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
TextView titleView = new TextView(this);
EditText editTextView = new EditText(this);
titleView.setText("PASSWORD");
editTextView.setHint("password");
editTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
titleView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
dialogBuilder.setCustomTitle(titleView);
dialogBuilder.setView(editTextView);
dialogBuilder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface DialogInterface, int i) {
String editTextInput = editTextView.getText().toString();
}
});
dialogBuilder.setNegativeButton("dismiss", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
This is my alert dialog . When ,dialog shows, keyboard gets up and editText has focus , i tried to force hidding keyboard different ways but without success so far . I looking forward to show this diakog while keeping keyboard down .

I want to see these buttons but i can't see them because is white. How can i change the colors?

AlertDialog.Builder builder = new AlertDialog.Builder(adapter.getContext());
builder.setTitle("Sterge Task-ul");
builder.setMessage("Esti sigur ca vrei sa stergi acest Task?");
AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
adapter.deleteItem(position);
}
}).create();
I don't know what to do more, can someone help?

How to get my TextView clickable to display the alert diaglog box?

I have the following code but the word "reset password" is not clickable. Even after I add some attributes to my xml, I still can't get it to be clicked. I thought that we should be using a button instead of a textview for clicking on? I have linked the variables to my xml file and set the relevant TextView for it.
public class LoginActivity extends AppCompatActivity {
private EditText email;
private EditText password;
private TextView reset_password;
private Button login;
private Button register;
private FirebaseAuth auth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = findViewById(R.id.email);
password = findViewById(R.id.password);
login = findViewById(R.id.login);
register = findViewById(R.id.register);
reset_password = findViewById(R.id.reset_password);
auth = FirebaseAuth.getInstance();
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String txt_email = email.getText().toString();
String txt_password = password.getText().toString();
loginUser(txt_email, txt_password);
}
});
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
}
});
}
private void loginUser(String email, String password) {
auth.signInWithEmailAndPassword(email, password).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
#Override
public void onSuccess(AuthResult authResult) {
Toast.makeText(LoginActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
});
reset_password.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final EditText resetMail = new EditText(v.getContext());
AlertDialog.Builder passwordResetDialog = new AlertDialog.Builder(v.getContext());
passwordResetDialog.setTitle("Reset Password ?");
passwordResetDialog.setMessage("Enter Your Email To Received Reset Link");
passwordResetDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// extract the email and send reset link
String mail = resetMail.getText().toString().trim();
auth.sendPasswordResetEmail(mail).addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Toast.makeText(LoginActivity.this, "Reset Link Sent To Your Email", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(LoginActivity.this, "Error! Reset Link is Not Sent" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
passwordResetDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// close the dialog
}
});
passwordResetDialog.create().show();
}
});
}
}
This is my xml code:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Forgot Password"
android:layout_below="#id/password"
android:id="#+id/reset_password"/>

Unable to find AppLovin SDK key. Please add meta-data android:name="applovin.sdk.key" android:value="YOUR_SDK_KEY_HERE" into AndroidManifest.xml

Hello everyone today I was busy with camera actions just applied rutin camera action on my application and apploving sdk key error actualy application is working but I need to know why I have this this warming on my android monitor
1. Here is my class where I start action and putExtra into intend
public class CameraActionFragment extends Fragment
{
private static final int REQUEST_CODE_IMG = 2;// for image
private static final int REQUEST_CODE_VIDEO = 1;// for video
public static final int RESULT_OK = -1;
Button btn_frag_camera_image;
Button btn_frag_camera;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_camera_action_3, container, false);
//return inflater.inflate(R.layout.fragment_camera_action_3, container, false);
btn_frag_camera_image = (Button) view.findViewById(R.id.btn_frag_camera_image);
btn_frag_camera = (Button) view.findViewById(R.id.btn_frag_camera);
// Image Action
btn_frag_camera_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Hello From Image", Toast.LENGTH_SHORT).show();
Intent intenImatToSec = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intenImatToSec, REQUEST_CODE_IMG);
}
});
// Camera Action
btn_frag_camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intenImatToSec = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intenImatToSec, REQUEST_CODE_VIDEO);
//intenImatToSec.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
//intenImatToSec.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
//Toast.makeText(getActivity(), "Hello From Camera", Toast.LENGTH_SHORT).show();
}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CODE_IMG) {
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");
Intent intentBitMap = new Intent(getActivity(), DisplayImage.class);
// aldıgımız imagi burda yonlendirdiğimiz sınıfa iletiyoruz
ByteArrayOutputStream _bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, _bs);
intentBitMap.putExtra("byteArray", _bs.toByteArray());
startActivity(intentBitMap);
} else if (requestCode == REQUEST_CODE_VIDEO) {
Uri videoUrl = data.getData();
Intent intenToDisplayVideo = new Intent(getActivity(), DisplayVideo.class);
intenToDisplayVideo.putExtra("videoUri", videoUrl.toString());
startActivity(intenToDisplayVideo);
}
}
} }
1. And I play my video here
public class DisplayVideo extends Activity
{
private static final int REQUEST_CODE_VIDEO = 100;
VideoView videoView;
Button btn_cancel;
Button btn_send_cahallenge;
Button btn_image_play;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_video_activity);
videoView = (VideoView) findViewById(R.id.videoview_display_video_actvity);
btn_cancel = (Button) findViewById(R.id.btn_display_image_cancel);
btn_send_cahallenge = (Button) findViewById(R.id.btn_display_image_send_cahallenge);
btn_image_play = (Button) findViewById(R.id.btn_display_image_play);
// CameraActionFragmentten gelen uri
Bundle extras = getIntent().getExtras();
Uri myUri = Uri.parse(extras.getString("videoUri"));
videoView.setVideoURI(myUri);
btn_image_play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
videoView.start();
}
});
btn_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences shp = getSharedPreferences("pref", MODE_PRIVATE);
SharedPreferences.Editor editor = shp.edit();
editor.putInt("frag_no", 2);
editor.commit();
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_VIDEO && resultCode == RESULT_OK) {
Uri videoUrl = data.getData();
videoView.setVideoURI(videoUrl);
//videoView.setMediaController(new MediaController(getApplicationContext()));
//videoView.requestFocus();
}
}
}
3. Cant find some usefull guide about AppLovin SDK key. Lately I
defined facebook sdk key and everything was good and after camera
actions ı have this problem
Error is
E/AppLovinSdk: Unable to find AppLovin SDK key. Please add meta-data android:name="applovin.sdk.key" android:value="YOUR_SDK_KEY_HERE" into AndroidManifest.xml.
07-29 16:24:26.390 12911-12911/? E/AppLovinSdk: Called with an invalid SDK key from: java.lang.Throwable:
at com.applovin.impl.sdk.AppLovinSdkImpl.a(Unknown Source)
at com.applovin.sdk.AppLovinSdk.b(Unknown Source)
at com.applovin.sdk.AppLovinSdk.c(Unknown Source)
at com.applovin.sdk.AppLovinSdk.b(Unknown Source)
at com.qihoo.security.SecurityApplication.onCreate(360Security:263)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4806)
at android.app.ActivityThread.access$1600(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:234)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
you have an invalid SDK key you need to setup AppLovin correctly
please try to add:
<meta-data android:name="applovin.sdk.key"
android:value="YOUR_SDK_KEY_HERE"/>
to your AndroidManifest file inside application tag.
Please check below link to find AppLovin SDK Key
Click Here To open AppLovin's Key Window

hello how can i make full width dialog popup in android this is my code

view.findViewById(R.id.doc_prof_det_add_speciality_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
LayoutInflater factory = LayoutInflater.from(v.getContext());
final View view = factory.inflate(R.layout.doc_prof_det_add_speciality, null);
alertDialog.setView(view);
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
});
Try this:
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
//Grab the window of the dialog, and change the width
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = alertDialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
}
});

Resources