broadcastreceiver - Which is the better way to define permission in android? -


i want start activity on_boot_completed. facing 1 strange problem.

if specify boot permission outside of receiver tag, outside of application tag. activity gets started. following

<uses-sdk     android:minsdkversion="8"     android:targetsdkversion="16" /> <uses-permission android:name="android.permission.receive_boot_completed" /> <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.example.broadcaststaticdemo.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>     <receiver android:name="com.example.broadcaststaticdemo.startapponboot" > <intent-filter>     <action android:name="android.intent.action.boot_completed" />     <category android:name="android.intent.category.home" /> </intent-filter> 

if specify permission inside receiver tag activity not started. following

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.broadcaststaticdemo" android:versioncode="1" android:versionname="1.0" > <uses-sdk     android:minsdkversion="8"     android:targetsdkversion="16" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.example.broadcaststaticdemo.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>     <receiver android:name="com.example.broadcaststaticdemo.startapponboot"         android:permission="android.permission.receive_boot_completed" > <intent-filter>     <action android:name="android.intent.action.boot_completed" />     <category android:name="android.intent.category.home" /> </intent-filter> 

while have used second approach (permission inside receiver tag) in other application working fine. confused difference between specifying permission @ application level , receiver level. have seen android documentation have mentioned

the name of permission broadcasters must have send message broadcast receiver. if attribute not set, permission set element's permission attribute applies broadcast receiver. if neither attribute set, receiver not protected permission. mean can specify where. appriciated

when use <uses-permission android:name="android.permission.receive_boot_completed" /> gives application ability talk interfaces require receive_boot_complete permission.

but when assign attribute android:permission in <receiver> stating interfaces broadcast receiver requires permission receive_boot_complete. more info here http://developer.android.com/guide/topics/manifest/receiver-element.html#prmsn.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -