#StackBounty: #git #android-studio How can I compare two commit in different branches with Git in Android Studio 4.1?

Bounty: 50

I use Git in Android Studio 4.1. There are two commit in different branches.

The first commit is named "TestC 47" located in "TestC" branch, the second commit is named "Dell_Merge 25" located in "master" branch.

I hope to know what are different between "TestC 47" commit and "Dell_Merge 25" commit, how can I do?

Image 1
enter image description here

Image 2

enter image description here


Get this bounty!!!

#StackBounty: #android #android-studio #package-managers #android-package-managers Android studio is making used import statement as un…

Bounty: 50

I have just starting working my android studio project in another pc with same android studio version and it automatically makes used import statement as unused in the code and mark evey code related to particular import statement red. How can i fix this issue , its very annoying. but when i run the project ,it works fine without any error.

I have tried all those tricks including deleting .ide ,.gradle and even restarting with invalidate cash ,restard and disabling automatic import as well.

In the below screenshot , android studio just grayout all import statment i am using below and mark all those classes and its related method red in the code. how can i fix this issue

screenshot


Get this bounty!!!

#StackBounty: #android #android-studio #android-layout Draw partial circle as progress bar in android studio

Bounty: 50

SUMMARY :

Use picture 1 for reference.

I need to keep the grey part under the green part, so that when green decreases, grey becomes visible. But I also want the uncovered part (just grey to not be there). Resulting in a 2/3rd overlapping circle.


I am trying to create 2/3rd circle (with rounded corners) as a progress bar in android studio. I am not able to do it.
I was hoping to get your help.

Current circle: (PICTURE 1)

enter image description here

Circle I need :

enter image description here

Shape:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="ring" android:innerRadiusRatio="2.5" android:useLevel="false"
            android:thicknessRatio="12">
            <solid android:color="#DDD"/>
     </shape>
    </item>
    <item>
        <shape android:shape="ring" android:innerRadiusRatio="2.5" android:useLevel="true"
            android:thicknessRatio="12">
            <solid android:color="@color/colorAccent"/>
        </shape>
    </item>
</layer-list>

Layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    tools:context=".MainActivity">

    <ProgressBar
        android:id="@+id/timerProgressBar"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="1:1"
        android:indeterminateOnly="false"
        android:progressDrawable="@drawable/circle"
        android:rotation="-90"
        app:layout_constraintBottom_toTopOf="@+id/guidelineBottom"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guidelineTop"
        android:progress="10"/>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.5" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.1" />

 
</androidx.constraintlayout.widget.ConstraintLayout>


Get this bounty!!!

#StackBounty: #android-studio #kotlin #android-jetpack Why does LiveData only effect main layout and doesn't LiveData effect child …

Bounty: 50

FragmentHome load layout_home.xml, and layout_home.xml displays a recyclerview and a button named btnMain

recyclerview include the item layout layout_voice_item.xml, it displays a button named btnChild

I use displayCheckBox : LiveData<Boolean> to control whether both btnMain and btnChild are shown or not with the code android:visibility="@{!aHomeViewModel.displayCheckBox? View.VISIBLE: View.GONE}".

I find btnMain can be shown or not when I change the value of displayCheckBox, but btnChild keep to show, why?

FragmentHome.kt

class FragmentHome : Fragment() {

    private lateinit var binding: LayoutHomeBinding

    private val mHomeViewModel by lazy {
        getViewModel {
            HomeViewModel(provideRepository(mContext))
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = DataBindingUtil.inflate(
            inflater, R.layout.layout_home, container, false
        )
        binding.lifecycleOwner = this.viewLifecycleOwner
        binding.aHomeViewModel=mHomeViewModel

        val adapter = VoiceAdapters(mHomeViewModel)
        binding.mvoiceList.adapter=adapter
        mHomeViewModel.listVoiceBySort.observe(viewLifecycleOwner){
          adapter.submitList(it)
        }
        ...
        return binding.root
    }
}

HomeViewModel.kt

class HomeViewModel(private val mDBVoiceRepository: DBVoiceRepository) : ViewModel() {

    private val _displayCheckBox = MutableLiveData<Boolean>(true)
    val displayCheckBox : LiveData<Boolean> = _displayCheckBox

