Click here to Skip to main content
15,881,938 members
Home / Discussions / Android
   

Android

 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 3:40
Pavlex429-Jan-17 3:40 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:56
professionalAfzaal Ahmad Zeeshan29-Jan-17 3:56 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 4:00
Pavlex429-Jan-17 4:00 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 4:54
Pavlex429-Jan-17 4:54 
AnswerRe: Alarm Manager Pin
David Crow30-Jan-17 10:25
David Crow30-Jan-17 10:25 
GeneralRe: Alarm Manager Pin
Pavlex430-Jan-17 10:40
Pavlex430-Jan-17 10:40 
AnswerRe: Alarm Manager Pin
David Crow30-Jan-17 16:50
David Crow30-Jan-17 16:50 
GeneralRe: Alarm Manager Pin
Pavlex431-Jan-17 10:48
Pavlex431-Jan-17 10:48 
Why it's not working?

Java
public class MainActivity extends AppCompatActivity
{
    private Process suProcess;
    private static int conn_length = -1;
    File directory = new File("/sys/bus/usb/devices");
    File[] contents = directory.listFiles();

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getRoot();



        FileObserver observer = new FileObserver("/sys/bus/usb/devices")
        {
            @Override
            public void onEvent(int event, String file)
            {
                if(contents.length == conn_length){
                    return;
                }
                else{
                    conn_length = contents.length;
                }

                if(conn_length == 0)
                {

                    Toast.makeText(MainActivity.this,"otg not connected",Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(MainActivity.this,"otg connected",Toast.LENGTH_SHORT).show();
                }
            }
        };
        observer.startWatching();
    }

    private void getRoot()
    {
        try
        {
            suProcess = Runtime.getRuntime().exec("su");
        }
        catch (IOException e)
        {

        }
    }
}

SuggestionRe: Alarm Manager Pin
David Crow31-Jan-17 17:23
David Crow31-Jan-17 17:23 
GeneralRe: Alarm Manager Pin
Pavlex431-Jan-17 20:22
Pavlex431-Jan-17 20:22 
QuestionRe: Alarm Manager Pin
David Crow1-Feb-17 2:14
David Crow1-Feb-17 2:14 
QuestionAndroid OTG Detect App Pin
Pavlex427-Jan-17 10:54
Pavlex427-Jan-17 10:54 
AnswerRe: Android OTG Detect App Pin
Richard MacCutchan27-Jan-17 22:05
mveRichard MacCutchan27-Jan-17 22:05 
QuestionSimple HTTP Post Request - application/json Pin
Django_Untaken27-Jan-17 9:21
Django_Untaken27-Jan-17 9:21 
AnswerRe: Simple HTTP Post Request - application/json Pin
Richard MacCutchan27-Jan-17 22:03
mveRichard MacCutchan27-Jan-17 22:03 
QuestionAndroid USB Detection Pin
Pavlex421-Jan-17 11:18
Pavlex421-Jan-17 11:18 
AnswerRe: Android USB Detection Pin
Afzaal Ahmad Zeeshan21-Jan-17 12:28
professionalAfzaal Ahmad Zeeshan21-Jan-17 12:28 
GeneralRe: Android USB Detection Pin
Pavlex421-Jan-17 12:53
Pavlex421-Jan-17 12:53 
GeneralRe: Android USB Detection Pin
Afzaal Ahmad Zeeshan21-Jan-17 13:00
professionalAfzaal Ahmad Zeeshan21-Jan-17 13:00 
GeneralRe: Android USB Detection Pin
Pavlex421-Jan-17 13:08
Pavlex421-Jan-17 13:08 
GeneralRe: Android USB Detection Pin
Afzaal Ahmad Zeeshan21-Jan-17 13:12
professionalAfzaal Ahmad Zeeshan21-Jan-17 13:12 
GeneralRe: Android USB Detection Pin
Pavlex421-Jan-17 13:36
Pavlex421-Jan-17 13:36 
GeneralRe: Android USB Detection Pin
David Crow24-Jan-17 2:38
David Crow24-Jan-17 2:38 
GeneralRe: Android USB Detection Pin
Jochen Arndt24-Jan-17 3:34
professionalJochen Arndt24-Jan-17 3:34 
GeneralRe: Android USB Detection Pin
Pavlex424-Jan-17 3:41
Pavlex424-Jan-17 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.