The app used to run. However, just recently it began to stop working. The device is running Android Nutella. Below is the LogCat.
java.lang.SecurityException: Permission Denial: reading com.google.android.music.store.ConfigContentProvider uri content://com.google.android.music.ConfigContent/one-key/2/ExplicitRestrictedByParentControl from pid=2500, uid=10373 requires the provider be exported, or grantUriPermission()
The app crashes in the the following code snippet on the last line(contained in a SongParser method).
String[] projection2 = {MediaStore.Audio.Media.ARTIST};
Uri songUri=null;
try {
songUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
} catch (NullPointerException e){
e.printStackTrace();
}
if (songUri!=null) {
CursorLoader cl2 = new CursorLoader(context,
songUri, projection2, null, null, null);
cursor = cl2.loadInBackground();
I grant the Uri permissions in the following method after asking for permissions through the runtime permissions methods.
private void startService() {
//start intent to RssService for feedback
intent = new Intent(getActivity(), SongService.class);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
getContext().grantUriPermission("xxx.xxx.xxx.SongService",Uri.parse("content://com.google.android.music.MusicContent/audio"),Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(SongService.RECEIVER, resultReceiver);
getActivity().startService(intent);
}
Here is where SongService calls SongParser.
#Override
protected void onHandleIntent(Intent intent) {
List<String> eventItems= null;
if (haveNetworkConnection()) {
parser = new SongParser();
eventItems = parser.getAllArtists(getApplicationContext());
}
Bundle bundle = new Bundle();
bundle.putSerializable(ITEMS, (Serializable) eventItems);
ResultReceiver receiver = intent.getParcelableExtra(RECEIVER);
receiver.send(0, bundle);}}
I have contained the permissions in the manifest as well. Again, this exception seemingly happened on its own.
<permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
What's happening is that for some reason, the (exported) MusicContent provider will redirect to ConfigContentProvider, which is not exported.
It seems that the way to solve it is to open Google Play Music. If you haven't launched it in a while, it will redirect to com.google.android.music.store.ConfigContentProvider and trigger a SecurityException. It's kind of problematic but at least I can tell my users what to do. Let me know if you can come up with something better.
It might also be a good idea to file a bug.
You do not have access to that ContentProvider. It is not exported, and that app did not pass you a Uri that you can use to access it.
Since presumably the Uri is from an app that you did not write, apparently an update to that app changed this behavior.
Related
When I try to get broadcast for incomming call:
BroadcastReceiver br = new MyBroadcastReceiver();
IntentFilter filter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
filter.addAction(Intent.ACTION_SCREEN_OFF);
MainApplication.getAppContext().registerReceiver(br, filter);
I got an error when doing or receiving a call:
W/System: A resource failed to call release.
The ACTION_SCREEN_OFF works fine, but ACTION_PHONE_STATE_CHANGED do not. My APP has a webRTC connection open. In other APP that dosen't work with webRTC, ACTION_PHONE_STATE_CHANGED works fine.
I'm trying to make the audio back to speaker after a incomming call.
Some clue? Thanks!
The problem was that I haven't set uses-permission in the manifest.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
And of course, you have to ask the user to use the PHONE_STATE.
React-native way:
(async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE,
{
'title': 'ReactNativeCode Location Permission',
'message': 'ReactNativeCode App needs access to your phone state '
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
Alert.alert("Location Permission Granted.");
}
else {
Alert.alert("Location Permission Not Granted");
}
} catch (err) {
console.warn(err)
}
})()
I have permissions for read and writing on AndroidManifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
... because I want to copy one file. I'm performing this process in two steps:
1. Launching an Intent so the user creates the file where he wants:
This code is mostly the example of the Android developers site.
private void createFile() {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/vnd.sqlite3");
intent.putExtra(Intent.EXTRA_TITLE, "test.db");
startActivityForResult(intent, CREATE_FILE);
}
2. Copy the file.
The intent returns a Uri, so inside the onActivityResult:
try {
destinationOutputStream = getContentResolver().openOutputStream(data.getData());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
(where data is the Intent), I'm able to get the output stream.
Finally, and according to the documentation, I should be able to copy the file:
try {
Long totalBytes = Files.copy(originalPath, destinationOutputStream);
} catch (IOException e) {
e.printStackTrace();
}
(where originalPath is the path (of type Path) where the original file is stored).
But, on runtime, I'm getting the following error:
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
I am trying to build a parental control app. So now i want to disable or lock app (like Whatsapp, Facebook, etc). I have tried using PackageManager.setComponentEnabledSetting(). But it is throwing java.lang.SercurityException.
So how can I make a parental control app such that I can disable any app I want without root.
my code is
pm.setComponentEnabledSetting(new ComponentName(temp.activityInfo.packageName,
temp.activityInfo.name+".class"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
my error was this
java.lang.SecurityException: Permission Denial: attempt to change component state from pid=11537, uid=10067, package uid=10029
You must add below permissions to manifest.
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
but , these permissions are for System apps and you can not use. :(
You can not write a app to lock or close another app.this is a policy in Google.
for lock a app you must check running apps repeatedly, if specific app is open,then show a activity over that.
while(!Thread.currentThread().isInterrupted())
{
String topActivity = getFrontApp();
if(topActivity.isEmpty())
{
threadSleep(500);
continue;
}
if(topActivity.equals("lockApp"))
{
showLockActivity();
}
threadSleep(500);
}
// for Api21+ need permission
public static String getFrontApp()
{
if (Build.VERSION.SDK_INT >= 21)
{
UsageStatsManager usageManager = SystemMaster.getUsageStatsManager();
long now = System.currentTimeMillis();
List<UsageStats> localList = usageManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, now - 900_000L, now);
String str = "";
if (localList != null)
{
SortedMap<Long,UsageStats> mySortedMap = new TreeMap<>();
for(UsageStats usageStats : localList)
mySortedMap.put(usageStats.getLastTimeUsed(), usageStats);
if(!mySortedMap.isEmpty())
str = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
}
return str;
}
else
{
ActivityManager am = (ActivityManager) getApplication().getSystemService(Context.ACTIVITY_SERVICE);
return am.getRunningTasks(1).get(0).topActivity.getPackageName();
}
above code is very simple , for real app must write more.
I am trying to send a crash report from an android application and it is opening a email client and entering com.x.x Crash Report in the email body. I cant seem to be able to get any other information in the email. The docs dont have a complete email example and i have reportContent added (but APP_VERSION is not resolving). I have also updated my manifest file with READ_PHONE_STATE
I'm referencing this https://github.com/ACRA/acra/wiki/AdvancedUsage#choosing-which-fields-to-be-included-in-reports.
Any help would be appreciated
Manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Application
#AcraCore(
reportContent = { /*APP_VERSION,*/ ANDROID_VERSION, PHONE_MODEL, CUSTOM_DATA, STACK_TRACE, LOGCAT}
)
#AcraMailSender(mailTo = "X#protonmail.com")
public class MyApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ACRA.init(this);
}
I know this is dead post, nevertheless there's mistake in ACRA's site, example should be reading:
#AcraCore(
buildConfigClass = org.acra.BuildConfig.class,
logcatArguments = {"-t", "200", "-v", "time"},
reportFormat= StringFormat.JSON,
reportContent = {
ReportField.USER_COMMENT,
ReportField.APP_VERSION_NAME,
ReportField.APP_VERSION_CODE,
ReportField.ANDROID_VERSION,
ReportField.PHONE_MODEL,
ReportField.CUSTOM_DATA,
ReportField.STACK_TRACE,
ReportField.LOGCAT }
)
#AcraMailSender(
mailTo = "email#domain.com"
)
I used Crashlytics instead as suggested by #gabe-sechan
I want to sent SMS with my Application with :
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
smsIntent.setData(Uri.parse("smsto:" + sms));
smsIntent.putExtra("smsto", sms);
smsIntent.putExtra("sms_body", "MYSMSBOBY");
mActivity.startActivity(smsIntent);
It's work fine in devices that there is SMS Application, but in some devices i get this crash error:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=smsto:xxxxxxxxxx flg=0x10000000 (has extras) }
Any idea how i can recognize if SMS Application installed on the device?
Any idea how i can recognize if SMS Application installed on the device?
While you can use PackageManager to see if there's any app to handle your intent, that's should not be really of your concern at all. What you should take care of is just the crash itself, so instead of just:
mActivity.startActivity(smsIntent);
you should at least have generic exception handling code:
try {
mActivity.startActivity(smsIntent);
} catch ( Exception e ) {
e.printStackTrace();
// show toast or something so user knows why it is not working
}
and catch any failure of startActivity(). You may also want to make create separate catch for this particular type of exception, ActivityNotFoundException
<!-- SMS -->
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
/**
* Test if device can send SMS
* #param context
* #return
*/
public static boolean canSendSMS(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
}