0

I want to run an implicitly tried with the following code:

MenuActivity.java

public class MenuActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu);

    Button btn = (Button) findViewById(R.id.btnVideo);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            Uri intentUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pp);
            intent.setDataAndType(intentUri,"audio/mp3");
            startActivity(intent);
        }
    });


}

}

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
    android:allowBackup="true"
    android:icon="@drawable/iconopp14"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.powerpump.MainActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MenuActivity" />
</application>

You need to specify more parameters in AndroidManifest.xml?

Thanks.

  • Which Activity is not found? Please post a stack trace. – Mike M. Nov 22 '13 at 01:09
  • Hi Mike, when i press btnVideo it calls implicity a application for play media or i should want to do this. But when i press button the app breaks. http://pastebin.com/UaGXgNWK –  Nov 22 '13 at 01:14
  • I think your problem is with your file. Are you sure it's an mp3? You launch the Intent with type "audio/mp3", but your stack trace is showing type "video/mp4". – Mike M. Nov 22 '13 at 01:40
  • Yeah, judging from your comment below, I think you've actually got a video file that you're trying to open as an audio file. Try to open the file with a video player app. – Mike M. Nov 22 '13 at 01:42
  • Hi Mike, im playing with both resources, pp for mp3 and pp14 for mp4. But it doesnt function. At the bottom of this question there are one answer for create a file object,afterwards, i can open an native app, as music player or video player, but the files do not play. –  Nov 22 '13 at 08:55
  • Do you get errors from the native apps, or do they just open up and play dumb? – Mike M. Nov 22 '13 at 09:00
  • if i create file object when i give uri, activity doesnt breaks, else it breaks. –  Nov 22 '13 at 18:10

2 Answers2

0

I guess you simply have to register your MenuActivity in you AndroidManifest.xml as demonstrated here.

Community
  • 1
  • 1
Robin Ellerkmann
  • 2,083
  • 4
  • 29
  • 34
0

Looking at your code, it looks like you created a MenuActivity class after creating an android project with default settings and MenuActivity is your main activity(Launcher) class.

Just replace the MainActivity with MenuActivity in your AndroidManifest.xml file and delete

 <activity android:name=".MenuActivity" />

OR

Replace the class name to MainActivity from MenuActivity in your java code as follows

public class MainActivity extends Activity {
   ......

OR

use this as your android manifest.xml file

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
  <application
     android:allowBackup="true"
     android:icon="@drawable/iconopp14"
     android:label="@string/app_name"
     android:theme="@style/AppTheme" >

    <activity android:name="com.powerpump.MenuActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 </application>
Harsh Singal
  • 377
  • 1
  • 7
  • Hi, i have two activities, MainActivity for to show a splash demo for 2secs and MenuActivity for to show a menu with some buttons. One of them plays a media file on raw resource. Maybe isnt the correct way for to make it. Im rookie –  Nov 22 '13 at 00:28
  • Can you please post the MainActivity code? How are you linking MainActivity with MenuActivity? – Harsh Singal Nov 22 '13 at 00:35
  • As the fellow team member in another reply mentioned, try giving full name of the class(including package name) in your AndroidManifest.xml 'code' 'code' – Harsh Singal Nov 22 '13 at 00:56
  • Can you also post the logcat trace? – Harsh Singal Nov 22 '13 at 01:00
  • I tried running your code on my end and it launches the demo activity for 1.5 seconds as mentioned by you and it takes me to the MenuActivity class also. – Harsh Singal Nov 22 '13 at 01:03
  • My problem is that i cant play media, activities works, main and menu –  Nov 22 '13 at 01:08
  • Can you try this: [link]http://stackoverflow.com/questions/3114471/android-launching-music-player-using-intent – Harsh Singal Nov 22 '13 at 01:15
  • This code open the app of my device correctly, but i cant play it. I think that file isnt a good object for media's app –  Nov 22 '13 at 01:33