teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

書式の改善

2017/10/07 10:47

投稿

S.I
S.I

スコア48

title CHANGED
File without changes
body CHANGED
@@ -1,16 +1,16 @@
1
1
  ###前提・実現したいこと
2
2
  プログラミング初心者です。android studioでのアプリ開発について。
3
- ボタンを押したら自作の”Qr Code Scanner”というプロジェクトへ画面遷移させたいのですが、エミュレーターで実行するとボタンを押したらエラーになります。どなたか回答よろしくお願いします。
3
+ ボタンを押したら自作の”Qr Code Scanner”というへ画面遷移させたいのですが、エミュレーターで実行するとボタンを押したらエラーになります。どなたか回答よろしくお願いします。
4
4
 
5
+
6
+ ボタンを配置しているアクティビティのクラス
5
7
  ```java
6
- package com.example.a1881.myapplication;
8
+ package com.example.nakahara.sample;
7
9
 
8
10
  import android.content.Intent;
9
- import android.net.Uri;
10
11
  import android.support.v7.app.AppCompatActivity;
11
12
  import android.os.Bundle;
12
13
  import android.view.View;
13
- import android.widget.Button;
14
14
 
15
15
  public class MainActivity extends AppCompatActivity {
16
16
 
@@ -19,22 +19,65 @@
19
19
  super.onCreate(savedInstanceState);
20
20
  setContentView(R.layout.activity_main);
21
21
 
22
- Button btn = (Button)findViewById(R.id.button);
22
+ }
23
- btn.setOnClickListener(new View.OnClickListener() {
24
23
 
25
- @Override
26
- public void onClick(View v) {
24
+ public void openQrCodeScanner(View view){
27
- // TODO Auto-generated method stub
28
- // インテントのインスタンス生成
25
+ // インテント生成する
29
- Intent intent = new Intent();
26
+ Intent intent = new Intent();
27
+
30
- // インテントにアクション及びURLセット
28
+ // アクションを指定する
31
- intent.setAction(Intent.ACTION_VIEW);
29
+ intent.setAction(Intent.ACTION_MAIN);
30
+
31
+ // カテゴリを追加する(サンプルでは独自のカテゴリを指定しています)
32
+ //intent.addCategory(Intent.CATEGORY_DEFAULT);
32
- intent.setData(Uri.parse("QrCodeScanner"));
33
+ intent.addCategory("QrCodeScanner");
34
+
33
- // ブラウザ起動
35
+ // アプリを起動する
34
- startActivityForResult(intent, Integer.parseInt("QrCodeScanner"));
36
+ startActivity(intent) ;
35
- }
37
+
36
- });
37
- }
38
38
  }
39
+ }
40
+ ```
39
41
 
42
+ "Qr Code Scanner"のマニフェストファイルです
43
+ ```java
44
+ <?xml version="1.0" encoding="utf-8"?>
45
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
46
+ package="com.kaola.qrcodescanner">
47
+
48
+ <uses-permission android:name="android.permission.CAMERA"/>
49
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
50
+ <uses-permission android:name="android.permission.VIBRATE"/>
51
+
52
+ <uses-feature
53
+ android:name="android.hardware.camera"
54
+ android:required="false"/>
55
+ <uses-feature
56
+ android:name="android.hardware.camera.flash"
57
+ android:required="false"/>
58
+
59
+ <application
60
+ android:name=".qrcode.QrCodeApplication"
61
+ android:allowBackup="true"
62
+ android:icon="@mipmap/ic_launcher"
63
+ android:label="@string/app_name"
64
+ android:supportsRtl="true"
65
+ android:theme="@style/Theme.AppCompat.NoActionBar">
66
+ <activity android:name=".qrcode.QrCodeActivity">
67
+ <intent-filter>
68
+ <action android:name="android.intent.action.MAIN"/>
69
+ <category android:name="android.intent.category.LAUNCHER"/>
70
+ </intent-filter>
71
+ <intent-filter>
72
+ <action android:name="android.intent.action.MAIN" />
73
+ <category android:name="android.intent.category.DEFAULT" />
74
+ <category android:name="android.intent.category.BROWSABLE" />
75
+ <data android:scheme="http" />
76
+ </intent-filter>
77
+
78
+ </activity>
79
+ </application>
80
+
81
+ </manifest>
82
+
40
83
  ```

1

コード記述に変更

2017/10/07 10:47

投稿

S.I
S.I

スコア48

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
  プログラミング初心者です。android studioでのアプリ開発について。
3
3
  ボタンを押したら自作の”Qr Code Scanner”というプロジェクトへ画面遷移させたいのですが、エミュレーターで実行するとボタンを押したらエラーになります。どなたか回答よろしくお願いします。
4
4
 
5
-
5
+ ```java
6
6
  package com.example.a1881.myapplication;
7
7
 
8
8
  import android.content.Intent;
@@ -35,4 +35,6 @@
35
35
  }
36
36
  });
37
37
  }
38
- }
38
+ }
39
+
40
+ ```