Click here to Skip to main content
15,885,546 members
Home / Discussions / Android
   

Android

 
QuestionAndroid Popup Window Pin
Pavlex42-Feb-17 8:09
Pavlex42-Feb-17 8:09 
QuestionPermissions Not Persistent During Across App Startups Pin
Django_Untaken1-Feb-17 20:51
Django_Untaken1-Feb-17 20:51 
AnswerRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan1-Feb-17 22:33
professionalAfzaal Ahmad Zeeshan1-Feb-17 22:33 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 1:06
Django_Untaken2-Feb-17 1:06 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Afzaal Ahmad Zeeshan2-Feb-17 2:21
professionalAfzaal Ahmad Zeeshan2-Feb-17 2:21 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Django_Untaken2-Feb-17 2:58
Django_Untaken2-Feb-17 2:58 
GeneralRe: Permissions Not Persistent During Across App Startups Pin
Richard Deeming2-Feb-17 3:46
mveRichard Deeming2-Feb-17 3:46 
QuestionAlarm Manager Pin
Pavlex429-Jan-17 0:40
Pavlex429-Jan-17 0: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 2:01
mveRichard MacCutchan29-Jan-17 2:01 
GeneralRe: Alarm Manager Pin
Pavlex429-Jan-17 2:13
Pavlex429-Jan-17 2:13 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 2:18
mveRichard MacCutchan29-Jan-17 2:18 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 2:22
professionalAfzaal Ahmad Zeeshan29-Jan-17 2:22 
GeneralRe: Alarm Manager Pin
Richard MacCutchan29-Jan-17 2:47
mveRichard MacCutchan29-Jan-17 2:47 
GeneralRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 3:07
professionalAfzaal Ahmad Zeeshan29-Jan-17 3:07 
AnswerRe: Alarm Manager Pin
Afzaal Ahmad Zeeshan29-Jan-17 2:20
professionalAfzaal Ahmad Zeeshan29-Jan-17 2:20 
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 
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 

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.