Click here to Skip to main content
15,794,629 members
Home / Discussions / Android
   

Android

 
QuestionAndroid Popup Window Pin
Pavlex42-Feb-17 9:09
Pavlex42-Feb-17 9:09 
QuestionPermissions Not Persistent During Across App Startups Pin
Django_Untaken1-Feb-17 21:51
Django_Untaken1-Feb-17 21:51 
AnswerRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan1-Feb-17 23:33
professionalAfzaal Ahmad Zeeshan1-Feb-17 23:33 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 2:06
Django_Untaken2-Feb-17 2:06 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan2-Feb-17 3:21
professionalAfzaal Ahmad Zeeshan2-Feb-17 3:21 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 3:58
Django_Untaken2-Feb-17 3:58 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Richard Deeming2-Feb-17 4:46
mveRichard Deeming2-Feb-17 4:46 
QuestionAlarm Manager Pin
Pavlex429-Jan-17 1:40
Pavlex429-Jan-17 1:40 
I want to check every second if /sys/bus/usb/devices/ directory is empty or it contain files because I want to make text inside app that says otg not connected if directory is empty or to say otg connected if directory contain files and I want to check that outside the app,while it runs in background! I need to check every second if directory is empty or it contain files?

I have crated detection using alarm manager but it doesn't work.It's just repeating "otg connected"

MainActivity.class

Java
public class MainActivity extends AppCompatActivity
{
    private Process suProcess;
    private PendingIntent pendingIntent;

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

        getRoot();
        startAlarm();  
    }

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

        }
    }

    private void startAlarm()
    {
        Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);

        AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        int interval = 1000;
        manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
    }
}


Alarm Receiver.class

Java
public class AlarmReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context,Intent intent)
    {
        File[] listFiles = new File("/sys/bus/usb/devices").listFiles();
        if (listFiles == null) Toast.makeText(context,"otg not connected",Toast.LENGTH_SHORT).show();
        if (listFiles != null) Toast.makeText(context,"otg connected",Toast.LENGTH_SHORT).show();
    }
}

AnswerRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 3:01
mveRichard MacCutchan29-Jan-17 3:01 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 3:13
Pavlex429-Jan-17 3:13 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 3:18
mveRichard MacCutchan29-Jan-17 3:18 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:22
professionalAfzaal Ahmad Zeeshan29-Jan-17 3:22 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 3:47
mveRichard MacCutchan29-Jan-17 3:47 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 4:07
professionalAfzaal Ahmad Zeeshan29-Jan-17 4:07 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:20
professionalAfzaal Ahmad Zeeshan29-Jan-17 3:20 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 4:40
Pavlex429-Jan-17 4:40 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 4:56
professionalAfzaal Ahmad Zeeshan29-Jan-17 4:56 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 5:00
Pavlex429-Jan-17 5:00 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 5:54
Pavlex429-Jan-17 5:54 
AnswerRe: Alarm Manager Pin
David Crow30-Jan-17 11:25
David Crow30-Jan-17 11:25 
GeneralRe: Alarm Manager Pin
Pavlex430-Jan-17 11:40
Pavlex430-Jan-17 11:40 
AnswerRe: Alarm Manager Pin
David Crow30-Jan-17 17:50
David Crow30-Jan-17 17:50 
GeneralRe: Alarm Manager Pin
Pavlex431-Jan-17 11:48
Pavlex431-Jan-17 11:48 
SuggestionRe: Alarm Manager Pin
David Crow31-Jan-17 18:23
David Crow31-Jan-17 18:23 
GeneralRe: Alarm Manager Pin
Pavlex431-Jan-17 21:22
Pavlex431-Jan-17 21:22 

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.