2017-02-13 5 views
0

Ich arbeite an einer App (nur ein kleines lustiges Projekt für mich selbst, ich werde es nicht auf den Play Store setzen), die einen Toast senden wird. Mein Endziel ist ein Shell-Befehl, um einen Toast zu senden. Es ist mir egal, wie ich diese Ergebnisse bekomme, ich möchte nur, dass es funktioniert.Benutzerdefinierte Absicht Absturz meiner App

Ich denke, ich werde die Shell-Befehl senden eine Absicht zu meiner App haben. Ich verwende eine benutzerdefinierte Absicht:

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

Wenn ich adb shell am start -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain" verwenden, es zu starten, meine App stürzt ab.

Hier ist meine AndroidManifest.xml:

<?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> 

Und mein handler.java

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()); 
     } 
    } 
} 

Vielen Dank für jede Hilfe!

Antwort

0

diese mit Broadcast

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

statt

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

replace starten versuchen.

hoffe, es funktioniert.

+0

Obwohl es diesmal nicht abgestürzt ist, hat es auch nicht den Toast gemacht. –