Skip to content

Instantly share code, notes, and snippets.

View AliAsadi's full-sized avatar
:octocat:

Ali Asadi AliAsadi

:octocat:
View GitHub Profile
new Notification.Builder(context)
.setContentTitle(title)
.setContentText(contentText)
.setSmallIcon(R.drawable.icon)
.setContentIntent(intent);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Default", NotificationManager.IMPORTANCE_DEFAULT);
channel.setVibrationPattern(new long[0]);
channel.enableVibration(false);
channel.setSound(null,null);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
private static String longArrayToString(long[] values) {
StringBuffer sb = new StringBuffer();
if (values != null) {
for (int i = 0; i < values.length - 1; i++) {
sb.append(values[i]).append(DELIMITER);
}
sb.append(values[values.length - 1]);
}
return sb.toString();
}
if (vibrationPattern !=null && vibrationPattern.lenght > 0){
this.mVibrationEnabled = true;
this.mVibration = vibrationPattern
}else{
this.mVibrationEnabled = false;
this.mVibration = null;
}
public class ThreadActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
new DownloadTask().start();
}
private class DownloadTask extends Thread {
@Override
public class ThreadActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//....
new DownloadTask(this).start();
}
private class DownloadTask extends Thread {
public class SingletonManager {
private static SingletonManager singleton;
private Context context;
private SingletonManager(Context context) {
this.context = context;
}
public synchronized static SingletonManager getInstance(Context context) {
public class LoginActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
SingletonManager.getInstance(this);
}
}
SingletonManager.getInstance(getApplicationContext());
public class SingletonManager {
// ....
public synchronized static SingletonManager getInstance(Context context) {
if (singleton == null) {
singleton = new SingletonManager(context.getApplicationContext());
}
return singleton;
}
}