Volume increases on its own
- By Billybronco
- Smartphones
- 11 Replies
When I'm listening to music with Pandora the volume automatically increases by itself. Galaxy S9
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
public class Settings extends AppCompatActivity {
private static final String TAG = "SettingsActivity";
private RelativeLayout layout;
private SharedPreferences preferences;
private Bundle savedInstanceState;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Spinner spinner = findViewById(DarkMode);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.e(TAG, "onItemSelected: " + position);
handleNightMode(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.e(TAG, "onNothingSelected: ");
}
});
}
private void handleNightMode(int position) {
switch (position) {
case 0:
Log.e(TAG, "Nothing Selected");
break;
case 1:
Log.e(TAG, "FOLLLOW_SYSTEM");
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
getDelegate().applyDayNight();
break;
case 2:
Log.e(TAG, "YES");
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
getDelegate().applyDayNight();
break;
case 3:
Log.e(TAG, "NO");
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
getDelegate().applyDayNight();
break;
case 4:
Log.e(TAG, "AUTO");
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
getDelegate().applyDayNight();
break;
default:
Log.e(TAG, "FOLLLOW_SYSTEM");
break;
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String NightMode = preferences.getString("prefTheme", "NO");
if (NightMode.equals("YES"))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
if (NightMode.equals("NO"))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
else if (NightMode.equals("AUTO"))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Paint;
import android.graphics.pdf.PdfDocument;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class MainActivity extends AppCompatActivity {
mySQLiteDBHandler sqlLiteDBHandler;
EditText editTextSerialNumberInsert;
EditText editTextSerialNumberFetch;
EditText editTextInsert;
TextView textViewDisplay;
Button btnInsertUpdate;
SQLiteDatabase sqLiteDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sqlLiteDBHandler = new mySQLiteDBHandler(null,null,null,1);
ActivityCompat.requestPermissions(this,new String[]{READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
sqLiteDatabase = sqlLiteDBHandler.getWritableDatabase();
editTextSerialNumberInsert = findViewById(R.id.editText1);
editTextInsert = findViewById(R.id.editText2);
editTextSerialNumberFetch = findViewById(R.id.editText3);
textViewDisplay = findViewById(R.id.textView1);
btnInsertUpdate = findViewById(R.id.btn_insert);
InsertUpdateData();
}
public void InsertUpdateData() {
btnInsertUpdate.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isUpdate = sqlLiteDBHandler.insertUpdateData(editTextSerialNumberInsert.getText().toString(),
editTextInsert.getText().toString());
if(isUpdate == true)
Toast.makeText(MainActivity.this,"Data Updated",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Something went wrong!",Toast.LENGTH_LONG).show();
}
}
);
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void CreatePDF(View view){
String query = "Select Text from PDFTable where SerialNumber=" + editTextSerialNumberFetch.getText().toString();
Cursor cursor = sqLiteDatabase.rawQuery(query,null);
try{
cursor.moveToFirst();
textViewDisplay.setText(cursor.getString(0));
}
catch (Exception e){
e.printStackTrace();
textViewDisplay.setText("uh-oh..");
return;
}
PdfDocument pdfDocument = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(300,600,1).create();
PdfDocument.Page page = pdfDocument.startPage(pageInfo);
page.getCanvas().drawText(cursor.getString(0),10,25, new Paint());
pdfDocument.finishPage(page);
String filePath = Environment.getExternalStorageDirectory().getPath()+"/Download/"+editTextSerialNumberFetch.getText().toString()+".pdf";
File file = new File(filePath);
try {
pdfDocument.writeTo(new FileOutputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
pdfDocument.close();
}
}
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
import static android.content.ContentValues.*;
public class mySQLiteDBHandler extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "PDFDatabase.db";
public static final String TABLE_NAME = "PDFTable";
public static final String COL_1 = "SerialNumber";
public static final String COL_2 = "Text";
public mySQLiteDBHandler(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME +" (SERIALNUMBER TEXT,TEXT TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public boolean insertUpdateData(String serialnumber,String text) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,serialnumber);
contentValues.put(COL_2,text);
db.update(TABLE_NAME, contentValues, "SERIALNUMBER = ?", new String[] {serialnumber});
return true;
}
}