-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storage permissions & make presenter calls on UI thread
- Loading branch information
Showing
5 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 32 additions & 2 deletions
34
sample/src/main/java/org/smartregister/p2p/sample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
package org.smartregister.p2p.sample; | ||
|
||
import android.Manifest; | ||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import org.smartregister.p2p.activity.P2pModeSelectActivity; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private String[] permissions = new String[] {Manifest.permission.READ_EXTERNAL_STORAGE | ||
, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
requestPermissions(); | ||
} | ||
|
||
private void requestPermissions() { | ||
if (!arePermissionsGranted()) { | ||
ActivityCompat.requestPermissions(this, permissions, 8348); | ||
} else { | ||
startActivity(new Intent(this, P2pModeSelectActivity.class)); | ||
} | ||
} | ||
|
||
private boolean arePermissionsGranted() { | ||
for (String permission: permissions) { | ||
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { | ||
return false; | ||
} | ||
} | ||
|
||
startActivity(new Intent(this, P2pModeSelectActivity.class)); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters