android appos 笔记

源码位置:

frameworks/base/services/java/com/android/server/AppOpsService.java

frameworks/base/core/java/android/app/AppOpsManager.{aidl,java}

frameworks/base/core/java/com/android/internal/app/IAppOps{Service,Callback}.aidl

是否打开服务:

修改系统属性:persist.sys.strict_op_enable

开启应用权限管理:true

关闭应用权限管理:false


public AppOpsService(File storagePath)

 {  

    mStrictEnable = "true".equals(SystemProperties.get(STRICT_PERMISSION_PROPERTY)); 

 }  

check if strict

private boolean isStrict(int code, int uid, String packageName) {     

 if (!mStrictEnable)         

  return false;       

return ((uid > Process.FIRST_APPLICATION_UID) &&              (AppOpsManager.opStrict(code)) && !isInWhitelist(packageName)); 

 }  


private static boolean[] sOpStrict =new boolean[]{

true, //OP_COARSE_LOCATION

true,//OP_FINE_LOCATION

true,//OP_GPS

...

true,//OP_READ_SMS

};


不过目前测试好像上面的几个都没生效

菜单在

package/apps/settings/res/xml/security_settings_misc.xml


以下是一个简单的 Android 笔记本应用的代码示例,包括增加、删除、修改和查找笔记的功能: 1. 在 activity_main.xml 中添加一个 ListView 元素和三个 Button 元素,以便用户列出、添加、编辑和删除笔记: ```xml <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/addButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Add"/> <Button android:id="@+id/editButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Edit"/> <Button android:id="@+id/deleteButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Delete"/> ``` 2. 在 note_item.xml 中添加一个 TextView 元素,以便在 ListView 中显示笔记的标题: ```xml <TextView android:id="@+id/titleTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:padding="10dp"/> ``` 3. 在 MainActivity.java 文件中编写以下代码: ```java import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { ListView listView; Button addButton, editButton, deleteButton; ArrayList<String> notes; ArrayAdapter<String> adapter; int selectedIndex = -1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = findViewById(R.id.listView); addButton = findViewById(R.id.addButton); editButton = findViewById(R.id.editButton); deleteButton = findViewById(R.id.deleteButton); notes = new ArrayList<>(); adapter = new ArrayAdapter<>(this, R.layout.note_item, R.id.titleTextView, notes); listView.setAdapter(adapter); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showNoteDialog("New note", "", true); } }); editButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (selectedIndex != -1) { String note = notes.get(selectedIndex); showNoteDialog("Edit note", note, false); } else { Toast.makeText(MainActivity.this, "Please select a note to edit", Toast.LENGTH_SHORT).show(); } } }); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (selectedIndex != -1) { String note = notes.get(selectedIndex); showDeleteDialog(note); } else { Toast.makeText(MainActivity.this, "Please select a note to delete", Toast.LENGTH_SHORT).show(); } } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { selectedIndex = i; } }); } private void showNoteDialog(String title, String note, final boolean isNew) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(title); final EditText input = new EditText(this); input.setText(note); builder.setView(input); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { String text = input.getText().toString(); if (isNew) { notes.add(text); } else { notes.set(selectedIndex, text); } adapter.notifyDataSetChanged(); } }); builder.setNegativeButton("Cancel", null); builder.show(); } private void showDeleteDialog(final String note) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Delete note"); builder.setMessage("Are you sure you want to delete this note?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { notes.remove(note); adapter.notifyDataSetChanged(); selectedIndex = -1; } }); builder.setNegativeButton("No", null); builder.show(); } } ``` 4. 运行应用程序并测试添加、编辑、删除和查找笔记的功能。 注意:这只是一个简单的笔记本应用程序示例,未进行任何输入验证或错误处理。在实际应用程序中,您可能需要添加更多的代码来确保应用程序的稳定性和安全性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值