In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
本篇内容主要讲解"Android中如何利用shared_user_id获取系统权限",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Android中如何利用shared_user_id获取系统权限"吧!
一、使用同一个shareuserid,多个apk运行到同一个进程,实现多个apk之间的数据访问
实现效果:把A.apk assets目录下的session.log拷贝到/data/data/A包名/目录下面
A.apk
AndroidManifest.xml
B.apk(实现访问资源并且拷贝)
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
A.apk,B.apk使用同一个shareduserid:com.example
实现效果:
二、通过shareduserid来获取系统权限
(1)在AndroidManifest.xml中添加android:sharedUserId="android.uid.system"
(2)在Android.mk文件里面添加LOCAL_CERTIFICATE := platform(使用系统签名)
(3)在源码下面进行mm编译
这样生成的apk能够获取system权限,可以在任意system权限目录下面进行目录或者文件的创建,其他apk资源的访问等(注意创建的文件(夹)只有创建者(比如system,root除外)拥有可读可写权限-rw-------)。
三、扩展
系统中所有使用android.uid.system作为共享UID的APK,都会首先在manifest节点中增加 android:sharedUserId="android.uid.system",然后在Android.mk中增加 LOCAL_CERTIFICATE := platform。可以参见Settings等
系统中所有使用android.uid.shared作为共享UID的APK,都会在manifest节点中增加 android:sharedUserId="android.uid.shared",然后在Android.mk中增加 LOCAL_CERTIFICATE := shared。可以参见Launcher等
系统中所有使用android.media作为共享UID的APK,都会在manifest节点中增加 android:sharedUserId="android.media",然后在Android.mk中增加LOCAL_CERTIFICATE := media。
到此,相信大家对"Android中如何利用shared_user_id获取系统权限"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 239
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.