Skip to content

Instantly share code, notes, and snippets.

View ashishkudale's full-sized avatar

Ashish Kudale ashishkudale

View GitHub Profile
import static android.Manifest.permission.CAMERA;
public class Camera extends AppCompatActivity {
private static final int PERMISSION_REQUEST_CODE = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_permission);
//open settings when user
private void openSettings() {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
@ashishkudale
ashishkudale / file.java
Last active April 11, 2020 17:02
check permission and request permission
//Add this line in import section
import static android.Manifest.permission.CAMERA;
private void requestPermission() {
ActivityCompat.requestPermissions(this, new String[]{CAMERA}, PERMISSION_REQUEST_CODE);
}
private boolean checkPermission() {
return ContextCompat.checkSelfPermission(getApplicationContext(), CAMERA) == PackageManager.PERMISSION_GRANTED;
}
@ashishkudale
ashishkudale / showAlertDialog.java
Last active April 11, 2020 17:03
showAlertDialog helps to show dialog box with custom title,message and OnClickListener
private void showAlertDialog(String title, String message, String positiveButtonText, String negativeButtonText, DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) {
AlertDialog dialog = new AlertDialog.Builder(CameraPermission.this)
.setPositiveButton(positiveButtonText, positiveListener)
.setNegativeButton(negativeButtonText, negativeListener)
.create();
if (title != null || !title.isEmpty()) {
dialog.setTitle(title);
}
dialog.setMessage(message);
dialog.show();
@ashishkudale
ashishkudale / MainActivity.java
Last active November 12, 2019 17:15
get shared preference values
//To get string value from shared preference
String phoneNumber = SharedPrefHandler.getInstance(MainActivity.this, SharedPrefHandler.PrefFiles.USER_DE
.getValue(SharedPrefHandler.Keys.USER_DETAILS);
//To get boolean value from shared preference
boolean userKyc = SharedPrefHandler.getInstance(MainActivity.this, SharedPrefHandler.PrefFiles.USER_DETAI
.getBooleanValue(SharedPrefHandler.Keys.USER_KYC);
//To add string value from shared preference
SharedPrefHandler.getInstance(MainActivity.this, SharedPrefHandler.PrefFiles.USER_DETAILS_PREF)
@ashishkudale
ashishkudale / SharedPrefHandler.java
Last active November 12, 2019 16:43
Shared Preference Helper using singleton.
public class SharedPrefHandler {
private static SharedPrefHandler me;
private static String sharedPrefName;
private static Context context;
private SharedPrefHandler(){}
public static SharedPrefHandler getInstance(Context cntx, PrefFiles sharedPrefFileName){
if(me == null){
@ashishkudale
ashishkudale / enable features
Created June 11, 2018 17:43
following commands are for enabling xp_cmdshell.
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
GO
-- To update the currently configured value for advanced options.
RECONFIGURE;
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
GO
-- To update the currently configured value for this feature.
CREATE PROCEDURE [dbo].[auto_backup] as
declare
@DATABASENAME nvarchar (100),
@PATH nvarchar (100),
@zipname nvarchar (100),
@zipname1 nvarchar (100)
SET @DATABASENAME = db_name()
SET @PATH = 'C:\DB_Backup\'+@DATABASENAME
DBCC SHRINKDATABASE (@DATABASENAME)
BACKUP DATABASE @DATABASENAME TO DISK =@PATH WITH NAME = 'BACKUP',STATS = 10
@ashishkudale
ashishkudale / build.gradle
Created May 13, 2018 13:42
app level gradle
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
@ashishkudale
ashishkudale / HomeActivity.java
Last active May 13, 2018 12:36
implementation
public class HomeActivity extends AppCompatActivity {
private RecyclerView rvSubject;
private SubjectAdapter subjectAdapter;
private ArrayList<Subject> subjects;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);