how to get ride of deprecated API error in Android Studio - api

I am working on android studio project for the first time and I am using Broadcast Receiver. Whenever I run my application I get an error that my Broadcast File uses or overrides a deprecated Api. Although my project runs fine but I need to know why I am getting this and how to get rid of this error.My broadcast file is as follows:
package com.example.user.offlinemobilefinder;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
public class AlarmActivity extends AppCompatActivity {
MediaPlayer myMediaPlayer = null;
Button btnStop;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
Intent intent= getIntent();
final String contact=intent.getStringExtra("contact");
btnStop=findViewById(R.id.stopButton);
myMediaPlayer = MediaPlayer.create(this, R.raw.loudalarm);
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
myMediaPlayer.start();
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
myMediaPlayer.stop();
SmsManager smsManager = SmsManager. getDefault();
smsManager.sendTextMessage(contact, null, "Alarm Stoped", null, null);
}
});
}
}
Thanks in advance for help.

AndroidStudio should tell you which method is deprecated. You can then go to the documentation for that method on developer.android.com and there should be a note telling you what to use instead.

Related

How can I implement the Android Car API for Andorid Studio to read out my EVs percentage?

I'm currently trying to display the percentage of my Ev Via Android Auto. I can't manage to get CarInfo carInfo = getCarContext().getCarService(CarHardwareManager.class).getCarInfo(); to run. I used this in my automotive build.gradle useLibrary 'android.car' and tried importing many things but that didn't help obviously.
This is my first file:
package com.example.aatest4;
import android.car.Car;
import android.car.CarInfoManager;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.car.app.CarAppMetadataHolderService;
import androidx.car.app.CarAppService;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.Session;
import androidx.car.app.hardware.CarHardwareManager;
import androidx.car.app.hardware.info.CarInfo;
import androidx.car.app.validation.HostValidator;
//import android.content.ServiceConnection;
public class HelloWorldService extends CarAppService {
#NonNull
#Override
public HostValidator createHostValidator() {
return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR;
}
public Session onCreateSession() {
return new Session() {
#NonNull
#Override
public Screen onCreateScreen(#NonNull Intent intent) {
CarInfo carInfo = getCarContext().getCarService(CarHardwareManager.class).getCarInfo();
return new HelloWorldScreen(getCarContext());
}
};
}
}
and this my second:
package com.example.aatest4;
//import android.car.Car;
//import android.car.CarInfoManager;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.model.Pane;
import androidx.car.app.model.PaneTemplate;
import androidx.car.app.model.Row;
import androidx.car.app.model.Template;
public class HelloWorldScreen extends Screen {
//public HelloWorldScreen() {
public HelloWorldScreen(CarContext carContext) {
super(carContext);
}
#NonNull
#Override
public Template onGetTemplate() {
String akku = String.valueOf(50);
Row row = new Row.Builder().setTitle(akku + "% ").addText(akku + "%").build();
return new PaneTemplate.Builder(new Pane.Builder().addRow(row).build()) .setTitle("Akkuanzeige").build();
//Todo: Center?
}
}

Minecraft Forge 1.12.2 - Item Textures Not Loading

