-2

background

i wish to send a broadcast intent (even with root permission) that an app was removed, and for this, i have to broadcast an intent with extras.

problem

i just can't figure out what am i missing, since i can't find the correct way to do it.

what i've done so far

i think I've found where on android the OS broadcasts the intent (the file is called "PackageManagerService.java" ). I've also found out how to get the correct permission using root (and it works) , and also how to put extra data into the intent of the broadcast (link here) , all using the "adb" tool.

now i have to put all of the pieces together.

the code so far is :

String packageOfCurrentApp=..., packageOfAppToReportAbout=... ;
try
  {
  final java.lang.Process p=
      Runtime.getRuntime().exec(
          String.format("su -c pm grant %s android.permission.BROADCAST_PACKAGE_REMOVED",packageOfCurrentApp));
  final int res=p.waitFor();
  Logger.log(LogLevel.DEBUG,"got permission:"+(res==0));
  if(res==0)
    {
    final java.lang.Process p2=Runtime.getRuntime().exec(//
            "am broadcast -a android.intent.action.PACKAGE_REMOVED "+//
            "--ei android.intent.extra.UID -1 "+//
            "-eez android.intent.extra.DATA_REMOVED true"+//
            " -d com.syncme.syncmeapp ");
    final int res2=p2.waitFor();
    Logger.log(LogLevel.DEBUG,"broadcast?"+(res2==0));
    }
  }
catch(final Exception e)
  {
  Logger.log(LogLevel.DEBUG,"error:"+e);
  }

the permission getting works, but the broadcasting doesn't.

question

what is wrong with the code? what is missing? how can i fix it?

i would also like to know how to do the same via the shell (of the PC).

4

2 回答 2

0

就像电池一样:- 我们在下面使用 m 广播“intent:#Intent;action=android.intent.action.BATTERY_CHANGED;i.status=5;i.voltage=4155;i.level=100;end”

于 2013-10-29T09:22:06.650 回答
-1

请参考 PackageManagerService.java 的源码

        Bundle extras = new Bundle(1);
        extras.putInt(Intent.EXTRA_UID, removedUid);
        extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false);
        sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage,
                extras, null, null);
于 2013-08-15T03:42:12.203 回答