Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
共有(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