In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to add custom permissions in an orderly broadcast in Android". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to add custom permissions in an orderly broadcast in Android" can help you solve your doubts.
An instance of adding custom permissions to ordered broadcasts in Android
Orderly broadcast instructions:
Orderly broadcasting is more complicated because it has to deal with the processing results of the message.
* sendOrderedBroadcast (Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)
If you just want the broadcast to be collected according to priority and do not care about the result of processing, you can use the following version:
* sendOrderedBroadcast (Intent intent, String receiverPermission)
Similarly, in a multi-user environment, you can choose which user to broadcast:
* sendOrderedBroadcastAsUser (Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)
First of all, we need to customize a permission in AndroidManifest.xml. The format refers to the permission that comes with the system, Android.permission.XXXXX, as long as it is xxx.peimission.XXXXXX. If you do not follow this format, then this permission may not be available.
Then use sendOrderedBroadcast (intent, "test.permission.TEST"); to send an orderly broadcast, of course, to specify the priority of the recipient before sending the broadcast, and the higher the priority, the higher the number specified by android:priority. The range of values is-1000 to 1000, which will not be described in detail.
Public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Button send= (Button) findViewById (R.id.send); send.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {Intent intent=new Intent (); intent.setAction ("") Intent.putExtra ("msg", "a simple message"); sendOrderedBroadcast (intent, "test.permission.TEST");}});}}
When the first BroadcastReceiver receives the broadcast, if you want to add something of your own to it, you can first create a Bundle object and store the data.
Then add the bundle to the original message through setResultExtras (bundle)
Ublic class MyReceiver extends BroadcastReceiver {public MyReceiver () {} @ Override public void onReceive (Context context, Intent intent) {Toast.makeText (context, "the Action of the received Intent is" + intent.getAction () + "\ nThe message content is:" + intent.getStringExtra ("msg"), Toast.LENGTH_LONG). Show (); Bundle bundle=new Bundle (); bundle.putString ("first", "the first BroadCast stored message!"); setResultExtras (bundle);}}
The next BroadcastReceiver can extract the information through getResultExtras.
Ublic class MyReceiver2 extends BroadcastReceiver {public MyReceiver2 () {} @ Override public void onReceive (Context context, Intent intent) {/ / TODO: This method is called when the BroadcastReceiver is receiving Bundle bundle=getResultExtras (true); String first=bundle.getString ("first"); Toast.makeText (context, "the first BroadCast stored message is:" + first,Toast.LENGTH_LONG) .show () }} after reading this, the article "how to add custom permissions to orderly broadcasts in Android" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it. If you want to know more about related articles, please follow the industry information channel.
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: 0
*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.