Skip to content

Instantly share code, notes, and snippets.

@takuo
Created March 6, 2012 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuo/1985494 to your computer and use it in GitHub Desktop.
Save takuo/1985494 to your computer and use it in GitHub Desktop.
共有(Intent.ACTION_SEND)で受け取ったテキストをクリップボードにぶち込むだけのアプリ
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.takuo.android.sharetoclipboard"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/activity_name"
android:name=".SharetoClipboardActivity" >
<intent-filter >
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
</manifest>
package jp.takuo.android.sharetoclipboard;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.ClipboardManager;
public class SharetoClipboardActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String text = intent.getDataString();
if ( text == null ) {
text = intent.getStringExtra(Intent.EXTRA_TEXT);
}
ClipboardManager cm = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
cm.setText(text);
finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment