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

這篇文章給大家介紹Android中怎么利用shared_user_id獲取系統(tǒng)權(quán)限,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、普蘭店ssl等。為成百上千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的普蘭店網(wǎng)站制作公司

一、使用同一個(gè)shareuserid,多個(gè)apk運(yùn)行到同一個(gè)進(jìn)程,實(shí)現(xiàn)多個(gè)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(如何訪問assets資源文件請(qǐng)看另一篇http://mobile.51cto.com/aprogram-387591.htm)

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使用同一個(gè)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,都會(huì)首先在manifest節(jié)點(diǎn)中增加 android:sharedUserId="android.uid.system",然后在Android.mk中增加 LOCAL_CERTIFICATE := platform。可以參見Settings等

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

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

關(guān)于Android中怎么利用shared_user_id獲取系統(tǒng)權(quán)限就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

新聞標(biāo)題:Android中怎么利用shared_user_id獲取系統(tǒng)權(quán)限
當(dāng)前URL:http://muchs.cn/article16/pisedg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作虛擬主機(jī)、關(guān)鍵詞優(yōu)化、App設(shè)計(jì)、服務(wù)器托管、面包屑導(dǎo)航

廣告

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

微信小程序開發(fā)