Tuesday 30 July 2019

How to Debug android App over WIFI(without Root) in android studio Adb

1.you need to connect your device to your computer via USB cable .Make sure Debugging is working .you can check if it shows up when running    adb devices.

C:\Users\Developer\AppData\Local\Android\Sdk\platform-tools>adb devices
        List of devices attached
        S980601711B01366        device


2.Run adb tcpip 5555

C:\Users\Developer\AppData\Local\Android\Sdk\platform-tools>adb tcpip 5555  
      restarting in TCP mode port: 5555

2.Disconnect your device(remove the usb )

4.Go to the settings ->About phone ->status view the IP address of your phone .

5.Run adb connect <IP address of uour device here>:5555

C:\Users\Developer\AppData\Local\Android\Sdk\platform-tools>adb connect 192.168.1.100:5555   
     connected to 192.168.1.100:5555

6.If you run adb devices again ,you should see your device.
C:\Users\Developer\AppData\Local\Android\Sdk\platform-tools>adb devices
        List of devices attached
        192.168.1.100:5555       device

Now you can execute adb command or use IDE for android .

Friday 10 May 2019

Fix MTP driver Installation on Windows 10

Fix MTP driver Installation on Windows 10

C:\Windows\INF\wpmdmtp.inf

wpmdmtp.inf is a file related to MTP and installing it manually can possibly 
resolve your issues is a file related to MTP and installing it manually can 
possibly resolve your issues

Right-click on the wpmdmtp.inf file and select Install
now the problem solved.

Thursday 9 May 2019

How to get string if length is more than 50 after 50 it split into another string ?

String st = "A string is a data type used in programming,
 such as an integer and floating point unit,
but is used to represent text rather than numbers";
if (st.length() > 50) {
    int comma = st.indexOf(',', 50);
    if (comma >= 0) {

        //Bit before comma        String partOne = st.substring(0, comma);

        //Bit after comma        String partTwo = st.substring(comma);
        Log.e("string partOne", partOne);
        Log.e("string partTwo", partTwo);
    }
}

Parses a specific value from string against a specific key for xml format data l̥

 Parses a specific value from string against a specific key for xml format data l̥

private String getValueFromString(String key, String input) {
    if (!AppUtility.isNullOrEmpty(input)) {
        try {
            String match = key.toLowerCase() + "=\"";
            String[] dataArray1 = input.split(match);
            String[] dataArray2;
            if (dataArray1 != null && (dataArray1.length > 0)) {
                int size = dataArray1.length;
                if (size > 1) {
                    dataArray2 = dataArray1[1].split("\"");
                    return dataArray2[0].trim();
                } else {
                    match = key.toUpperCase() + "=\"";
                    dataArray1 = input.split(match);
                    if (dataArray1 != null && (dataArray1.length > 0)) {
                        size = dataArray1.length;
                        if (size > 1) {
                            dataArray2 = dataArray1[1].split("\"");
                            return dataArray2[0].trim();
                        }
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return " ";/*empty string*/
}

Tuesday 9 April 2019

Add quotation at the start and end of each line of string word in Notepad++ and make array in java

1.Find (in regular expression mode):
        (.+)

        Replace with:
        "\1"
        This adds the quotes:
        "amit"        "programming "        "code "        "tech"        
 2.Find (in extended mode):
        \r\n

   Replace with (with a space after the comma, not shown):
        ,

  This converts the lines into a comma-separated list:
        "amit", "programming", "code", "tech"

Number format in indian style RS in java android

import java.text.Format;
import java.text.NumberFormat;
import java.util.Locale;

Code:-

Format format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
     
Log.e("valueindianstyle",format.format("10000000"));

OUTPUT: Rs 1,00,00,000

Monday 1 April 2019

move a file into another directory location in android with java programmatically


/*move a file into another directory location in android with programmatically*/
   private void moveFile(File file, File dir, File deteleold) throws IOException {
    File newFile = new File(dir, file.getName());
    FileChannel outputChannel = null;
    FileChannel inputChannel = null;
    try {
        outputChannel = new FileOutputStream(newFile).getChannel();
        inputChannel = new FileInputStream(file).getChannel();
        inputChannel.transferTo(0, inputChannel.size(), outputChannel);
        inputChannel.close();
        file.delete();/*remove the file */
    } finally {
        if (inputChannel != null) inputChannel.close();
        if (outputChannel != null) outputChannel.close();
    }

}

Thursday 10 January 2019

Get RecyclerViewAdapter onclick position in main activity

You can achieve this by creating an interface inside 
your adapter for an itemclicklistener and then you can
 set onItemClickListener from your MainActivity.

Somewhere inside your RecyclerViewAdapter you would
 need the following:



private onRecyclerViewItemClickListener mItemClickListener;


public void setOnItemClickListener(onRecyclerViewItemClickListener mItemClickListener) {

    this.mItemClickListener = mItemClickListener;
}


public interface onRecyclerViewItemClickListener {

    void onItemClickListener(View view, int position);
}


Then inside your ViewHolder (which I've added as an inner class inside my adapter),
 you would apply the listener to the components you'd like the user to click, like so:

 class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public ImageView imageview;

    RecyclerViewHolder(View view) {

        super(view);

        this.imageview = (ImageView) view

                .findViewById(R.id.image);

        imageview.setOnClickListener(this);
    }


    @Override

    public void onClick(View v) {

        if (mItemClickListener != null) {

            mItemClickListener.onItemClickListener(v, getAdapterPosition());
        }
    }
}

This example shows an onClickListener being applied to the image inside a ViewHolder.
To implement this code, you would setOnItemClickListener to your adapter 
inside MainActivity as shown above.


 recyclerView.setAdapter(adapter);// set adapter on recyclerview

            adapter.notifyDataSetChanged();// Notify the adapter

            adapter.setOnItemClickListener(new RecyclerViewAdapter.onRecyclerViewItemClickListener() {

    @Override

    public void onItemClickListener(View view, int position) {

        Switch (view.getId()) {

            case R.id.letter:
                //logic here
                break;

            case R.id.firstname:
                //logic here
                break;
        ....            

        }
    }
});

Wednesday 9 January 2019

How to use fragment method in Main Activity class


Create interface
public interface ListenFromActivity {    void doSomethingInFragment();}
In Activity class keep refrence of ListenFromActivity interface
public ListenFromActivity activityListener;   
Make public method to set listener
public void setActivityListener(ListenFromActivity activityListener) {        this.activityListener = activityListener;    }
Add some trigger point in activity class, here I have used user interaction
   @Override    public void onUserInteraction() {        super.onUserInteraction();
        if (null != activityListener) {            activityListener.doSomethingInFragment();        }    }

Now in Fragment class
make your fragment implement interface class
public class SomeFragment extends Fragment implements ListenFromActivity
Android studio will prompt you to implement method of interface in fragment
void doSomethingInFragment(){//Add your code here }
Final part part listener instance to activity like this in fragment onCreate method
((ListnerActivity) getActivity()).setActivityListener(SomeFragment.this);
DONE!!. now you can call fragment method from activity.