android-permissions

Android UsageStatsManager: Get a list of currently running apps on phone

老子叫甜甜 提交于 2020-01-13 16:54:39
问题 I am trying to get a list of currently running apps on my phone. Here is the code I am using: if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { UsageStatsManager usm = (UsageStatsManager)this.getSystemService(Context.USAGE_STATS_SERVICE); long time = System.currentTimeMillis(); List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 10000*10000, time); if (appList != null && appList.size() == 0) { Log.d("Executed app", "########

How to hide bottom system bar in android tablet

不问归期 提交于 2020-01-13 10:25:50
问题 I am developing an application for tablet only, where the requirement is to run the app on the full screen of the tablet. For this I have used following code in my main activity: getWindow().requestFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); This code snippet only removes the title bar and action bar. But in tablets, there is a bottom system bar (having home and back button). I also want to

java.lang.RuntimeException: start failed

只谈情不闲聊 提交于 2020-01-12 14:42:53
问题 I am trying to record audio in one of my Activities using MediaRecorder. Part of the code is shown below. File file = new File(AppConstants.MSGS_DIR, filename); MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(AudioSource.MIC); recorder.setOutputFormat(OutputFormat.THREE_GPP); recorder.setAudioEncoder(AudioEncoder.AMR_WB); recorder.setOutputFile(file.getAbsolutePath()); try { recorder.prepare(); recorder.start(); } catch (IOException e) { System.out.println("Exception: "

java.lang.RuntimeException: start failed

为君一笑 提交于 2020-01-12 14:42:51
问题 I am trying to record audio in one of my Activities using MediaRecorder. Part of the code is shown below. File file = new File(AppConstants.MSGS_DIR, filename); MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(AudioSource.MIC); recorder.setOutputFormat(OutputFormat.THREE_GPP); recorder.setAudioEncoder(AudioEncoder.AMR_WB); recorder.setOutputFile(file.getAbsolutePath()); try { recorder.prepare(); recorder.start(); } catch (IOException e) { System.out.println("Exception: "

Analyze code with Lint for calls that require permissions

你离开我真会死。 提交于 2020-01-12 08:27:08
问题 I am setting my targetSdkVersion to 23 and therefore I want to implement "Requesting permissions at runtime". (see here) Lint directly calls out if you forget to check the permission and tells you the following: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission ) or explicitly handle a potential `SecurityException' This is quite nice and I want to analyze my code for any call that I may have forgotten,

Android M - custom permission dialog style

落爺英雄遲暮 提交于 2020-01-11 10:21:37
问题 While implementing the new Android M permission model I noticed that the permissions dialog does not respect the theming of my styles.xml. In my styles.xml I override the dialog and alertdialog style like this: <item name="android:dialogTheme">@style/Theme.dialog</item> <item name="android:alertDialogTheme">@style/Theme.dialog</item> Is it possible to change the theming? Or is it because this is a system dialog like in the device settings? 回答1: No, it's not possible. The permissions dialog is

Intent custom permission not working

纵然是瞬间 提交于 2020-01-11 04:00:26
问题 UPDATE My immediate problem is solved as per my answer below. My environment (PC + devices) does not allow custom permissions in DEBUG builds. I'm convinced I was able to run DEBUG builds fine a few weeks ago - hence the description of an "intermittent" error. UPDATE 2 The code synced out on a different developer's machine, works fine on his device in DEBUG mode through Eclipse. On my devices, it does not work from his machine. Also the DEBUG build from my machine works fine on this other

Android request ACCESS_NOTIFICATION_POLICY and mute phone

我只是一个虾纸丫 提交于 2020-01-10 20:03:09
问题 I am a beginner Android developer and I have an interesting question at hand. I am trying to mute the phone with AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); But I am getting the following error java.lang.SecurityException: Not allowed to change Do Not Disturb state Now I do not understand this, as I am using EasyPermissions (https://github.com/googlesamples

API 26+: WRITE_EXTERNAL_STORAGE permission is always denied

假如想象 提交于 2020-01-10 08:10:30
问题 I have switched my app to target API 27 and now it can't be granted WRITE_EXTERNAL_STORAGE permission -- grantResult is always -1 . My app needs this permission since it doesn't use apps private external storage space (which doesn't require WRITE_EXTERNAL_STORAGE starting from API 19). I know that in API 26 there have been behavior changes for permissions. However this doesn't explain my problem. I'm requesting both READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions in a standard

java.io.filenotfoundexception open failed eacces (permission denied) on device

馋奶兔 提交于 2020-01-09 19:08:20
问题 The following code which consists of downloading a file from a server and save it in the storage works fine when the device has an internal storage. But when I tried it with a device with no internal storage, only with external storage I get the following exception. java.io.filenotfoundexception open failed eacces (permission denied) public void downloadFile(String dlUrl, String dlName) { int count; HttpURLConnection con = null; InputStream is = null; FileOutputStream fos = null; try { URL