Ver Fonte

Initial commit for BroadcastReceiverSingleStatic project.

Cristian Tanas há 11 anos atrás
pai
commit
1a20a69c89

+ 37 - 0
BroadcastReceiverSingleStatic/AndroidManifest.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.broadcastreceiver.singlestatic"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+    
+    <uses-permission android:name="android.permission.VIBRATE"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        
+        <receiver 
+            android:name=".RandomBroadcastReceiver"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="org.uab.android.broadcastreceiver.singlestatic.SEND_RANDOM_BROADCAST"/>
+            </intent-filter>
+        </receiver>
+    </application>
+
+</manifest>

BIN
BroadcastReceiverSingleStatic/ic_launcher-web.png


BIN
BroadcastReceiverSingleStatic/libs/android-support-v4.jar


BIN
BroadcastReceiverSingleStatic/res/drawable-hdpi/ic_launcher.png


BIN
BroadcastReceiverSingleStatic/res/drawable-mdpi/ic_launcher.png


BIN
BroadcastReceiverSingleStatic/res/drawable-xhdpi/ic_launcher.png


BIN
BroadcastReceiverSingleStatic/res/drawable-xxhdpi/ic_launcher.png


+ 17 - 0
BroadcastReceiverSingleStatic/res/layout/activity_main.xml

@@ -0,0 +1,17 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="${relativePackage}.${activityClass}" >
+
+    <Button
+        android:id="@+id/button1"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginTop="16dp"
+        android:text="@string/launch" />
+
+</RelativeLayout>

+ 11 - 0
BroadcastReceiverSingleStatic/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
BroadcastReceiverSingleStatic/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 8 - 0
BroadcastReceiverSingleStatic/res/values/strings.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">BroadcastReceiverSingleStatic</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="launch">Send broadcast!</string>
+
+</resources>

+ 20 - 0
BroadcastReceiverSingleStatic/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 36 - 0
BroadcastReceiverSingleStatic/src/org/uab/android/broadcastreceiver/singlestatic/MainActivity.java

@@ -0,0 +1,36 @@
+package org.uab.android.broadcastreceiver.singlestatic;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+public class MainActivity extends Activity {
+	
+	public static final String	SEND_RANDOM_BROADCAST = "org.uab.android.broadcastreceiver.singlestatic.SEND_RANDOM_BROADCAST";
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		// Get a reference to the Send Broadcast button
+		Button sendBroadcastButton = (Button) findViewById(R.id.button1);
+		
+		// Set an OnClickListener to the button
+		sendBroadcastButton.setOnClickListener(new OnClickListener() {
+			
+			@Override
+			public void onClick(View v) {
+				
+				// Send a broadcast event with the SEND_RANDOM_BROADCAST action
+				// This event is delivered to only those receivers having the android.permission.VIBRATE permission
+				sendBroadcast(
+						new Intent(SEND_RANDOM_BROADCAST), 
+						android.Manifest.permission.VIBRATE);
+			}
+		});
+	}
+}

+ 28 - 0
BroadcastReceiverSingleStatic/src/org/uab/android/broadcastreceiver/singlestatic/RandomBroadcastReceiver.java

@@ -0,0 +1,28 @@
+package org.uab.android.broadcastreceiver.singlestatic;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Vibrator;
+import android.util.Log;
+import android.widget.Toast;
+
+public class RandomBroadcastReceiver extends BroadcastReceiver {
+	
+	private static final String LOG_TAG = "RANDOM_BROADCAST_RECEIVER";
+
+	@Override
+	public void onReceive(Context context, Intent intent) {
+		
+		Log.i(LOG_TAG, "Intent with action: " + intent.getAction() + " received!");
+		
+		// Make the device vibrate for 500ms
+		Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+		vibrator.vibrate(500);
+		
+		// Show a Toast to inform the event has been received and processed
+		Toast.makeText(context, "Intent received by RandomBroadcastReceiver.", Toast.LENGTH_SHORT)
+			.show();
+	}
+
+}