Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限”吧!

10年積累的網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先建設(shè)網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有揭東免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

一、使用同一個shareuserid,多個apk運(yùn)行到同一個進(jìn)程,實(shí)現(xiàn)多個apk之間的數(shù)據(jù)訪問


    實(shí)現(xiàn)效果:把A.apk assets目錄下的session.log拷貝到/data/data/A包名/目錄下面

A.apk

Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.demo1" android:sharedUserId="com.example" android:versionCode="1" android:versionName="1.0" > <uses-sdk     android:minSdkVersion="8"     android:targetSdkVersion="15" /> <application     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/AppTheme" >     <activity           android:name=".MainActivity"           android:label="@string/title_activity_main" >           <intent-filter>           <action android:name="android.intent.action.MAIN" />                     <category             android:name="android.intent.category.LAUNCHER" />           </intent-filter>      </activity>      </application>      </manifest>

B.apk(實(shí)現(xiàn)訪問資源并且拷貝)
MainActivity.java

package com.example.demo2;     import java.io.File;     import java.io.FileOutputStream;     import java.io.IOException;     import java.io.InputStream;     import java.io.OutputStream;     import android.os.Bundle;     import android.app.Activity;     import android.content.Context;     import android.content.pm.PackageManager.NameNotFoundException;     import android.view.Menu;     import android.view.MenuItem;     import android.support.v4.app.NavUtils;     public class MainActivity extends Activity {         @Override         public void onCreate(Bundle savedInstanceState) {             super.onCreate(savedInstanceState);             setContentView(R.layout.activity_main);             Context context = null;             InputStream input = null;             OutputStream output = null;             try {                 context = this.createPackageContext("com.example.demo1",                         Context.CONTEXT_IGNORE_SECURITY);                 File file = new File("/data/data/com.example.demo1/session.log");                 if (!file.exists()) {                     file.createNewFile();                 }                 input = context.getAssets().open("session.log");                 output = new FileOutputStream(file);                 byte[] buffer = new byte[1024];                 int readLength = 0;                 while((readLength = input.read(buffer)) != -1){                     output.write(buffer, 0, readLength);                 }             } catch (Exception e) {                 // TODO Auto-generated catch block                 e.printStackTrace();             }             finally{                 try {                     if(input!=null || output!= null){                         input.close();                         output.close();                         input = null;                         output = null;                     }                 } catch (Exception e2) {                     // TODO: handle exception                 }             }         }               @Override         public boolean onCreateOptionsMenu(Menu menu) {             getMenuInflater().inflate(R.menu.activity_main, menu);             return true;         }           }

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"         package="com.example.demo2"         android:versionCode="1"         android:versionName="1.0"         android:sharedUserId="com.example">         <uses-sdk             android:minSdkVersion="8"             android:targetSdkVersion="15" />         <application             android:icon="@drawable/ic_launcher"             android:label="@string/app_name"             android:theme="@style/AppTheme" >             <activity                 android:name=".MainActivity"                 android:label="@string/title_activity_main" >                 <intent-filter>                     <action android:name="android.intent.action.MAIN" />                     <category android:name="android.intent.category.LAUNCHER" />                 </intent-filter>             </activity>         </application>     </manifest>

A.apk,B.apk使用同一個shareduserid:com.example  
實(shí)現(xiàn)效果:

Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限

二、通過shareduserid來獲取系統(tǒng)權(quán)限
(1)在AndroidManifest.xml中添加android:sharedUserId="android.uid.system"
(2)在Android.mk文件里面添加LOCAL_CERTIFICATE := platform(使用系統(tǒng)簽名)
(3)在源碼下面進(jìn)行mm編譯
這樣生成的apk能夠獲取system權(quán)限,可以在任意system權(quán)限目錄下面進(jìn)行目錄或者文件的創(chuàng)建,其他apk資源的訪問等(注意創(chuàng)建的文件(夾)只有創(chuàng)建者(比如system,root除外)擁有可讀可寫權(quán)限-rw-------)。

三、擴(kuò)展

系統(tǒng)中所有使用android.uid.system作為共享UID的APK,都會首先在manifest節(jié)點(diǎn)中增加 android:sharedUserId="android.uid.system",然后在Android.mk中增加 LOCAL_CERTIFICATE := platform??梢詤⒁奡ettings等

系統(tǒng)中所有使用android.uid.shared作為共享UID的APK,都會在manifest節(jié)點(diǎn)中增加 android:sharedUserId="android.uid.shared",然后在Android.mk中增加 LOCAL_CERTIFICATE := shared。可以參見Launcher等

系統(tǒng)中所有使用android.media作為共享UID的APK,都會在manifest節(jié)點(diǎn)中增加 android:sharedUserId="android.media",然后在Android.mk中增加LOCAL_CERTIFICATE  := media。

到此,相信大家對“Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

當(dāng)前文章:Android中如何利用shared_user_id獲取系統(tǒng)權(quán)限-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://bm7419.com/article46/dgdieg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、企業(yè)建站、小程序開發(fā)、App開發(fā)、網(wǎng)站策劃虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)