When following Cubicoder's modding tutorial for Forge 1.12.2, and creating my first item, the texture for the item will not load. I have double checked all of my code against his code. I have my latest log here. I have my registration handler RegistrationHandler.java down below.
package notacyborg.tutorialmod;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import notacyborg.tutorialmod.util.RegistryUtil;
#EventBusSubscriber(modid = TutorialMod.MODID)
public class RegistrationHandler
{
#SubscribeEvent
public static void registerItems(Register<Item> event)
{
final Item[] items = {
RegistryUtil.setItemName(new Item(), "first_item").setCreativeTab(CreativeTabs.MISC)
};
event.getRegistry().registerAll(items);
}
}
ModelRegistrationHandler.java
package notacyborg.tutorialmod.client;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import notacyborg.tutorialmod.TutorialMod;
import notacyborg.tutorialmod.init.ModItems;
#EventBusSubscriber(value = Side.CLIENT, modid = TutorialMod.MODID)
public class ModelRegistrationHandler
{
#SubscribeEvent
public static void registerModels(ModelRegistryEvent event)
{
registerModel(ModItems.FIRST_ITEM, 0);
}
private static void registerModel(Item item, int meta)
{
ModelLoader.setCustomModelResourceLocation(item, meta,
new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
}
And my first_item.json model file.
{
"parent": "item/generated",
"textures": {
"layer0": "tutorialmod:textures/items/first_item"
}
}
Any help is appreciated!
Your error log says that it was not able to find the model file of your first_item. Make sure that you have put your first_item.json (model file) in assets/Your-Mod-ID/models/item/first_item.json
In your first_item.json file, line 4 should be:
"textures": {
"layer0": "tutorialmod:item/first_item"
}
Try it out and post an error log too if you encounter any further errors.

Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference In Android ReactNative

ReactNative:0.61.4
ReactNativeMaps:0.26.1
Android: 7 ~ 10
I found an error in FireBase Crashlytics while using ReactNativeMaps.
com.google.maps.api.android.lib6.gmm6.api.m.a (:com.google.android.gms.dynamite_mapsdynamite#200616061#20.06.16 (100300-0):5)
com.google.maps.api.android.lib6.impl.dd.a (:com.google.android.gms.dynamite_mapsdynamite#200616061#20.06.16 (100300-0):12)
com.google.android.gms.maps.internal.ag.a (:com.google.android.gms.dynamite_mapsdynamite#200616061#20.06.16 (100300-0):1)
ch.onTransact (:com.google.android.gms.dynamite_mapsdynamite#200616061#20.06.16 (100300-0):4)
android.os.Binder.transact (Binder.java:692)
com.google.android.gms.internal.maps.zza.zzb (unkonwSource:20)
com.google.android.gms.maps.internal.zzai.zza (unkonwSource:5)
com.google.android.gms.maps.zzm.onLocationChanged (unkonwSource:2)
com.airbnb.android.react.maps.FusedLocationSource$1.onSuccess (FusedLocationSource.java:46)
com.airbnb.android.react.maps.FusedLocationSource$1.onSuccess (FusedLocationSource.java:43)
com.google.android.gms.tasks.zzn.run (unkonwSource:4)
android.os.Handler.handleCallback (Handler.java:873)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:205)
android.app.ActivityThread.main (ActivityThread.java:6996)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:884)
I don't know where the rest of the code is
Because only FusedLocationSource is known
I saw FusedLocationSource but android.location.Location.getLatitude () doesn't exist.
package com.airbnb.android.react.maps;
import android.content.Context;
import android.location.Location;
import android.os.Looper;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.LocationSource;
import com.google.android.gms.tasks.OnSuccessListener;
public class FusedLocationSource implements LocationSource {
private final FusedLocationProviderClient fusedLocationClientProviderClient;
private final LocationRequest locationRequest;
private LocationCallback locationCallback;
public FusedLocationSource(Context context){
fusedLocationClientProviderClient =
LocationServices.getFusedLocationProviderClient(context);
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(5000);
}
public void setPriority(int priority){
locationRequest.setPriority(priority);
}
public void setInterval(int interval){
locationRequest.setInterval(interval);
}
public void setFastestInterval(int fastestInterval){
locationRequest.setFastestInterval(fastestInterval);
}
#Override
public void activate(final OnLocationChangedListener onLocationChangedListener) {
fusedLocationClientProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
#Override
public void onSuccess(Location location) {
onLocationChangedListener.onLocationChanged(location);
}
});
locationCallback = new LocationCallback() {
#Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
onLocationChangedListener.onLocationChanged(location);
}
}
};
fusedLocationClientProviderClient.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper());
}
#Override
public void deactivate() {
fusedLocationClientProviderClient.removeLocationUpdates(locationCallback);
}
}
I know this is an error that occurs inside onSuccess, but I don't know how to fix it. Help.
check runtime permission for Android. May be this is an issue of permission and due to that you are not able to get location value.

how to add Headless js log geolocation for continuous interval

In Android Manifest I have added all the required permission for geolocation and added the service name as TimeTracking
package com.timetracking;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.react.HeadlessJsTaskService;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
import javax.annotation.Nullable;
public class TimeTracking extends HeadlessJsTaskService {
#Override
protected #Nullable HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
WritableMap data = extras != null ? Arguments.fromBundle(extras) : null;
return new HeadlessJsTaskConfig(
"TimeTracking", // Use the registered headless Task here
data,
500,
true);
}
}
And in app.js page in react native I have called it.
AppRegistry.registerHeadlessTask('TimeTracking', () => TimeTracking);
but nothing is displaying in console.Please can somebody tell the method to get timeInterval of location.
Thanks in advance.

HSQLDB inmemory mode doesn't delete files on shutdown

I'm using HSQLDB version 2.2.9 for testing purposes.
When I create named in memory database, files aren't deleted after calling shutdown function. On my filesystem I have folder DBname.tmp and files DBname.lck, DBname.log, DBname.properties and DBname.script. As I understand documentation (http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_connection_url) it shouldn't happened.
For testing I'm using the following code:
import java.io.IOException;
import org.hsqldb.Server;
import org.hsqldb.persist.HsqlProperties;
import org.hsqldb.server.ServerAcl.AclFormatException;
import org.junit.Test;
public class HSQLDBInMemTest {
#Test
public void test() throws IOException, AclFormatException {
HsqlProperties props = new HsqlProperties();
props.setProperty("server.database.0", "test1");
props.setProperty("server.dbname.0", "test1");
props.setProperty("server.database.1", "test2");
props.setProperty("server.dbname.1", "test2");
Server hsqlServer = new Server();
hsqlServer.setRestartOnShutdown(false);
hsqlServer.setNoSystemExit(true);
hsqlServer.setProperties(props);
hsqlServer.start();
hsqlServer.shutdown();
}
}
Answered here: http://sourceforge.net/mailarchive/message.php?msg_id=30881908 by fredt
The code should look like:
import java.io.IOException;
import org.hsqldb.Server;
import org.hsqldb.persist.HsqlProperties;
import org.hsqldb.server.ServerAcl.AclFormatException;
import org.junit.Test;
public class HSQLDBInMemTest {
#Test
public void test() throws IOException, AclFormatException {
HsqlProperties props = new HsqlProperties();
props.setProperty("server.database.0", "mem:test1");
props.setProperty("server.database.1", "mem:test2");
Server hsqlServer = new Server();
hsqlServer.setRestartOnShutdown(false);
hsqlServer.setNoSystemExit(true);
hsqlServer.setProperties(props);
hsqlServer.start();
hsqlServer.shutdown();
}
}
The path for a memory database looks like props.setProperty("server.database.0", "mem:test1");