    fun setCheckBox(isDisplay:Boolean){
        _displayCheckBox.value = isDisplay
    }

    ...
}

VoiceAdapters.kt

class VoiceAdapters (private val aHomeViewModel: HomeViewModel):
        ListAdapter<MVoice, VoiceAdapters.VoiceViewHolder>(MVoiceDiffCallback()) {
    ...
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VoiceViewHolder {
        return VoiceViewHolder(
            LayoutVoiceItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        )
    }

    override fun onBindViewHolder(holder: VoiceViewHolder, position: Int) {
        val aMVoice = getItem(position)
        holder.bind(aHomeViewModel, aMVoice)
    }

    inner class VoiceViewHolder (private val binding: LayoutVoiceItemBinding):
          RecyclerView.ViewHolder(binding.root) {

        fun bind(mHomeViewModel: HomeViewModel, aMVoice: MVoice) {
            binding.aHomeViewModel = mHomeViewModel
            binding.executePendingBindings()
        }

    }

    ...
}
class MVoiceDiffCallback : DiffUtil.ItemCallback<MVoice>() {
    ...
}

layout_home.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
        <import type="android.view.View" />

        <variable name="aHomeViewModel"
            type="info.dodata.voicerecorder.viewcontrol.HomeViewModel" />
    </data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/mvoice_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            tools:listitem="@layout/layout_voice_item"            
        />

