2017-02-13 4 views
0

私はトーストを送るアプリ(自分のために少し楽しいプロジェクトですが、私はプレイストアに入れていません)に取り組んでいます。私の最終目標は、トーストを送るシェルコマンドを持つことです。私はこれらの結果をどのように得るか気にしない、私はそれが機能するようにしたい。私のアプリをクラッシュさせるカスタムインプット

私は、私のアプリケーションにインテントを送信するシェルコマンドを持っていると思っています。私はそれを開始するためにadb shell am start -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain"を使用すると、私のアプリのクラッシュを

<intent-filter> 
    <action android:name="com.tylerr147.toast" /> 
<category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 

:私は、カスタムの意図を使用しています。任意の助け

package com.tylerr147.intenttoast; 
import android.app.*; 
import android.content.*; 
import android.net.*; 
import android.os.*; 
import android.widget.*; 
import java.util.*; 
import android.util.*; 

public class handler extends Activity 
{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     Intent intent = getIntent(); 
     String action = intent.getAction(); 
     String type = intent.getType(); 
     handleSendText(intent); 
    } 
    public void handleSendText(Intent intent) 
    { 
     try{ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); 
     if (sharedText != null) { 
      // Update UI to reflect text being shared 
      Toast.makeText(getApplicationContext(), sharedText, Toast.LENGTH_LONG).show(); 
     } 
     } catch(Exception e) { 
    Log.e("Boked", e.toString()); 
     } 
    } 
} 

おかげ

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tylerr147.intenttoast" > 
<application android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 
    <activity android:name=".handler" > 
     <intent-filter> 
     <action android:name="android.intent.action.SEND" /> 
<category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 
<intent-filter> 
<action android:name="com.tylerr147.toast" /> 
    <category android:name="android.intent.category.DEFAULT"/> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 
</activity> 
</application> 
</manifest> 

そして、私のhandler.java:

は、ここに私のAndroidManifest.xmlをです!

答えて

0

この

adb shell am broadcast -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain" 

代わりの

adb shell am start -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain" 

放送でスタートを交換してみてください。

希望します。

+0

今回はクラッシュしませんでしたが、トーストもしませんでした。 –

関連する問題