Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android project for interacting with android clipboard service via shell
- Loading branch information
0 parents
commit 7cf8401
Showing
12 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.cm.android" android:versionCode="1" android:versionName="1.0-SNAPSHOT"> | ||
|
||
<application android:icon="@drawable/icon" android:label="@string/app_name"> | ||
<activity android:name=".HelloAndroidActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<service android:name=".ClipboardServiceFront" | ||
android:exported="true" | ||
android:enabled="true"> | ||
</service> | ||
<service android:name=".ClipperReceiver" | ||
android:exported="true" | ||
android:enabled="true"> | ||
<intent-filter> | ||
<data android:scheme="clipper" android:host="*" android:mimeType="*/*"/> | ||
</intent-filter> | ||
</service> | ||
|
||
</application> | ||
|
||
</manifest> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# File used by Eclipse to determine the target system | ||
# Project target. | ||
target=android-10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.cm.android</groupId> | ||
<artifactId>clipboard-service</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>apk</packaging> | ||
<name>clipboard-service</name> | ||
|
||
<properties> | ||
<platform.version>2.3.3</platform.version> | ||
<android.sdk.path>/Users/majidv/android-sdk-macosx/</android.sdk.path> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.android</groupId> | ||
<artifactId>android</artifactId> | ||
<version>${platform.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.jayway.maven.plugins.android.generation2</groupId> | ||
<artifactId>android-maven-plugin</artifactId> | ||
<version>3.1.1</version> | ||
<configuration> | ||
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> | ||
<assetsDirectory>${project.basedir}/assets</assetsDirectory> | ||
<resourceDirectory>${project.basedir}/res</resourceDirectory> | ||
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> | ||
<sdk> | ||
<platform>10</platform> | ||
</sdk> | ||
<undeployBeforeDeploy>true</undeployBeforeDeploy> | ||
</configuration> | ||
<extensions>true</extensions> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
> | ||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/hello" | ||
/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="hello">Hello clipboard-service!</string> | ||
<string name="app_name">clipboard-service</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.cm.android; | ||
|
||
import android.text.ClipboardManager; | ||
import android.app.IntentService; | ||
import android.content.Intent; | ||
|
||
import android.util.Log; | ||
|
||
public class ClipboardServiceFront extends IntentService { | ||
private static String TAG = "Clipboard service"; | ||
|
||
|
||
|
||
private static String ACTION_GET = "get"; | ||
private static String ACTION_SET = "set"; | ||
|
||
private static String EXTRA_TEXT = "text"; | ||
|
||
|
||
|
||
/** | ||
* A constructor is required, and must call the super IntentService(String) | ||
* constructor with a name for the worker thread. | ||
*/ | ||
public ClipboardServiceFront() { | ||
super("ClipboardServiceFront"); | ||
|
||
} | ||
|
||
/** | ||
* The IntentService calls this method from the default worker thread with | ||
* the intent that started the service. When this method returns, IntentService | ||
* stops the service, as appropriate. | ||
*/ | ||
@Override | ||
protected void onHandleIntent(Intent intent) { | ||
Log.i(TAG, "Inside intent handler!"); | ||
Log.i(TAG, "ACTION:"+intent.getAction()); | ||
Log.i(TAG, "Text:"+ intent.getStringExtra(EXTRA_TEXT)); | ||
|
||
ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); | ||
if (ACTION_SET.equals(intent.getAction())) { | ||
Log.i(TAG, "Setting text into clipboard"); | ||
cb.setText( intent.getStringExtra(EXTRA_TEXT)); | ||
} else if (ACTION_GET.equals( intent.getAction()) ) { | ||
String clip = cb.getText().toString(); | ||
Log.i(TAG, "Got this from clipboard:"+clip); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.cm.android; | ||
|
||
import android.text.ClipboardManager; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.BroadcastReceiver; | ||
|
||
import android.util.Log; | ||
/* Same implementatio just listen to broadcasts */ | ||
public class ClipperReceiver extends BroadcastReceiver { | ||
private static String TAG = "Clipboard receiver"; | ||
|
||
|
||
private static String ACTION_GET = "get"; | ||
private static String ACTION_SET = "set"; | ||
|
||
private static String EXTRA_TEXT = "text"; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Log.i(TAG, "Inside intent handler!"); | ||
Log.i(TAG, "ACTION:"+ intent.getAction()); | ||
Log.i(TAG, "Text:"+ intent.getStringExtra(EXTRA_TEXT)); | ||
|
||
ClipboardManager cb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); | ||
|
||
if (ACTION_SET.equals(intent.getAction())) { | ||
Log.i(TAG, "Setting text into clipboard"); | ||
cb.setText( intent.getStringExtra(EXTRA_TEXT)); | ||
} else if (ACTION_GET.equals( intent.getAction()) ) { | ||
String clip = cb.getText().toString(); | ||
Log.i(TAG, "Got this from clipboard:" + clip); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.cm.android; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
public class HelloAndroidActivity extends Activity { | ||
|
||
private static String TAG = "clipboard-service"; | ||
|
||
/** | ||
* Called when the activity is first created. | ||
* @param savedInstanceState If the activity is being re-initialized after | ||
* previously being shut down then this Bundle contains the data it most | ||
* recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b> | ||
*/ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
Log.i(TAG, "onCreate"); | ||
setContentView(R.layout.main); | ||
} | ||
|
||
} | ||
|