      <Button
            android:id="@+id/btnMain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"         
            android:visibility="@{!aHomeViewModel.displayCheckBox? View.VISIBLE: View.GONE}"            
        />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

layout_voice_item.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>
    <import type="android.view.View" />
    <variable name="aHomeViewModel"
        type="info.dodata.voicerecorder.viewcontrol.HomeViewModel" />
</data>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
        android:id="@+id/btnChild"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="@{!aHomeViewModel.displayCheckBox? View.VISIBLE: View.GONE}"        
    />

</LinearLayout>
</layout>


Get this bounty!!!

#StackBounty: #android #android-studio String encoding in class library project

Bounty: 100

I am facing a strange problem.

I have a solution that contains an Android project and a class library project.

If in that library project I execute this line:

String s = "Código inválido";

This is actually shown when watching the variable: Código inválido.

However, when I do that assignment inside the Activity code, the text is shown correctly as Código inválido.

What may be wrong with this?

The origin of the problem was when I tried to show, in the Activity layout, a text that was assigned in a class library method. After a lot of digging, I found what I expose in this question.

Just in case, I tell you that all files encodings are UTF-8, and in the project settings all encodings are also UTF-8.

This is Android Studio 4.0.1

Thanks

Jaime


Get this bounty!!!

#StackBounty: #android #android-studio #bluetooth-lowenergy #signals #packet How to track the packets transmitted in Bluetooth Low Ener…

Bounty: 50

I am making an Android app for transmitting and scanning BLE signals for an experiment. I need the metric for how many packets are advertised by the transmitting device and how many are received by the scanning device. Is it possible to obtain these numbers?

Here is my advertisement code :

private void transmit() {   

        disableScanBtn();

        mBluetoothLeAdvertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();



        switch (advParameter){
            case 0 :
                advInterval = AdvertisingSetParameters.INTERVAL_HIGH;
                advSetting = "High";
                break;

            case 1 :
                advInterval = AdvertisingSetParameters.INTERVAL_MEDIUM;
                advSetting = "Medium";
                break;
            case 2 :
                advInterval = AdvertisingSetParameters.INTERVAL_LOW;
                advSetting = "Low";
                break;
            case 3 :

                advInterval = AdvertisingSetParameters.INTERVAL_MIN;
                advSetting = "Min";
                break;
            default:
                advInterval = AdvertisingSetParameters.INTERVAL_MAX;
                advSetting = "Max";
        }

        AdvertisingSetParameters parameters = new AdvertisingSetParameters.Builder()
                .setInterval(advInterval)
                .setTxPowerLevel(AdvertisingSetParameters.TX_POWER_MEDIUM)
                .setConnectable(true)
                .build();

        deviceId = Installation.id ( this );
        ParcelUuid pUuid = new ParcelUuid( UUID.fromString( deviceId ) );
        AdvertiseData data = new AdvertiseData.Builder()
                .setIncludeDeviceName(true)
                .addServiceUuid( pUuid )
                .addServiceData( pUuid, "Data".getBytes( StandardCharsets.UTF_8 ) )
                .build();

        mAdvertiseCallback = new AdvertisingSetCallback () {

            @Override
            public void onAdvertisingSetStarted(AdvertisingSet advertisingSet,
                                                int txPower,
                                                int status) {
                super.onAdvertisingSetStarted (advertisingSet, txPower, status);
            
                Toast.makeText( BluetoothActivity.this, "Started "+ status, Toast.LENGTH_LONG ).show ();

            }

            @Override
            public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {
                Log.e(TAG, "Advertising onStartFailure: ");
                super.onAdvertisingSetStopped (advertisingSet);
            }
        };

        mBluetoothLeAdvertiser.startAdvertisingSet(parameters, data, null,null,null, mAdvertiseCallback);
        mTransmitTime.setText ( String.valueOf (System.currentTimeMillis ()));

    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    private void stopTransmit() {


            enableScanBtn();


        if (mBluetoothLeAdvertiser != null) {
                mBluetoothLeAdvertiser.stopAdvertisingSet(mAdvertiseCallback);

        }
    }

Here is my scanning code:

private final ScanCallback scanCallback = new ScanCallback () {


        @RequiresApi(api = Build.VERSION_CODES.O)
        @Override
        public void onScanResult(int callbackType, ScanResult result) {

            super.onScanResult ( callbackType, result );


            if (mList.size () > 0) {
                try {
                    mList.clear ();
                    mArrayAdapter.clear ();
                    mArrayAdapter.notifyDataSetChanged ();
                    rssi = result.getRssi ();
                    id = result.getDevice ().getAddress ();

                } catch (final Exception e) {
                    e.printStackTrace ();
                }
            }

            if (result == null || result.getDevice () == null) {
                Log.e ( TAG, "-> No devices found" );
                return;
            }

            try {


                name = result.getScanRecord ().getDeviceName ();
                id = result.getDevice ().getAddress ();


                time= System.currentTimeMillis();

                if (String.valueOf ( name ) != "null"){
                    addItemToSheet ( String.valueOf(rssi), id, time );
                }


                String apDetails = "AP: " + name + "n" +
                        "UUID: " + id + "n" +
                        "RSSI: " + rssi + "n" +
                        "Time : " + time;

                Log.i ( TAG, apDetails );

                mList.add ( apDetails );


            } catch (NullPointerException e) {

                Log.e ( TAG, e.getMessage () );
            }

            mArrayAdapter = new ArrayAdapter<> ( getApplicationContext (),
                    android.R.layout.simple_list_item_1, mList );
            mListView.setAdapter ( mArrayAdapter );
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {

            super.onBatchScanResults ( results );
        }

        @Override
        public void onScanFailed(int errorCode) {

            super.onScanFailed ( errorCode );
            Toast.makeText ( BluetoothActivity.this, "onScanFailed: " + String.valueOf ( errorCode ), Toast.LENGTH_LONG ).show ();
        }

    };

Is there a way to count the number of packets in the given code?


Get this bounty!!!

#StackBounty: #java #android #android-studio #broadcastreceiver #alarmmanager AlarmManager and BroadcastReceiver in Android Oreo+

Bounty: 50

I am making an application that notifies the user at certain times of the day. Like an alarm clock. The code works normally in versions prior to Android Oreo.

From what I read, Android Oreo and later versions kill actions in the background and that’s why I’m having the error below.

2020-07-13 20:31:06.766 1609-1737/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:studio.com.archeagemanager flg=0x4000010 (has extras) } to air.br.com.alelo.mobile.android/co.acoustic.mobile.push.sdk.wi.AlarmReceiver

It is as if the BroadcastService is simply not triggered when it should be. But when I open the app, it starts up instantly.

AndroidManifest.xml

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="owner.custom.permission" />
<permission
    android:name="owner.custom.permission"
    android:protectionLevel="signatureOrSystem">
</permission>

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/app_icon_new"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".SplashScreenActivity"
        android:theme="@style/AppCompat.TelaCheia">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <receiver
        android:name=".AlarmReceiver"
        android:enabled="true"
        android:exported="false">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

</application>

TabFragEventA.java (Here I put only the function that initiates the alarm)

public void startAlarm(int eventID) {
    String[] NOTIFICATION_TITLES = {"Ocleera Rift", "Ocleera Rift", "Mistmerrow Conflict", "Mistmerrow Conflict",
            "Mistmerrow Conflict", "Nation Construction Quests", "Diamond Shores", "Diamond Shores", "Battle of the Golden Plains",
            "Battle of the Golden Plains", "Karkasse Ridgelands", "Kraken", "The Mirage Isle Fish Fest", "Red Dragon",
            "Abyssal Attack", "Lusca Awakening", "Delphinad Ghostship", "Cattler Wrangler", "Legendary Chef", "+1"};

    String notificationTitle = getString(R.string.contentTitle);
    String notificationText = NOTIFICATION_TITLES[eventID] + getString(R.string.contentNotificationText);

    int alarmHour = localHour.get(eventID);
    int alarmMinute = localMinute.get(eventID);
    // Decrease 5 minutes
    if(alarmMinute == 0) {
        alarmHour = alarmHour - 1;
        alarmMinute = 55;
    } else {
        alarmMinute = alarmMinute - 5;
    }
    // Setting the alarm moment
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, alarmHour);
    calendar.set(Calendar.MINUTE, alarmMinute);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    // Analyze if the alarm moment has passed
    Calendar actualTime = Calendar.getInstance();
    if(actualTime.getTimeInMillis() >= calendar.getTimeInMillis()) {
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }

    Intent intent = new Intent(getActivity().getApplicationContext(), AlarmReceiver.class);
    intent.putExtra("contentTitle", notificationTitle);
    intent.putExtra("contentText", notificationText);
    /*if(eventID == 11 || eventID == 13) {
        intent.putExtra("specificDayWeek", true);
    } else {
        intent.putExtra("specificDayWeek", false);
    }*/
    if(eventID == 12) {
        intent.putExtra("castleSupply", true);
        intent.putIntegerArrayListExtra("castleSupplyDayWeek", (ArrayList<Integer>) CastleSupply);
    }
    else if(eventID == 13) {
        intent.putExtra("castleClaim", true);
        intent.putIntegerArrayListExtra("castleClaimDayWeek", (ArrayList<Integer>) CastleClaim);
    }
    else if(eventID == 14) {
        intent.putExtra("abyssalAttack", true);
        intent.putIntegerArrayListExtra("abyssalDaysWeek", (ArrayList<Integer>) AbyssalDayWeek);
    }
    else if(eventID == 15) {
        intent.putExtra("luscaAwakening", true);
        intent.putIntegerArrayListExtra("luscaAwakeningDayWeek", (ArrayList<Integer>) LuscaAwakening);
    } else {
        intent.putExtra("abyssalAttack", false);
    }

    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    // PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity().getApplicationContext(), eventID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity().getApplicationContext(), eventID, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}

AlarmReceiver.java

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        String contentTitle = intent.getStringExtra("contentTitle");
        String contentText = intent.getStringExtra("contentText");

        String CHANNEL_ID = "my_channel_01";
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = "Channel Name";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
            notificationManager.createNotificationChannel(mChannel);
        }

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
                .setSmallIcon(R.drawable.icon_notification)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_notification))
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setVibrate(new long[]{800, 500, 600, 300});

        notificationManager.notify(0, notificationBuilder.build());

        Log.d("ALARMRECEIVER", "INSIDE");

    }
}

I would like to know what to do to make the Broadcast Receiver work in the background. Or an alternative to set this alarm clock on Android Oreo + so that it notifies the user even with the application closed or in the background.


Get this bounty!!!

#StackBounty: #java #android #android-studio #kotlin Unable to add library to Android Studio project

Bounty: 150

I’m trying to add this library to Android Studio locally using this tutorial on YouTube.

However, I get errors that I can’t post here because they’re too many (99+).

Can someone tell me step by step (in detail) how to succesfully add this library to my project and be able to edit it afterwards?

This is the main error I get when I try to import this library: Unable to determine constructor argument #1: missing parameter of type Factory, or no service of type Factory<LoggingManagerInternal>.


Get this bounty!!!