标签:des android style http io ar os java sp
application name: Custom Permission
pacakage name: com.cust.perm
1) 特权活动 PrivActivity.java
package com.cust.perm; import android.app.Activity; import android.os.Bundle; /** * Created by lsc on 14-11-4. */ public class PrivActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_priv); } }
2 ) 布局文件activity_priv.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Hello from PrivActivity" android:textSize="20dp"/> </LinearLayout>
3)配置文件 AndroidManifest.xml,其中的<permission …… />部分是声明自定义的权限,有权限名字syh.permission.STARTMYACTIVITY,稍后在project2中调用该特权活动privActivity时需要在配置文件中利用该permission名称获取该自定义权限。
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cust.perm" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.cust.perm.CustPermMainActivity" 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=".PrivActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> </intent-filter> </activity> </application> <permission android:name="syh.permission.STARTMYACTIVITY" android:protectionLevel="normal" android:label="Start My Activity" android:description="@string/startMyActivityDesc"></permission> </manifest>
application name: ClientOfCustomPermission
package name: com.client.cust.perm
1)活动ClientCustPermMainActivity.java
package com.client.cust.perm; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; public class ClientCustPermMainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_clientcustperm); } //当调用按钮时,创建一个新Intent,然后设置想要启动的活动的类名称 public void doClick(View view){ Intent intent = new Intent(); intent.setClassName("com.cust.perm","com.cust.perm.PrivActivity");//调用project1中的特权活动 startActivity(intent); } }
2) 布局文件 activity_clientcustperm.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_margin="20dp" tools:context=".ClientCustPermMainActivity$PlaceholderFragment"> <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Launch PrivActivity" android:id="@+id/btn" android:onClick="doClick"/> </LinearLayout>
3) 配置文件 配置文件 AndroidManifest.xml,其中的<uses-permission android:name="syh.permission.STARTMYACTIVITY"/>声明本活动获取自定义权限,有了这句话才可以调用project1中的特权活动
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.client.cust.perm" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.client.cust.perm.ClientCustPermMainActivity" 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> <uses-permission android:name="syh.permission.STARTMYACTIVITY"/> </manifest>
标签:des android style http io ar os java sp
原文地址:http://my.oschina.net/liusicong/blog/340785