I am trying make my own permission for android application.
For this my android manifest file looks like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.happybirthday" >
<permission
android:name="com.example.hp.happybirthday.PERM"
android:description="#string/pdesc"
android:label="#string/CAREFUL"
/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:permission="com.example.hp.happybirthday.PERM">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The problem that I am facing is that I want to have my own permission associated with this application and hence i have added the following line as shown above under the application tag, so that only those activities have access to this app which possess my defined permission.
android:permission="com.example.hp.happybirthday.PERM"
But the problem is that when I try to run my app, the app whose manifest file I have declared, it shows the error app is not installed.
But when I remove the above mentioned line, it works, but then any activity will have access to this app which I do not want.
when I try to run my app, the app whose manifest file I have declared, it shows the error app is not installed
That is because the home screen is an app, and the home screen does not hold your custom permission. Hence, the home screen cannot start your launcher activity.
then any activity will have access to this app which I do not want
First, custom permissions do not work all that well.
Second, permissions are usually applied at a finer granularity than "this app". You only secure those components that need the security, and you leave public other components, like the launcher activity.
It looks like you've defined the permission, and set it to be required... but you haven't actually granted it to your own app. Add a uses-permission tag
Related
I am working on an AAOS (Android Automotive OS) platform. The OS version is 10.
I included "DirectRenderingCluster" in my car_product/build/car.mk as
PRODUCT_PACKAGES += DirectRenderingCluster.
In this App, there is a ClusterRenderingService, which implements InstrumentClusterRenderingService.
In InstrumentClusterRenderingService, it will try to gather some information of the suitable navigation App from the PackageManager. Originally, it will pick the FakeClusterNavigationActivity in EmbeddedKitchenSinkApp.
I want to replace the FakeClusterNavigationActivity with my own navigation App.
I mimicked it and made a similar activity.
However, I am getting error messages printed at line 153 and 299 of InstrumentClusterRenderingService.
What do I miss? What should I do to make the Car service recognize my App is an eligible navigation App for cluster? Thank you.
My AndroidManifest.xml looks like as follows. The targetSdkVersion is 29.
<manifest
package="com.mytest.android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="1.0"
android:versionCode="1"
android:installLocation="auto"
android:sharedUserId="android.uid.system">
<application
android:hardwareAccelerated="true"
android:directBootAware="true"
android:persistent="false"
android:name="com.mytest.android.NaviApp"
android:label="#string/application_label"
android:icon="#drawable/icon">
<!-- Activity for cluster. Note that this is not the only activity in this App. -->
<activity android:process=":map_surface"
android:name=".MapSurfaceActivity"
android:label="MapSurfaceActivity"
android:screenOrientation="landscape"
android:launchMode="singleInstance"
android:allowEmbedded="true"
android:exported="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.car.cluster.NAVIGATION"/>
</intent-filter>
</activity>
<!-- Content provider for images (fake, not functional) -->
<provider android:name=".cluster.ClusterContentProvider"
android:authorities="com.mytest.android.cluster.clustercontentprovider"
android:grantUriPermissions="true"
android:exported="true"/>
It turns out to be Google's bug and has been fixed in the later code.
If the navigation app is launched as non-system user and is not installed for system user, this bug will occur.
In the original code, it uses system user's PackageManager to call getPackageInfo() and queryIntentActivities(). However, the navigation app is not installed for system user (maybe being put in the blacklist), so it won't be found.
To fix, PackageManager.MATCH_ANY_USER flag should be used in getPackageInfo(), and queryIntentActivitiesAsUser() should be used in stead of queryIntentActivities().
I don't know what commits fixed them but they are shown in the master branch.
https://android.googlesource.com/platform/packages/services/Car/+/master/car-lib/src/android/car/cluster/renderer/InstrumentClusterRenderingService.java
The problem occurred overnight. One day, everything worked fine. I shut my computer down and started it back up on another day. However, without changing a thing, I tried to launch my App on the same virtual device I had before and somehow it wont launch because:
"Error running 'app'. Default Activity not found."
My manifest looks like this. I changed the package name and the two activities below (see comments below). The rest is exactly the same.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MyPackageName">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait">
</activity>
<activity android:name=".AnotherActivity" />
<activity android:name=".OneMoreActivity">
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="364e8b3f6acfddf9ad32bed8c1503bb762b19cd5" />
</application>
</manifest>
And normally my app would just start with the Login Activity. However, now it does not. I tried to "Invalidate Caches / Restart". Nothing changed. I restarted AS multiple times. Still, nothing.
Then I tried to change the Launch Options. Current Option was set to "Default Activity". So I tried to change it to a specific one. Namely, the LoginActivity. But then it tells me:
"Error running 'app'. The Activity 'LoginActivity' is not declared in AndroidManifest.xml."
It tells me it's not declared, which it clearly is. Otherwise I wouldn't be able to choose it from the dropdown in the first place. I also tried to start on another Activity. "MainActivity". Still nothing.
What exactly am I doing wrong? Is there maybe a workaround where I can manually get the APK on my virtual device so that I can at least keep working?
Edit
I already tried deleting the .gradle-folder. Sadly this didn't work. I tried pushing it to git and cloning it again in another folder. That didn't work either.
Workaround
So far I've only been able to find a workaround:
Go to Run/Edit Configurations...
Go to General/Launch Options -> Launch: Nothing
Run as you normally would. Android Studio will build the project and install the application to your device, but won't launch it!
Launch your app manually on your device.
Go to Run/Attach Debugger to Android Process.
Choose your app.
Obviously, that's a little bit of a hassle and might make debugging the start of an app more difficult. So I'm still looking for an actual solution.
I've found the answer when I tried to look for a solution to another problem that randomly popped up out of nowhere.
Androidstudio wouldnt load any previews and put warnings in my layouts, because
One or more layouts are missing the layout_width or layout_height attributes.
One solution suggested in
the answer I found for that problem
was to delete all files in
C:\Users\UserName.AndroidStudio3.2\system\caches
Thats what I did and it solved both problems. Guess the developers have some fixing to do.
I'm trying to implement App Shortcuts to my app, but i can't get them work.
My shortcut.xml:
<Shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="shortcut"
android:enabled="true"
android:icon="#drawable/ic_shortcut"
android:shortcutShortLabel="#string/shortcut_label">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example"
android:targetClass="com.example.package.Activity"/>
</shortcut>
manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
<application
android:name=".Application"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:resizeableActivity="false"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".package.Activity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/voice_search_params" />
<meta-data android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
</activity>
So, i do shortcut same as in google example. I can see and click on shortcut, but nothing happens. I've tried different activities, changing activity location, activity action, params, like "exported=true", but nothing changes - in logs i can see only
ActivityNotFoundException: Shortcut could not be started
The only difference between my shortcut log, and google camera shortcut log is path to activity:
I/ActivityManager: START u0 {act=android.intent.action.VIEW flg=0x1000c000 cmp=com.example/.package.Activity}
vs
I/ActivityManager: START u0 {act=android.media.action.STILL_IMAGE_CAMERA flg=0x1000c000 cmp=com.google.android.GoogleCamera/com.android.camera.activity.CameraImageActivity}
Google cam has full path to activity, but package path differs.
PS: tried today google sample, static app shortcuts doesn't work in sample too. Dynamic app shortcuts work well.
In addition to Matin's answer, if you have multiple build types that change your application id, it won't work.
In my case, I had .debug and .qa suffix for application id. You can't reference to string reference or use variables inside intent element.
I found two solutions:
1) You will create different shortcuts.xml file for different build types and update your targetPackage.
For example,
<intent
android:action="com.example.ACTION"
android:targetClass="com.example.MainActivity"
android:targetPackage="com.example.debug"/>
2) There is a plugin that allows you to use applicationId variable in your XML file.
https://github.com/timfreiheit/ResourcePlaceholdersPlugin
android:targetPackage have to contain your application ID. So if you have defined your app id in build.gradle as applicationId "com.my.app.id" you have to use android:targetPackage="com.my.app.id"
Change the package name on your Activity to:
android:name=".Activity"
Change your shortcut target class to:
android:targetClass="com.example.Activity"
I also met this problem. Then i found that android:targetClass is not right path.
android:targetClass="com.example.camille.testappshortcuts.Main"
Main is app's access.
Maybe you should change Activity to another name, then add it.
i'm deploying an android application (Android 4.0.3) and when I press the home screen the application doesn't stay on the recent apps list. I've noticed that when I restart the application, it starts on the last screen i've navigated before press the home button. Anyone can help? Here is me Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/logo_home"
android:allowBackup="true">
<activity
android:name="com.test.activity.CommunicatorActivity"
android:launchMode="singleTop"
android:label="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.test.activity.InputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.SettingsActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.OutputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
</application>
</manifest>
I'm going to go out on a limb and suggest that this is your problem:
android:label=""
In your root activity CommunicatorActivity you've set the label to be an empty string. This label is used to identify your app in the list of available apps and because it is empty, this may be causing it not to show up in the list of recent apps.
Remove android:excludeFromRecents="true" from your manifest
You should use
android:label="your app_name"
2 things
Ok, there isn't something obvious in your manifest that should prevent it from appearing in your recents list.
1. Wrong identification
It's not always straight forward to tell which task contains your activity, using the GUI.
One of the possibilities is that an activity from some other app is on top of your task making you believe that your activity isn't there. Since, clearly it resumes to the last screen.
I suggest you to remove the single top temporarily and check the same.
2. Launcher modification
Has the launcher you use the standard launcher? Has the launcher or some other app modified the presentation or behavior of the recents screen (unlikely but worth a check)
For this, I suggest using a stock launcher or try the same app on a different phone or an emulator.
What would help is steps you followed and some screen shots of recents
screen and also of your app
I had the same problem.
The reason is that I had set android:label="" in manifest.xml.
I hadn't set android:launchMode="singleTop".
I declared on purpose android:label="" because I didn't find any better way to remove the title of the action bar from my main activity.
I turned android:label="app_name" again and everything now is OK; the app appears again in recent app list when pressing the home screen and doesn't start on the last navigated screen when restarting it.
I'm having a problem with my app after changing the default activity in the manifest. This is the manifest after i changed it. As far as i can see it's syntactically correct.
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".loginActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="CouncilPlannerActivity"></activity>
<activity android:name="MainTabActivity"></activity>
<activity android:name="MapTabActivity" android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:name="NodeFormActivity"></activity>
<activity android:name="viewNewsActivity"></activity>
</application>
The problem is when i deploy the app to my device it works fine first time. However, when i close the app with the home button it refuses to open again. Clicking the icon in the devices app list doesn't do anything.
If i change the default activity to the one it was at originally it works fine. Is this a bug or is there another reference to a default activity that i'm missing?
I'm developing on Android 2.2 if that makes a difference.
I just noticed the logcat spits out an error when i try to open the app : "Permission Denied: checkComponentPermission() reqUID10064"
You probably need to post the loginActivity in question here so we can see if there are any problems in the activity. Otherwise double check that the loginActivity is in the same package as the other activities, if its not you need to change the ".loginActivity" part of the manifest to its relative location to the main package, aka "somename.loginActivity"
I think the problem is in loginActivity class. May be you check for already loggined user and finish activity in this case?